Backlinks
Step-by-step guide to converting CSV data to RDF and importing it into the end-user dataspace
A CSV import has three components:
- CSV file
- The file containing the tabular data
- Mapping query
- SPARQL
CONSTRUCTquery that maps CSV rows to an RDF representation - CSV import
- Combines the file with the corresponding query
All the import components can be created from a single dialog, but the steps below create them one at a time:
- First, create a container for the data to be imported. This will be the import's target container.
- Upload a CSV file. Click on the Create dropdown at the bottom of the page and select File. This will open a new form.
- Fill out the Item fields — the document's Title (required) and optional Description, the same fields used when creating a document.
-
Fill out the mandatory File fields:
- Filename
- Click on Choose file and select a CSV file from your computer
- Title
- File title
- Once all the fields have been filled in, click Save.
- The browser will open your imported file.
- Create a mapping query that will transform the uploaded CSV to RDF — the tutorial's Data stage walks through a complete example, categories.rq. Click on the Create dropdown at the bottom of the page and select CONSTRUCT. This will open a new form.
- Fill out the Item fields.
-
Fill out the mandatory Query fields:
- Text
- SPARQL
CONSTRUCTquery string - You will not be able to save the query if its syntax is not valid SPARQL 1.1.
- Title
- Query title
- Once all the fields have been filled in, click Save. You can find it saved in the Queries container, which you can open from the document tree in the left sidebar.
- Click on the Create dropdown button at the bottom of the page and select CSV Import. This will open a new form.
- Fill out the Item fields.
-
Fill out the mandatory CSV Import fields:
- File
- Start typing the name of your CSV file and select it from the typeahead
- Query
- Select the mapping query using the typeahead
- Title
- Import title
- Click Save and you will be redirected to the newly created import document.
- Reload the document after a few moments to see the import progress. On success, the amount of data imported is displayed; on failure, the constraint violations or other import errors.
- Go back to the target container to see the newly imported data items.
The import is described by a document, which the command takes as its last argument, so create that document first. With the CLI installed and the LDH_* variables set:
doc=$(ldh create item \
--title "Categories import" \
--container "${LDH_BASE}categories/")
ldh import csv \
--title "Categories" \
--query-file categories/categories.rq \
--csv-file categories/categories.csv \
"$doc"Source: categories.rq, categories.csv — the mapping and the data are walked through in the CSV imports reference and the tutorial's Data stage
--delimiter defaults to , and can be set to another character.
The command prints the URI of the import it created, a fragment of $doc. The import runs in the background; add --wait to return only once it has ended, with exit code 1 and the error if it failed.