Backlinks
Step-by-step guide to importing RDF data
This guide is for importing larger amounts of data (e.g. more than a few thousand RDF triples) asynchronously. For smaller data, it is simpler to add data synchronously.
An RDF import has these components:
- RDF file
- The file containing the RDF data (can be in any RDF syntax)
- Transformation query (optional)
- SPARQL
CONSTRUCTquery that maps RDF to another RDF representation - Graph (optional)
- The document that the import results will be stored in, if no transformation query is specified
- RDF import
- Combines the file with the corresponding query
Specify either a query or a graph, but not both.
Import an RDF file¶
Without a transformation, the import asynchronously appends the RDF data to a document (see how to create a document).
With a transformation, it runs the uploaded RDF through a CONSTRUCT query before storing it, so the import can restructure or re-route the data.
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 an RDF 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 an RDF file from your computer
- Title
- File title
- Once all the fields have been filled in, click Save.
- The browser will open your uploaded file.
-
If you are importing with a transformation, create a transformation query that will
transform the uploaded RDF to a new RDF structure. 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 and the mandatory CONSTRUCT 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
- Click on the Create dropdown button at the bottom of the page and select RDF Import. This will open a new form.
- Fill out the Item fields.
-
Fill out the mandatory RDF Import fields:
- File
- Start typing the name of your RDF file and select it from the typeahead
- Title
- Import title
-
Select either the target graph or the transformation query — but not both:
- Name
- Select the target graph (document) using the typeahead
- Query
- Select the transformation query using the typeahead
- 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 document 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 "UNESCO category mappings" \
--container "${LDH_BASE}categories/")
ldh import rdf \
--title "UNESCO category mappings" \
--rdf-file categories/unesco-mappings.ttl \
--content-type "text/turtle" \
--graph "${LDH_BASE}categories/mappings/" \
"$doc"Pass either --graph with the target document's URI or --query-file with the path to a transformation query, but not both.
In the Northwind demo, the transformation query routes each mapping into its category's own document.
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.
Source: categories/unesco-mappings.ttl — the mapping file that connects Northwind categories to UNESCO Thesaurus concepts, shown in full in the RDF imports reference