rudof data
The data command can be used to parse one or more RDF data files in different formats.
Obtaining information about an RDF data file
Assuming the following content appears in a file called simple.ttl:
prefix : <http://example.org/>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
:a :name "Alice" ;
:birthdate "1990-05-02"^^xsd:date ;
:enrolledIn :cs101 .
:b :name "Bob", "Robert" .
:cs101 :name "Computer Science" .
The following command parses the file simple.ttl and shows its contents:
rudof data simple.ttl
Converting between different RDF data syntaxes
The -r option sets the output format, for example rdfxml, ntriples or trig:
rudof data -r rdfxml simple.ttl
The output is similar to this:
<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF xmlns="http://example.org/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:xsd="http://www.w3.org/2001/XMLSchema#" xmlns:its="http://www.w3.org/2005/11/its">
<rdf:Description rdf:about="http://example.org/b">
<name>Bob</name>
<name>Robert</name>
</rdf:Description>
<rdf:Description rdf:about="http://example.org/cs101">
<name>Computer Science</name>
</rdf:Description>
<rdf:Description rdf:about="http://example.org/a">
<name>Alice</name>
<birthdate rdf:datatype="http://www.w3.org/2001/XMLSchema#date">1990-05-02</birthdate>
<enrolledIn rdf:resource="http://example.org/cs101"/>
</rdf:Description>
</rdf:RDF>
It is possible to convert RDF data to a visual representation using the options svg, png or plantuml (see RDF visualization section).
Obtaining information about an RDF data located remotely
It is also possible to get RDF data from files which are remotely available through URIs like:
rudof data https://raw.githubusercontent.com/rudof-project/rudof/refs/heads/master/examples/simple.ttl
Data embedded in HTML
Web pages can embed RDF data with microdata, with RDFa and with JSON-LD <script> elements.
With --data-format html, rudof reads an HTML page and extracts the RDF of its microdata, its RDFa and its JSON-LD.
The conversion of microdata follows the W3C Microdata to RDF specification.
The conversion of RDFa follows RDFa Core 1.1 and HTML+RDFa 1.1.
The extraction of JSON-LD follows the HTML content algorithms of JSON-LD 1.1.
rudof reads all the <script> elements with the type application/ld+json.
The file people.html contains this page:
<!DOCTYPE html>
<html lang="en">
<body>
<div itemscope itemid="#alice" itemtype="http://schema.org/Person">
<span itemprop="name">Alice</span>
<data itemprop="age" value="23">twenty-three</data>
</div>
<div itemscope itemid="#bob" itemtype="http://schema.org/Person">
<span itemprop="name">Bob</span>
<span itemprop="age">unknown</span>
</div>
</body>
</html>
The following command shows the RDF of the page:
rudof data --data-format html --base http://example.org/people people.html
The output is similar to this:
<http://example.org/people#bob> <http://schema.org/name> "Bob"@en ;
<http://schema.org/age> "unknown"@en ;
a <http://schema.org/Person> .
<http://example.org/people#alice> <http://schema.org/name> "Alice"@en ;
<http://schema.org/age> 23 ;
a <http://schema.org/Person> .
The base IRI resolves the relative URLs of the page, such as itemid="#alice".
Without --base, rudof uses the base IRI of the configuration, or the current directory.
The extracted data is ordinary RDF data.
Every command that reads data accepts --data-format html, for example shex-validate, shacl-validate, query and node.
You can also merge HTML data with data in other formats.
For example, this command validates Bob against a ShEx schema:
rudof shex-validate --data-format html --base-data http://example.org/people -s people.shex -n "http://example.org/people#bob" -l "http://example.org/Person" people.html
The age of Bob is the string "unknown", so the validation fails:
<http://example.org/people#bob>@:Person FAIL
<http://example.org/people#bob> does not conform to :Person: property schema:age: Datatype error: found rdf:langString, expected xsd:integer, lexical form "unknown"@en (at @:Person~schema:age)
Microdata, RDFa, JSON-LD or any
By default, rudof reads the microdata, the RDFa and the JSON-LD of a page, and merges them in one graph.
The --html-extract option selects the RDF to read: microdata, rdfa, jsonld or any.
The file people_mixed.html has Alice in microdata, Bob in RDFa and Carol in JSON-LD:
<!DOCTYPE html>
<html>
<head>
<script type="application/ld+json">
{"@id": "#carol", "@type": "http://schema.org/Person", "http://schema.org/name": "Carol"}
</script>
</head>
<body>
<div itemscope itemid="#alice" itemtype="http://schema.org/Person">
<span itemprop="name">Alice</span>
</div>
<div resource="#bob" typeof="http://schema.org/Person">
<span property="http://schema.org/name">Bob</span>
</div>
</body>
</html>
This command reads only the JSON-LD of the page:
rudof data --data-format html --html-extract jsonld --base http://example.org/people -r ntriples people_mixed.html
The output has only Carol:
<http://example.org/people#carol> <http://schema.org/name> "Carol" .
<http://example.org/people#carol> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Person> .
Without --html-extract, the output has Alice, Bob and Carol.
To change the default, set html_extraction in the [rdf] section of the configuration.
See Configuration.
Merging RDF data
data can also read several RDF files, merge them, and write the result in any supported RDF format.
We carse several files, merge and serialize them in any of the RDF supported formats.
rudof data user.ttl simple.ttl -r rdfxml -o output.rdf
You can also write the merged data in another format, such as
ntriplesorrdfxml.
This merges several files in the same data command. In rudof shell, you can run several data commands in a session. There, a second data FILE replaces the loaded data by default. Add --merge to merge. See shell.
Reader mode
--reader-mode says how much the parser checks what it reads. It applies to every command that
reads RDF data, not just data.
In strict mode, the default, every term is validated. The first error stops
the whole document.
$ cat langstring.ttl
@prefix ex: <http://example.org/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
ex:a ex:b "x"^^rdf:langString .
$ rudof data langstring.ttl
Error: ... Parser error at line 3 between columns 16 and 30: The datatype of a literal without a language tag must not be rdf:langString
In lax mode, rudof assumes that the document is valid. It skips those checks, so parsing is faster. Parts that it cannot read at all are skipped, and the rest of the document is read.
rudof data --reader-mode lax langstring.ttl
RDF visualization
data can draw simple RDF graphs. Set --result-format to a visual format, such as svg or png.
The default engine is PlantUML. It needs the PlantUML binary, with its path in the PLANTUML variable. See convert: Prerequisites for the setup. That page also describes the --viz-engine graphviz alternative, which needs the Graphviz dot command on the PATH and no environment variable.
Another alternative is to use the plantuml result format to generate an intermediate file and pass that file to some PlantUML processor.
As an example, the following command generates a plantuml file:
rudof data examples/simple.ttl -r plantuml -o file.plantuml
If you have PlantUML available you can use directly:
rudof data examples/simple.ttl -r svg -o file.svg
To render with Graphviz instead, pass --viz-engine graphviz:
rudof data examples/simple.ttl -r svg --viz-engine graphviz -o file.svg
RDF Config file
--config-file (-c in short form) passes a TOML configuration file, including the [rdf] section (base IRI, registered SPARQL endpoints). See Configuration and config.
Options
$ rudof data --help
Show information about RDF data
Usage: rudof data [OPTIONS] [DATA]...
Arguments:
[DATA]...
Options:
-p, --prefix <PREFIX-SOURCE>
Prefix source (can be a string, a path or an URL)
-t, --data-format <FORMAT>
RDF Data format
[default: turtle]
[possible values: turtle, ntriples, rdfxml, trig, n3, nquads, jsonld, pg, html]
-b, --base <IRI>
Base IRI
--reader-mode <MODE>
RDF Reader mode
[default: strict]
[possible values: lax, strict]
-r, --result-format <FORMAT>
Output result format
[default: turtle]
[possible values: turtle, ntriples, jsonld, rdfxml, trig, n3, nquads, compact, json, plantuml, svg, png]
--viz-engine <ENGINE>
Visualization engine for image (SVG/PNG) result formats
[default: plantuml]
[possible values: plantuml, graphviz]
-c, --config-file <FILE>
Config file name
-o, --output-file <FILE>
Output file name, default = terminal
--force-overwrite
Force overwrite to output file if it already exists
--backend <BACKEND>
Choose which backend to load the input into.
- `memory` (default): parse into an in-process oxrdf::Graph. - `qlever`: launch a local QLever Docker container and index the input on disk. Requires the binary to be built with the `qlever` feature. - `lbug`: the connected LadybugDB property graph database (see `rudof connect`). Accepted here but not yet functional: rudof can derive a property graph from RDF (`load`/`ddl`) but cannot yet read one back out as RDF triples. - `endpoint=<URL_OR_NAME>`: query an external SPARQL endpoint by URL or by the name of an endpoint registered in the TOML config. See also the `--endpoint` / `-e` shortcut.
-e, --endpoint <URL_OR_NAME>
Shortcut for `--backend endpoint=<URL_OR_NAME>`.
Accepts either a full SPARQL endpoint URL or the name of an endpoint registered in the TOML config. Mutually exclusive with `--backend`.
--min-request-interval <MS>
Minimum milliseconds between two requests to the SPARQL endpoint (-e/--endpoint only); default: the endpoint's configured value, else 1100 for remote hosts and 0 for localhost
--max-concurrent-requests <N>
Maximum requests in flight at once to the SPARQL endpoint (-e/--endpoint only); default 1
--max-nodes-per-query <N>
Maximum nodes fetched per SPARQL query when prefetching a shapemap's nodes (-e/--endpoint only); 1 disables batching; default 20
--qlever-index-dir <DIR>
Directory for the QLever on-disk index, overriding `[rdf.qlever] index_dir` from the TOML config.
Only meaningful with `--backend qlever`. Naming a directory explicitly is how you find out (and share) where an index lives: pass the same directory again — from this machine or another rudof session pointed at the same path (e.g. a shared/mounted volume) — and the idempotent build step is skipped, going straight to serving. When unset, rudof resolves a per-input fingerprinted path under the platform cache dir and logs it at startup.
--html-extract <MODE>
RDF to read from HTML data: microdata, rdfa, jsonld or any (default: the config, else any)
[possible values: microdata, rdfa, jsonld, any]
-h, --help
Print help (see a summary with '-h')
See also
- RDF backends: where the data is (memory, QLever or a SPARQL endpoint).