npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@iqb/csv2ttl

v0.8.2

Published

Generate ttl files for publishing metadata vocabularies from csv

Downloads

82

Readme

License: MIT npm

Use this package to transform vocabularies from csv files of specific format to ttl files.

It's a pain to write ttl-files manually. But it's also a great idea to provide metadata vocabularies via ttl-files, especially if one uses skos or even skohub to generate shiny html or handy json.

So we support only a special use case of ttf/rdf: Hierarchical vocabularies. Here we use these attributes of rtf:

  • prefLabel (required): Multilingual name of the entry,
  • definition: Multilingual description to give more information about the entry, and
  • notation: Semver-like enumeration mainly to describe the hierarchy, like 2.4.3.

Workflow

1. First write the csv-File(s)

Look at the simplest example:

notation,title,description,id
,geschlossen,,
,halboffen,,
,offen,,

The first line and therefor the description of data structure is required. You see, that only the title is given.

2. Write csv2ttl_config.json

There is one json-file to provide with some parameters for the generation process. The idea is, that one (git)-repository contains of multiple vocabularies describing one common issue. We call this repo a 'vocabulary-group'. The config file lists all vocabularies with id and name.

3. Add IDs

Adding IDs is a precondition for the generation of ttl-files. This csv2ttl-package contains of two commands: addidcsv and csv2ttl. Use the first one to add IDs to the csv-files. Every entry gets an id randomly. Existing ids will not be overwritten.

4. Generate

Use the csv2ttl-command to get the ttl-files.

Create repo and install

First create a node repo. Precondition for that is of course a working node installation. Just create a new folder, go into this folder and type:

npm init

You will be prompted for some parameters. After that, type:

npm install @iqb/csv2ttl

Put all csv-files in that folder and write the csv2ttl_config.json.

After that, edit the package.json to have short access to the commands:

{
  "scripts": {
    "add": "addidcsv",
    "csv": "csv2ttl"
  }
}

To run these scripts, use your IDE or type

npm run add
npm run csv

If you like to store the source files in a separate folder, add a parameter when calling a script:

npm run add csv-src

Customise: csv2ttl_config.json

This json-file lists all vocabularies (i.e. csv-files) to convert and provides additional parameters for the generation process.

| parameter | description | default | |:--------------|:------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:--------------------------------------------------------:| | id | this entry will be used to make up the uri | required | | creator | use this to include the owner/developer | required | | title | multilingual: use lang to set the language and value to set the content | required | | csv_delimiter | possible values: ',' or ';'; the write process of the IDs will add quotes | ',' | | base | base-url to form the uri of the voc | required | | outDir | target folder for the ttl-files | '.' | | idPattern | when the IDs are generated, an external lib randex is used. This parameter value is directly given to this lib and must be an regular expression. It's kind of tricky and the lib is not free of problems, so play around with it before setting the parameter. | '^[abcdefghprqstuvxyz][2345679][abcdefghprqstuvxyz]$' | | vocabularies | Here you let the generator know what files should be included. Each voc must have an id and a title. Additionally, you can provide a description, a filename for the source and a filename for the target. | '.' |

Before processing the config file it is validated. You'll get errors if it's malformed.

5. Multi-language support

From the 0.7.6 csv2ttl supports multilanguage. The csv files should have the following format:

notation,title,description,id,title_en,description_en
,geschlossen,,,closed,
,halboffen,,,half open,
,offen,,,open,

The configuration example for multi-language support is available sample_data/csv2ttl_configEn.json.