SPARQL Anything behaves as a standard SPARQL query engine. For example, the SPARQL Anything server will act as a virtual endpoint that can be queried exactly as a remote SPARQL endpoint. In addition, SPARQL Anything provides a rich Command Line Interface (CLI). For information for how to run SPARQL Anything, please see the quickstart and usage sections of the documentation.
In order to instruct the query processor to delegate the execution to SPARQL Anything, you can use the following IRI-schema within SERVICE clauses.
x-sparql-anything ':' ([option] ('=' [value])? ','?)+
A minimal URI that uses only the resource locator is also possible.
x-sparql-anything ':' URL
In this case SPARQL Anything guesses the data source type from the file extension.
Alternatively, options can be provided as basic graph pattern inside the SERVICE clause as follows
PREFIX xyz: <http://sparql.xyz/facade-x/data/>
PREFIX fx: <http://sparql.xyz/facade-x/ns/>
PREFIX fxe: <http://sparql.xyz/facade-x/engine/>
SELECT ?seriesName
WHERE {
SERVICE <x-sparql-anything:> {
fxe:properties fxe:location "https://sparql-anything.cc/example1.json" .
?tvSeries xyz:name ?seriesName .
?tvSeries xyz:stars ?star .
?star fx:anySlot "Courteney Cox" .
}
}Note that
- The SERVICE IRI scheme must be
x-sparql-anything:. - Each triplification option to pass to the engine corresponds to a triple of the Basic Graph Pattern inside the SERVICE clause.
- Such triples must have
fxe:propertiesas subject,fxe:[OPTION-NAME]as predicate, and a literal or a variable as object. A variable must be bound by aBINDinside the same SERVICE clause, before the option triple (e.g.BIND("data.json" AS ?f) fxe:properties fxe:location ?f .). Variables bound outside the SERVICE clause (byBINDorVALUESin the outer query) are not passed to the engine yet, and the SERVICE returns no results. - The
fxe:namespace (http://sparql.xyz/facade-x/engine/) is the Façade-X Engine vocabulary defined by the W3C Data Façades Community Group. The Façade-X functions and the terms of the generated data (e.g.fx:Root) remain in thefx:namespace. - If the same option is given as an
fxe:triple, as anfx:triple and in the SERVICE IRI, thefxe:triple takes precedence, then thefx:triple, then the IRI. - The root container is typed
fx:Root(fx:rootbefore v1.3.0). Queries that still usefx:rootare rewritten tofx:Rootwith a deprecation warning (#681); this will be removed in a future release.
You can also mix the two modalities as follows.
PREFIX xyz: <http://sparql.xyz/facade-x/data/>
PREFIX fx: <http://sparql.xyz/facade-x/ns/>
PREFIX fxe: <http://sparql.xyz/facade-x/engine/>
SELECT ?seriesName
WHERE {
SERVICE <x-sparql-anything:blank-nodes=false> {
fxe:properties fxe:location "https://sparql-anything.cc/example1.json" .
?tvSeries xyz:name ?seriesName .
?tvSeries xyz:stars ?star .
?star fx:anySlot "Courteney Cox" .
}
}Deprecated. Since version X.Y.Z,
fx:propertiesand options in thefx:namespace (e.g.fx:properties fx:location "…") are deprecated. Such queries still work, and the engine logs a warning the first time each deprecated term is used. Support will be removed in a future major release. To migrate, addPREFIX fxe: <http://sparql.xyz/facade-x/engine/>and replacefx:withfxe:in both the subject and the predicate of every option triple:fxe:properties fxe:location "…". Options in the SERVICE IRI (x-sparql-anything:location=…) are not affected.
| Option name | Description | Valid Values | Default Value |
|---|---|---|---|
| location* | The URL of the data source. | Any valid URL or (absolute or relative) path of the file system. | * |
| content* | The content to be transformed. | Any valid literal. | * |
| command* | An external command line to be executed. The output is handled according to the option 'media-type' | Any valid literal. | * |
| read-from-std-in* | It tells SPARQL Anything to read the content to be transformerd from standard input (see issue #244) | true/false | false |
| query* | The query option takes the file path of a subquery as its value. It then executes the subquery and returns the results, depending on the query type. If the subquery is a SELECT, its bindings are returned (the subquery's variables are kept). Note that if the sub-query is a SELECT, any operations contained in the SERVICE clause of the outer query are ignored. If the sub-query is a CONSTRUCT (or a CONSTRUCT Quad), the graph (or dataset) resulting from the sub-query is constructed and the operation contained in the SERVICE clause of the outer query is applied to it. Please note that if the 'query' option is set, the other options will be ignored. (See #177) |
Any valid URL or (absolute or relative) path of the file system | * |
| from-archive | The filename of the resource to be triplified within an archive. | Any filename. | No value |
| archive-format | The format of the archive whose URL is specified in from-archive. This option is needed only when the format of the archive (tar or zip) can not be guessed from the URL or the content of the file (see Issue #554). Gzip- or bzip2-compressed archives are decompressed first (see Issue #710). |
Any supported archive format ("zip", "tar") | No value |
| root | The IRI of generated root resource. The root will be used as a namespace for the graphs and containers that will be generated. | Any valid IRI. | location (in the case of location argument set) or 'http://sparql.xyz/facade-x/data/' + md5Hex(content) (in the case of content argument set) or 'http://sparql.xyz/facade-x/data/' + md5Hex(command) (in the case of command argument set) |
| media-type | The media-type of the data source. | Any valid Media-Type. Supported media types are specified in the pages dedicated to the supported formats | No value (the media-type will be guessed from the file extension or, for HTTP(S) locations, from the Content-Type of the response) |
| namespace | The namespace prefix for the properties and classes that will be generated. | Any valid namespace prefix. | http://sparql.xyz/facade-x/data/ |
| blank-nodes | It tells SPARQL Anything to generate blank nodes or not. | true/false | true |
| trim-strings | Trim all string literals. | true/false | false |
| null-string | Do not produce triples where the specified string would be in the object position of the triple. | Any string | No value |
| triplifier | It forces sparql.anything to use a specific triplifier for transforming the data source | A canonical name of a Java class | No value |
| charset | The charset of the data source. | Any charset. | UTF-8 |
| metadata | It tells SPARQL Anything to extract metadata from the data source and to store it in the named graph with URI <http://sparql.xyz/facade-x/data/metadata> More details | true/false | false |
| ondisk | It tells SPARQL Anything to use an on disk graph (instead of the default in memory graph). The string should be a path to a directory where the on disk graph will be stored. Using an on disk graph is almost always slower (than using the default in memory graph) but with it you can triplify large files without running out of memory. | A path to a directory | No value |
| ondisk.reuse | When using an on disk graph, it tells sparql.anything to reuse the previous on disk graph. | true/false | true |
| strategy | The execution strategy. 0 = in memory, all triples; 1 = in memory, only triples matching any of the triple patterns in the where clause | 0,1 | 1 |
| slice | The resource is sliced and the SPARQL query executed on each one of the parts. Supported by: CSV (row by row); JSON (when array slice by item, when json object requires json.path); XML (requires xml.path) |
true/false | false |
| slice.size | Number of slices (CSV rows, JSON items, XML matches) evaluated per query execution, when slice=true. Supported by: CSV, JSON, XML. See Slicing large files. | Any valid positive number | 1 |
| use-rdfs-member | It tells SPARQL Anything to use the (super)property rdfs:member instead of container membership properties (rdf:_1, rdf:_2 ...) | true/false | false |
| annotate-triples-with-slot-keys | It tells SPARQL Anything to annotate slot statements with slot keys (see issue #378) | true/false | false |
| generate-predicate-labels | It tells SPARQL Anything to create labels for extracted predicates and classes (see issue #462) | true/false | false |
| audit | It tells SPARQL Anything to generate an additional graph containing information for auditing the result of the triplification. The audit graph has the URI <http://sparql.xyz/facade-x/data/audit> | true/false | false |
| s3.endpoint | When set to true, the location is interpreted as an endpoint for a the S3 storage service | true/false | false |
| s3.bucket-name | The name of the s3 bucket to use as a source | Any valid bucket name | No value |
| s3.key | The path of the file to retrieve from the s3 bucket | Any valid file name | No value |
| s3.access-key | The key for accessing the s3 bucket (username) | Any valid access key | No value |
| s3.secret-key | The secret key for accessing the s3 bucket (password) | Any valid secret key | No value |
| s3.region | The region of the s3 bucket | Any valid region name | No value |
* It is mandatory to provide either location, content, command, read-from-std-in, or query.
location tells the SPARQL Anything engine the URL of the input resource.
Note
Paths beginning with '~' are resolved as the home directory of the current user.
Any valid URL or (absolute or relative) path of the file system.
It is mandatory to provide either location, content, command, read-from-std-in, or query.
UC1: Retrieving from https://sparql-anything.cc/example1.json the names of the TV Series starring Courtney Cox.
PREFIX xyz: <http://sparql.xyz/facade-x/data/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX fx: <http://sparql.xyz/facade-x/ns/>
SELECT ?seriesName
WHERE {
SERVICE <x-sparql-anything:https://sparql-anything.cc/example1.json> {
?tvSeries xyz:name ?seriesName .
?tvSeries xyz:stars ?star .
?star fx:anySlot "Courteney Cox" .
}
}Result
| seriesName |
|---|
| "Cougar Town" |
| "Friends" |
UC2: Retrieving from /absolute/path/to/example1.json the names of the TV Series starring Courtney Cox.
PREFIX xyz: <http://sparql.xyz/facade-x/data/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX fx: <http://sparql.xyz/facade-x/ns/>
SELECT ?seriesName
WHERE {
SERVICE <x-sparql-anything:/absolute/path/to/example1.json> {
?tvSeries xyz:name ?seriesName .
?tvSeries xyz:stars ?star .
?star fx:anySlot "Courteney Cox" .
}
}Result
| seriesName |
|---|
| "Cougar Town" |
| "Friends" |
UC2: Retrieving from relative/path/to/example1.json the names of the TV Series starring Courtney Cox.
PREFIX xyz: <http://sparql.xyz/facade-x/data/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX fx: <http://sparql.xyz/facade-x/ns/>
SELECT ?seriesName
WHERE {
SERVICE <x-sparql-anything:relative/path/to/example1.json> {
?tvSeries xyz:name ?seriesName .
?tvSeries xyz:stars ?star .
?star fx:anySlot "Courteney Cox" .
}
}Result
| seriesName |
|---|
| "Cougar Town" |
| "Friends" |
The content to be transformed.
Note: if the media-type is not provided, the content is interpreted as plain text.
Any valid literal.
It is mandatory to provide either location, content, command, read-from-std-in, or query.
PREFIX fx: <http://sparql.xyz/facade-x/ns/>
PREFIX fxe: <http://sparql.xyz/facade-x/engine/>
SELECT (count(*) AS ?c)
WHERE
{ SERVICE <x-sparql-anything:>
{ fxe:properties
fxe:content "one,two,three" ;
fxe:txt.split "," .
?s fx:anySlot ?o
}
}Result
-----
| c |
=====
| 3 |
-----
PREFIX fx: <http://sparql.xyz/facade-x/ns/>
PREFIX fxe: <http://sparql.xyz/facade-x/engine/>
SELECT (count(*) AS ?c)
WHERE
{ SERVICE <x-sparql-anything:>
{ fxe:properties
fxe:content "[\"one\",\"two\",\"three\", \"four\"]" ;
fxe:media-type "application/json" .
?s fx:anySlot ?o
}
}Result
-----
| c |
=====
| 4 |
-----
An external command line to be executed.
The output is handled according to the option 'media-type'. If the 'media-type' is not provided, the output is interpreted as plain text.
Note: On Linux and macOS the command is run with bash -c, so the usual shell quoting rules apply: quote arguments that contain characters such as ", [ or spaces with single quotes. On Windows the command is split on spaces that are not inside double quotes.
For example, to run echo '["one","two","three", "four"]', provide echo '[\"one\",\"two\",\"three\", \"four\"]' as the option value (the \" are the escapes of the SPARQL string; see example below).
Any valid command line.
It is mandatory to provide either location, content, command, read-from-std-in, or query.
UC1: Count the number of items in the JSON Array generated by the command echo '["one","two","three", "four"]'
PREFIX fx: <http://sparql.xyz/facade-x/ns/>
PREFIX fxe: <http://sparql.xyz/facade-x/engine/>
SELECT (COUNT(?o) AS ?nOfItems)
WHERE
{ SERVICE <x-sparql-anything:>
{ fxe:properties
fxe:command "echo '[\"one\",\"two\",\"three\", \"four\"]'" ;
fxe:media-type "application/json" .
?s fx:anySlot ?o
}
}Result
------------
| nOfItems |
============
| 4 |
------------
The query option takes the file path of a subquery as its value. It then executes the subquery and returns the results, depending on the query type. If the subquery is a SELECT, its bindings are returned (the subquery's variables are kept). Note that if the sub-query is a SELECT, any operations contained in the SERVICE clause of the outer query are ignored. If the sub-query is a CONSTRUCT (or a CONSTRUCT Quad), the graph (or dataset) resulting from the sub-query is constructed and the operation contained in the SERVICE clause of the outer query is applied to it. Please note that if the 'query' option is set, the other options will be ignored.
The value is resolved, in this order, as:
- a URL with a scheme (
file:,http:orhttps:); - a path of the file system, absolute or relative to the working directory;
- a resource on the Java classpath.
If none of these resolves, the query fails with an error naming the value.
On Windows, a path in the SERVICE IRI must use forward slashes, because IRIs cannot contain backslashes: x-sparql-anything:query=C:/data/q.rq. In the Basic Graph Pattern, a native path is a SPARQL string, so each backslash must be escaped: fxe:properties fxe:query "C:\\data\\q.rq". An unescaped \t or \n is read as a tab or a newline.
It is mandatory to provide either location, content, command, read-from-std-in, or query.
Main query
PREFIX fx: <http://sparql.xyz/facade-x/ns/>
SELECT (COUNT(?o) AS ?nOfItems)
WHERE
{ SERVICE <x-sparql-anything:query=select.rq> { }
}Sub query (select.rq)
PREFIX fx: <http://sparql.xyz/facade-x/ns/>
PREFIX fxe: <http://sparql.xyz/facade-x/engine/>
SELECT *
WHERE
{ SERVICE <x-sparql-anything:>
{ fxe:properties
fxe:content "[\"one\",\"two\",\"three\", \"four\"]" ;
fxe:media-type "application/json" .
?s fx:anySlot ?o
}
}Result
------------
| nOfItems |
============
| 4 |
------------
Main query
PREFIX fx: <http://sparql.xyz/facade-x/ns/>
SELECT (COUNT(?o) AS ?nOfItems)
WHERE
{
SERVICE <x-sparql-anything:query=construct.rq> {
?s fx:anySlot ?o
}
}Sub query (construct.rq)
PREFIX fx: <http://sparql.xyz/facade-x/ns/>
PREFIX fxe: <http://sparql.xyz/facade-x/engine/>
CONSTRUCT {
?s ?p ?o
}
WHERE
{ SERVICE <x-sparql-anything:>
{ fxe:properties
fxe:content "[\"one\",\"two\",\"three\", \"four\"]" ;
fxe:media-type "application/json" .
?s ?p ?o
}
}Result
------------
| nOfItems |
============
| 4 |
------------
The filename of the resource to be triplified within an archive.
The format of the archive can be specified via the option archive-format, which takes precedence over the file extension. Without it, the format is taken from the extension when it names an archive format (e.g. .zip, .tar), and otherwise detected from the content.
Archives compressed with gzip or bzip2 (e.g. .tar.gz, .tgz, .tar.bz2) are decompressed before the archive format is determined, so archive-format is not needed for them (see Issue #710).
This option is only required when the archive format (tar or zip) cannot be determined from the file URL or its content (see Issue #554).
Any filename
No Value
UC1: Select and triplify only .csv and .txt files within the archive available at https://sparql-anything.cc/examples/example.tar
See also Archive
PREFIX xyz: <http://sparql.xyz/facade-x/data/>
PREFIX fx: <http://sparql.xyz/facade-x/ns/>
PREFIX fxe: <http://sparql.xyz/facade-x/engine/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
CONSTRUCT
{
?s1 ?p1 ?o1 .
}
WHERE
{ SERVICE <x-sparql-anything:location=https://sparql-anything.cc/examples/example.tar>
{ fxe:properties
fxe:archive.matches ".*txt|.*csv" .
?s fx:anySlot ?file1
SERVICE <x-sparql-anything:>
{ fxe:properties
fxe:location ?file1 ;
fxe:from-archive "https://sparql-anything.cc/examples/example.tar" .
?s1 ?p1 ?o1
}
}
}
Result
@prefix fx: <http://sparql.xyz/facade-x/ns/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix xyz: <http://sparql.xyz/facade-x/data/> .
[ rdf:type fx:Root ;
rdf:_1 [ rdf:_1 "Year" ;
rdf:_2 "Make" ;
rdf:_3 "Model" ;
rdf:_4 "Description" ;
rdf:_5 "Price"
] ;
rdf:_2 [ rdf:_1 "1997" ;
rdf:_2 "Ford" ;
rdf:_3 "E350" ;
rdf:_4 "ac, abs, moon" ;
rdf:_5 "3000.00"
] ;
rdf:_3 [ rdf:_1 "1999" ;
rdf:_2 "Chevy" ;
rdf:_3 "Venture \"Extended Edition\"" ;
rdf:_4 "" ;
rdf:_5 "4900.00"
] ;
rdf:_4 [ rdf:_1 "1999" ;
rdf:_2 "Chevy" ;
rdf:_3 "Venture \"Extended Edition, Very Large\"" ;
rdf:_4 "" ;
rdf:_5 "5000.00"
] ;
rdf:_5 [ rdf:_1 "1996" ;
rdf:_2 "Jeep" ;
rdf:_3 "Grand Cherokee" ;
rdf:_4 "MUST SELL!\nair, moon roof, loaded" ;
rdf:_5 "4799.00"
]
] .
[ rdf:type fx:Root ;
rdf:_1 "this is a test"
] .
The IRI of generated root resource. The root will be used as a namespace for the graphs and containers that will be generated.
Any valid IRI.
location (in the case of location argument set)
or
'http://sparql.xyz/facade-x/data/' + md5Hex(content) (in the case of content argument set)
or
'http://sparql.xyz/facade-x/data/' + md5Hex(command) (in the case of command argument set)
UC1: Set the root of the Facade-X model generated from the JSON Object {"name":"Vincent", "surname": "Vega"} as http://example.org/myRoot
PREFIX fx: <http://sparql.xyz/facade-x/ns/>
PREFIX fxe: <http://sparql.xyz/facade-x/engine/>
CONSTRUCT
{
?s ?p ?o .
}
WHERE
{ SERVICE <x-sparql-anything:>
{ fxe:properties
fxe:content "{\"name\":\"Vincent\", \"surname\": \"Vega\"}" ;
fxe:media-type "application/json" ;
fxe:root "http://example.org/myRoot" ;
fxe:blank-nodes false .
?s ?p ?o
}
}Result
@prefix fx: <http://sparql.xyz/facade-x/ns/> .
<http://example.org/myRoot>
a fx:Root ;
<http://sparql.xyz/facade-x/data/name>
"Vincent" ;
<http://sparql.xyz/facade-x/data/surname>
"Vega" .UC2: Set the root of the Facade-X model generated from the string "Hello World!" as http://example.org/myRoot
PREFIX fx: <http://sparql.xyz/facade-x/ns/>
PREFIX fxe: <http://sparql.xyz/facade-x/engine/>
CONSTRUCT
{
?s ?p ?o .
}
WHERE
{ SERVICE <x-sparql-anything:>
{ fxe:properties
fxe:content "Hello World!" ;
fxe:root "http://example.org/myRoot" ;
fxe:blank-nodes false .
?s ?p ?o
}
}Result
@prefix fx: <http://sparql.xyz/facade-x/ns/> .
<http://example.org/myRoot> a fx:Root ;
<http://www.w3.org/1999/02/22-rdf-syntax-ns#_1> "Hello World!" .Note: blank-nodes=false is needed for generating named entities instead of blank nodes.
The media-type of the data source.
Any valid Media-Type. Supported media types are specified in the pages dedicated to the supported formats
No value (the media-type will be guessed from the file extension).
If the location is an HTTP(S) URL without a known file extension, the media-type is taken from the Content-Type header of the response (without parameters such as charset).
To read it, SPARQL Anything sends a HEAD request, and falls back on a GET request whose body is not read; both use the same http.* options as the actual request.
This is only done for GET requests: with other methods (e.g. http.method set to POST), the media-type must be given.
UC1: Enforcing media-type for content string to count the number of elements in the JSON Array ["one", "two", "three", "four"]
PREFIX fx: <http://sparql.xyz/facade-x/ns/>
PREFIX fxe: <http://sparql.xyz/facade-x/engine/>
SELECT (count(*) AS ?c)
WHERE
{ SERVICE <x-sparql-anything:>
{ fxe:properties
fxe:content "[\"one\",\"two\",\"three\", \"four\"]" ;
fxe:media-type "application/json" .
?s fx:anySlot ?o
}
}Result
-----
| c |
=====
| 4 |
-----
The namespace prefix for the properties and classes that will be generated.
Any valid namespace prefix.
http://sparql.xyz/facade-x/data/
UC1: Set the namespace prefix to http://example.org/myNamespace/ for the properties generated from the JSON Object {"name":"Vincent", "surname": "Vega"}
PREFIX fx: <http://sparql.xyz/facade-x/ns/>
PREFIX fxe: <http://sparql.xyz/facade-x/engine/>
CONSTRUCT
{
?s ?p ?o .
}
WHERE
{ SERVICE <x-sparql-anything:>
{ fxe:properties
fxe:content "{\"name\":\"Vincent\", \"surname\": \"Vega\"}" ;
fxe:media-type "application/json" ;
fxe:namespace "http://example.org/myNamespace/" .
?s ?p ?o
}
}
Result
@prefix fx: <http://sparql.xyz/facade-x/ns/> .
[ a fx:Root ;
<http://example.org/myNamespace/name>
"Vincent" ;
<http://example.org/myNamespace/surname>
"Vega"
] .It tells SPARQL Anything to generate blank nodes or not.
true/false
true
UC1: Transform the JSON Object {"name":"Vincent", "surname": "Vega", "performer" : {"name": "John", "surname": "Travolta"} } into RDF without using blank nodes
PREFIX fx: <http://sparql.xyz/facade-x/ns/>
PREFIX fxe: <http://sparql.xyz/facade-x/engine/>
CONSTRUCT
{
?s ?p ?o .
}
WHERE
{ SERVICE <x-sparql-anything:>
{ fxe:properties
fxe:content "{\"name\":\"Vincent\", \"surname\": \"Vega\", \"performer\" : {\"name\": \"John\", \"surname\": \"Travolta\"}}" ;
fxe:media-type "application/json" ;
fxe:blank-nodes false .
?s ?p ?o
}
}Result
@prefix fx: <http://sparql.xyz/facade-x/ns/> .
@prefix xyz: <http://sparql.xyz/facade-x/data/> .
<http://sparql.xyz/facade-x/data/8e6a66944bcc9366cad8377556ea2302>
a fx:Root ;
xyz:name "Vincent" ;
xyz:performer <http://sparql.xyz/facade-x/data/8e6a66944bcc9366cad8377556ea2302/performer> ;
xyz:surname "Vega" .
<http://sparql.xyz/facade-x/data/8e6a66944bcc9366cad8377556ea2302/performer>
xyz:name "John" ;
xyz:surname "Travolta" .Trim all string literals.
true/false
false
UC1: Transform the JSON Object {"name":"Vincent", "surname": "Vega", "performer" : {"name": "John ", "surname": " Travolta"} } and trim the strings "John " and " Travolta"
PREFIX fx: <http://sparql.xyz/facade-x/ns/>
PREFIX fxe: <http://sparql.xyz/facade-x/engine/>
CONSTRUCT
{
?s ?p ?o .
}
WHERE
{ SERVICE <x-sparql-anything:>
{ fxe:properties
fxe:content "{\"name\":\"Vincent\", \"surname\": \"Vega\", \"performer\" : {\"name\": \"John \", \"surname\": \" Travolta\"} }" ;
fxe:media-type "application/json" ;
fxe:trim-strings true .
?s ?p ?o
}
}
@prefix fx: <http://sparql.xyz/facade-x/ns/> .
@prefix xyz: <http://sparql.xyz/facade-x/data/> .
[ a fx:Root ;
xyz:name "Vincent" ;
xyz:performer [ xyz:name "John" ;
xyz:surname "Travolta"
] ;
xyz:surname "Vega"
] .Do not produce triples where the specified string would be in the object position of the triple.
Any string
No value
UC1: Transform the JSON Object {"name":"Vincent", "surname": "Vega", "ID": "myNull", "performer" : {"name": "John", "surname": "Travolta"} } and consider the string "myNull" as null
PREFIX fx: <http://sparql.xyz/facade-x/ns/>
PREFIX fxe: <http://sparql.xyz/facade-x/engine/>
CONSTRUCT
{
?s ?p ?o .
}
WHERE
{ SERVICE <x-sparql-anything:>
{ fxe:properties
fxe:content "{\"name\":\"Vincent\", \"surname\": \"Vega\", \"ID\": \"myNull\", \"performer\" : {\"name\": \"John\", \"surname\": \"Travolta\"} }" ;
fxe:media-type "application/json" ;
fxe:null-string "myNull" .
?s ?p ?o
}
}Result
@prefix fx: <http://sparql.xyz/facade-x/ns/> .
@prefix xyz: <http://sparql.xyz/facade-x/data/> .
[ a fx:Root ;
xyz:name "Vincent" ;
xyz:performer [ xyz:name "John" ;
xyz:surname "Travolta"
] ;
xyz:surname "Vega"
] .It forces SPARQL Anything to use a specific triplifier for transforming the data source.
A canonical name of a Java class
No value
UC1: Transform the JSON Object {"name":"Vincent", "surname": "Vega"" } (provided as a content string)into RDF by using the JSON Triplifier
PREFIX fx: <http://sparql.xyz/facade-x/ns/>
PREFIX fxe: <http://sparql.xyz/facade-x/engine/>
CONSTRUCT
{
?s ?p ?o .
}
WHERE
{ SERVICE <x-sparql-anything:>
{ fxe:properties
fxe:content "{\"name\":\"Vincent\", \"surname\": \"Vega\" }" ;
fxe:triplifier "io.github.sparqlanything.json.JSONTriplifier" .
?s ?p ?o
}
}Result
@prefix fx: <http://sparql.xyz/facade-x/ns/> .
@prefix xyz: <http://sparql.xyz/facade-x/data/> .
[ a fx:Root ;
xyz:name "Vincent" ;
xyz:surname "Vega"
] .The charset of the data source.
Any charset.
UTF-8
UC1: Triplify the UTF-16 file located at https://sparql-anything.cc/examples/utf16.txt
PREFIX fx: <http://sparql.xyz/facade-x/ns/>
PREFIX fxe: <http://sparql.xyz/facade-x/engine/>
CONSTRUCT
{
?s ?p ?o .
}
WHERE
{ SERVICE <x-sparql-anything:>
{ fxe:properties
fxe:location "https://sparql-anything.cc/examples/utf16.txt" ;
fxe:charset "UTF16" .
?s ?p ?o
}
}Result
@prefix fx: <http://sparql.xyz/facade-x/ns/> .
@prefix xyz: <http://sparql.xyz/facade-x/data/> .
[ a fx:Root ;
<http://www.w3.org/1999/02/22-rdf-syntax-ns#_1>
"UTF-16 test file"
] .It tells SPARQL Anything to use an on disk graph (instead of the default in memory graph). The string should be a path to a directory where the on disk graph will be stored. Using an on disk graph is almost always slower (than using the default in memory graph) but with it you can triplify large files without running out of memory.
A path to a directory.
No value
UC1: Use on disk graph for triplifying the JSON Object {"name":"Vincent", "surname": "Vega" } (provided as a content string).
PREFIX fx: <http://sparql.xyz/facade-x/ns/>
PREFIX fxe: <http://sparql.xyz/facade-x/engine/>
CONSTRUCT
{
?s ?p ?o .
}
WHERE
{ SERVICE <x-sparql-anything:>
{ fxe:properties
fxe:content "{\"name\":\"Vincent\", \"surname\": \"Vega\" }" ;
fxe:ondisk "/tmp" ;
fxe:media-type "application/json" .
?s ?p ?o
}
}Result
@prefix fx: <http://sparql.xyz/facade-x/ns/> .
@prefix xyz: <http://sparql.xyz/facade-x/data/> .
[ a fx:Root ;
xyz:name "Vincent" ;
xyz:surname "Vega"
] .When using an on disk graph, it tells SPARQL Anything to reuse the previous on disk graph.
true/false
true
PREFIX fx: <http://sparql.xyz/facade-x/ns/>
PREFIX fxe: <http://sparql.xyz/facade-x/engine/>
CONSTRUCT
{
?s ?p ?o .
}
WHERE
{ SERVICE <x-sparql-anything:>
{ fxe:properties
fxe:content "{\"name\":\"Vincent\", \"surname\": \"Vega\" }" ;
fxe:ondisk "/tmp/" ;
fxe:ondisk.reuse true ;
fxe:media-type "application/json" .
?s ?p ?o
}
}
Result
@prefix fx: <http://sparql.xyz/facade-x/ns/> .
@prefix xyz: <http://sparql.xyz/facade-x/data/> .
[ a fx:Root ;
xyz:name "Vincent" ;
xyz:surname "Vega"
] .Note: the result doesn't change, but no new ondisk graph is created.
The execution strategy. 0 = in memory, all triples; 1 = in memory, only triples matching any of the triple patterns in the where clause.
0, 1
1
UC1: Retrieving from relative/path/to/example1.json the names of the TV Series starring Courtney Cox.
PREFIX xyz: <http://sparql.xyz/facade-x/data/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX fx: <http://sparql.xyz/facade-x/ns/>
SELECT ?seriesName
WHERE {
SERVICE <x-sparql-anything:relative/path/to/example1.json,strategy=0> {
?tvSeries xyz:name ?seriesName .
?tvSeries xyz:stars ?star .
?star fx:anySlot "Courteney Cox" .
}
}Result
| seriesName |
|---|
| "Cougar Town" |
| "Friends" |
Note: the strategy option does not affect the result.
The resource is sliced and the SPARQL query executed on each one of the parts. Supported by: CSV (row by row); JSON (when array slice by item, when json object requires json.path); XML (requires xml.path)
See Slicing large files for how slicing works and how it affects query semantics.
true/false
false
UC1: Retrieving name and surname of the actors in https://sparql-anything.cc/examples/simpleArray.json along with the movie they performed in.
PREFIX xyz: <http://sparql.xyz/facade-x/data/>
PREFIX fx: <http://sparql.xyz/facade-x/ns/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT ?name ?surname ?movie
WHERE
{ SERVICE <x-sparql-anything:location=https://sparql-anything.cc/examples/simpleArray.json,slice=true>
{ ?p xyz:name ?name ;
xyz:surname ?surname ;
xyz:movie ?movie
}
}Result
------------------------------------------
| name | surname | movie |
==========================================
| "Vincent" | "Vega" | "Pulp fiction" |
| "Winnfield" | "Vega" | "Pulp fiction" |
| "Beatrix" | "Kiddo" | "Kill Bill" |
------------------------------------------
PREFIX xyz: <http://sparql.xyz/facade-x/data/>
PREFIX fx: <http://sparql.xyz/facade-x/ns/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT *
WHERE
{ SERVICE <x-sparql-anything:location=https://sparql-anything.cc/examples/simpleArray.json,slice=true>
{ ?p1 xyz:name ?name1 ;
xyz:surname ?surname1 ;
xyz:movie ?movie .
?p2 xyz:name ?name2 ;
xyz:surname ?surname2 ;
xyz:movie ?movie
FILTER ( ?p1 != ?p2 )
}
}
Note: the query contains a join over two slices, therefore, running the query with slicing option enabled affects the result.
Result
---------------------------------------------------------
| p1 | name1 | surname1 | movie | p2 | name2 | surname2 |
=========================================================
---------------------------------------------------------
When slice is true, this option sets how many slices (rows for CSV, items for JSON arrays/json.path matches, elements for XML xml.path) are triplified together and evaluated with a single query execution, instead of exactly one. Supported by: CSV, JSON, XML (same formats that support slice).
Increasing the value trades memory (bounded by roughly slice.size items' worth of triples at a time) for throughput, since the per-query-execution overhead is amortized over more items. As the value grows, behaviour approaches the slice=false (whole-source) case.
Note: with slice.size greater than 1, a query joining across multiple items — like UC2 above — can start producing matches within a batch, whereas with the default slice.size=1 such joins never match (each execution only ever sees one item). This is intentional: larger batches move query semantics progressively closer to the unsliced case.
Any positive integer. Invalid values (missing, non-numeric, zero or negative) fall back to 1 with a warning.
1
SERVICE <x-sparql-anything:location=allCountries.txt,media-type=text/tab-separated-values,csv.headers=true,slice=true,slice.size=100000> {
fxe:properties fxe:csv.delimiter "\t" .
...
}allCountries.txt is a tab-separated file with a .txt extension, so the media type selects the CSV triplifier (by extension, .txt would be read as plain text). The tab delimiter is given in the basic graph pattern, because the SERVICE IRI does not decode escapes such as %09.
Triplifies and evaluates 100,000 rows per query execution instead of one, bounding memory to ~100k rows' worth of triples while avoiding per-row invocation overhead.
It tells SPARQL Anything to use the (super)property rdfs:member instead of container membership properties (rdf:_1, rdf:_2 ...)
true/false
false
UC1: Using rdfs:member instead of container membership properties for triplifying the JSON Array [1,2,3]
PREFIX xyz: <http://sparql.xyz/facade-x/data/>
PREFIX fx: <http://sparql.xyz/facade-x/ns/>
PREFIX fxe: <http://sparql.xyz/facade-x/engine/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
CONSTRUCT
{
?s ?p ?o .
}
WHERE
{ SERVICE <x-sparql-anything:>
{ fxe:properties
fxe:use-rdfs-member true ;
fxe:content "[1,2,3]" ;
fxe:media-type "application/json" .
?s ?p ?o
}
}Result
@prefix fx: <http://sparql.xyz/facade-x/ns/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix xyz: <http://sparql.xyz/facade-x/data/> .
[ rdf:type fx:Root ;
rdfs:member "3"^^xsd:decimal , "2"^^xsd:decimal , "1"^^xsd:decimal
] .It tells SPARQL Anything to annotate slot statements with slot keys (see issue #378)
true/false
false
UC1: Using rdfs:member instead of container membership properties for triplifying the JSON Array [1,2,3], but keeping the ordinal number of the slots
PREFIX xyz: <http://sparql.xyz/facade-x/data/>
PREFIX fx: <http://sparql.xyz/facade-x/ns/>
PREFIX fxe: <http://sparql.xyz/facade-x/engine/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
CONSTRUCT
{
?s ?p ?o .
}
WHERE
{ SERVICE <x-sparql-anything:>
{ fxe:properties
fxe:use-rdfs-member true ;
fxe:content "[1,2,3]" ;
fxe:annotate-triples-with-slot-keys true ;
fxe:media-type "application/json" .
?s ?p ?o
}
}Result
@prefix fx: <http://sparql.xyz/facade-x/ns/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix xyz: <http://sparql.xyz/facade-x/data/> .
<< _:b0 rdfs:member "1"^^xsd:decimal >>
fx:slot-key 1 .
_:b0 rdf:type fx:Root ;
rdfs:member "3"^^xsd:decimal , "2"^^xsd:decimal , "1"^^xsd:decimal .
<< _:b0 rdfs:member "2"^^xsd:decimal >>
fx:slot-key 2 .
<< _:b0 rdfs:member "3"^^xsd:decimal >>
fx:slot-key 3 .It tells SPARQL Anything to create labels for extracted predicates and classes (see issue #462)
true/false
false
PREFIX xyz: <http://sparql.xyz/facade-x/data/>
PREFIX fx: <http://sparql.xyz/facade-x/ns/>
PREFIX fxe: <http://sparql.xyz/facade-x/engine/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
CONSTRUCT
{
?s ?p ?o .
}
WHERE
{ SERVICE <x-sparql-anything:>
{ fxe:properties
fxe:content "<Element1 attr=\"value\"/> " ;
fxe:generate-predicate-labels true ;
fxe:media-type "application/xml" .
?s ?p ?o
}
}Result
PREFIX fx: <http://sparql.xyz/facade-x/ns/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX xyz: <http://sparql.xyz/facade-x/data/>
[ rdf:type xyz:Element1 , fx:Root;
xyz:attr "value"
] .
xyz:attr <http://www.w3.org/2000/01/rdf-schema#label>
"attr" .
xyz:Element1 <http://www.w3.org/2000/01/rdf-schema#label>
"Element1" .It tells SPARQL Anything to read the content to be transformed from standard input channel (STDIN) -- see issue #244.
When it is set to true, the engine reads from the STDIN and sets the input as the value for the content option.
Therefore, the input from the STDIN is processed as inline content (and the inline content is overwritten by the input from the STDIN).
true/false
false
SELECT ?v {
SERVICE <x-sparql-anything:read-from-std-in=true> {
?root a <http://sparql.xyz/facade-x/ns/Root> ;
<http://www.w3.org/1999/02/22-rdf-syntax-ns#_1> ?v
}
}Standard Input
abc
Result
| ?v |
|---|
| abc |
It tells SPARQL Anything to generate an additional graph containing information for auditing the result of the triplification. The audit graph has the URI <http://sparql.xyz/facade-x/data/audit> For each content graph generated by the triplifier, the audit graph specifies:
- the graph name;
- the number of triples in the content graph;
- whether the graph was retrieved from the cache;
- the datetime when the graph was created;
- a string representation of the SPARQL algebra of the operation that generated the graph.
Note Do not use strategy 1 (i.e. triple filtering) for querying the audit graph (specifically, do not add triple patterns matching the audit graph) otherwise the engine will filter out all the triples in the content graph.
true/false
false
CONSTRUCT
{
GRAPH ?g
{ ?s ?p ?o .}
}
WHERE
{ SERVICE <x-sparql-anything:content=abc,audit=true,strategy=0>
{ GRAPH ?g
{ ?s ?p ?o }
}
}
Result
<http://sparql.xyz/facade-x/data/900150983cd24fb0d6963f7d28e17f72> {
[ a <http://sparql.xyz/facade-x/ns/Root>;
<http://www.w3.org/1999/02/22-rdf-syntax-ns#_1>
"abc"
] .
}
<http://sparql.xyz/facade-x/data/audit> {
<http://sparql.xyz/facade-x/data/900150983cd24fb0d6963f7d28e17f72>
a <http://www.w3.org/ns/sparql-service-description#NamedGraph>;
<http://rdfs.org/ns/void#triples>
"2"^^<http://www.w3.org/2001/XMLSchema#long>;
<http://sparql.xyz/facade-x/ns/cachedGraph>
false;
<http://sparql.xyz/facade-x/ns/cachedGraphCreation>
"2024-09-03T14:32:57.174Z"^^<http://www.w3.org/2001/XMLSchema#dateTime>;
<http://sparql.xyz/facade-x/ns/sparqlAlgebra>
"(service <x-sparql-anything:content=abc,audit=true,strategy=0>\n (graph ?g\n (bgp (triple ?s ?p ?o))))\n";
<http://www.w3.org/ns/sparql-service-description#name>
"http://sparql.xyz/facade-x/data/900150983cd24fb0d6963f7d28e17f72" .
<http://sparql.xyz/facade-x/data/audit#root>
<http://www.w3.org/ns/sparql-service-description#namedGraph>
<http://sparql.xyz/facade-x/data/900150983cd24fb0d6963f7d28e17f72> .
}When set to true, the result of the triplification is cached in memory and persists across multiple query executions until the process terminates. This is the user-level cache. (see issue #371, #372, and #585).
Note: Even when use-cache=false (default), SPARQL Anything uses an internal query cache that is automatically enabled for each query execution. This internal cache prevents redundant triplification when the same source is accessed multiple times within a single query (e.g., nested SERVICE clauses). The internal cache is automatically cleared after each query completes.
You can check out whether a query has been evaluated over a cached graph via the fx:cachedGraph assertion of the audit graph.
When to use use-cache=true:
- When executing multiple queries against the same data sources
- When the data sources are large and expensive to triplify
- When the data in the source doesn't change
When to keep use-cache=false (default):
- When source data might chang between query executions
- When memory is limited
- For one-off queries
true/false
false
Controls how the functions fx:entity, fx:literal and fx:bnode behave when they cannot build a valid term (see issue #712).
The option can be set in the SERVICE IRI, in which case it applies to the functions evaluated inside that SERVICE clause, or at query level with -c fx.onerror=<value> (or in the ARQ context when SPARQL Anything is used as a library), in which case it applies to the whole query, including expressions outside any SERVICE clause. The value in the SERVICE IRI takes precedence.
The SPARQL built-in functions (IRI(), STRLANG(), STRDT(), ...) are not affected.
| Value | Behaviour |
|---|---|
unbound |
SPARQL semantics: an evaluation error is raised and the variable is left unbound. Nothing is logged. |
warn |
As unbound, plus a warning in the log naming the function, its arguments and the solution being evaluated. |
fail |
The query is aborted with the same message as warn. |
lenient |
No validation (behaviour before version X.Y). For example, fx:entity("some space") produces the IRI <some space>. |
unbound
fx:entity: the concatenated string is not a valid IRI. Relative IRIs are resolved against the query'sBASE(or the system base if none is declared), as withIRI(). Withlenient, relative IRIs are not resolved.fx:literal(?a, ?b):?bis neither an IRI nor a non-empty string. As withSTRDT()andSTRLANG(), the lexical form and the language tag are not validated.- All three functions: one or more arguments are unbound or fail to evaluate. The function call is reported once, listing all its arguments.
The solution printed by warn and fail includes the bindings of the query, for example ?slot. Binding fx:cardinal(?slot) gives the position of the record in a CSV file. Note that this is not the line number when quoted cells contain newlines.
With fail, an error inside fx:entity cannot be caught by an enclosing COALESCE. To provide a fallback for an optional value, wrap the argument instead:
BIND(fx:entity(ex:, COALESCE(?id, "unknown")) AS ?s)java -jar sparql-anything-<version>.jar -q mapping.sparql -c fx.onerror=failSPARQL Anything relies on Apache Commons HTTP for HTTP connections.
| Option name | Description | Valid Values | Default Value |
|---|---|---|---|
| http.client.* | Calls methods on the HTTPClient Java object. E.g. http.client.useSystemProperties=false means to avoid inheriting Java system properties (Default 'yes') |
||
| http.client.useSystemProperties | Use Java System Properties to configure the HTTP Client. | true/false | true |
| http.header.* | To add headers to the HTTP request. E.g. http.header.accept=application/json |
||
| http.query.* | To add parameters to the query string. E.g. http.query.var=value. To repeat a parameter, add a numeric suffix: http.query.var.1=a, http.query.var.2=b sends var=a&var=b (see below) |
||
| http.form.* | To add form parameters to the request body (application/x-www-form-urlencoded). E.g. http.form.var=value. Numeric suffixes work as for http.query.* |
||
| http.method | HTTP Method | GET,POST,... | GET |
| http.payload | Sets the body of the request. Sent only with methods that have a body (POST, PUT, PATCH), with a Content-Length header. Set the content type with http.header.Content-Type |
||
| http.protocol | Protocol | 0.9,1.0,1.1 | 1.1 |
| http.auth.user | Authentication: user name | ||
| http.auth.password | Authentication: password | ||
| http.redirect | Follow redirects? With false, a 3xx response is not followed and the query fails like for any other non-2xx status |
true,false | true |
| http.sleep | Wait the given milliseconds before sending the request |
Options are a map, so the same option name cannot be given twice. To send a query string (or form) parameter more than once, append .N to the name, where N is a number. The suffix is removed from the parameter name, and the values are sent in numeric order (.2 before .10); a parameter without a suffix comes first.
PREFIX fxe: <http://sparql.xyz/facade-x/engine/>
SELECT * WHERE {
SERVICE <x-sparql-anything:> {
fxe:properties fxe:location "https://example.org/data" ;
fxe:http.query.tag.1 "a" ;
fxe:http.query.tag.2 "b" ;
fxe:http.query.tag.10 "j" .
?s ?p ?o
}
}The request is GET https://example.org/data?tag=a&tag=b&tag=j.
http.payload is sent as the request body for POST, PUT and PATCH; with other methods it is ignored and a warning is logged. No content type is added by default:
PREFIX fxe: <http://sparql.xyz/facade-x/engine/>
SELECT * WHERE {
SERVICE <x-sparql-anything:> {
fxe:properties fxe:location "https://example.org/api" ;
fxe:media-type "application/json" ;
fxe:http.method "POST" ;
fxe:http.header.Content-Type "application/json" ;
fxe:http.payload """{"q":1}""" .
?s ?p ?o
}
}SPARQL Anything can read a resource stored in an Amazon S3 bucket, or in any S3-compatible object storage service (e.g. MinIO), as the input of a query (see issue #560). S3 support is provided by the separate sparql-anything-s3-support module; see the S3 page for setup, examples, and caveats.
| Option name | Description | Required |
|---|---|---|
s3.endpoint |
The URL of the S3-compatible endpoint (e.g. https://s3.amazonaws.com, or a MinIO instance URL). Setting this property routes the request through the S3 service instead of a plain HTTP(S) request. |
Yes |
s3.bucket-name |
The name of the bucket containing the object to read. | Yes |
s3.key |
The key (path) of the object within the bucket. | Yes |
s3.access-key |
The access key used to authenticate against the S3-compatible service. | Yes |
s3.secret-key |
The secret key used to authenticate against the S3-compatible service. | Yes |
s3.region |
The AWS region to use (e.g. us-east-1). Required by the AWS SDK even against non-AWS services such as MinIO. |
Yes |