0.7.7 • Published 3 months ago

@iqb/csv2ttl v0.7.7

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

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.

parameterdescriptiondefault
idthis entry will be used to make up the urirequired
creatoruse this to include the owner/developerrequired
titlemultilingual: use lang to set the language and value to set the contentrequired
csv_delimiterpossible values: ',' or ';'; the write process of the IDs will add quotes','
basebase-url to form the uri of the vocrequired
outDirtarget folder for the ttl-files'.'
idPatternwhen 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]$'
vocabulariesHere 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.

0.7.7

3 months ago

0.7.4

6 months ago

0.7.3

6 months ago

0.7.2

6 months ago

0.7.1

7 months ago

0.7.0

7 months ago

0.6.3

7 months ago

0.6.2

8 months ago

0.6.1

8 months ago

0.6.0

8 months ago

0.5.0-beta

8 months ago

0.4.0-beta

8 months ago

0.3.0-beta

8 months ago

0.2.0-beta2

8 months ago

0.2.0-beta

8 months ago

0.1.0

8 months ago