Overview
RDFQ Vocabulary
RDFQ Service Parameters
The Nokia RDFQ Service
ExamplesThe following examples illustrate a broad range of queries which can be expressed in RDFQ. Note: because the Nokia RDFQ service implementation supports basic inference, which is always applied when evaluating the input query graph (even if not applied to the execution of the query itself on the knowlege base), it is able to infer the rdf:type of rdfq:Query, rdfq:Target, and rdfq:Value resources based on the defined rdfs:range and rdfs:domain of the RDFQ vocabulary terms. Thus, queries can be expressed in Turtle in a more compact form. This compact form is shown following each full Turtle example. Implementations supporting queries expressed in Turtle SHOULD apply rdfs:range and rdfs:domain closures for RDFQ vocabulary terms used in input queries, even if inference is not otherwise supported, so as to facilitate the more compact form of expression. The following namespaces declarations are presumed for all examples:
dc http://purl.org/dc/elements/1.1/
dct http://purl.org/dc/terms/
rss http://purl.org/rss/1.0/
xsd http://www.w3.org/2001/XMLSchema#
ex http://example.org/
voc http://sw.nokia.com/VOC-1/
{default} http://sw.nokia.com/RDFQ-1/
Match all resources having a dc:title defined, returning the concise bounded description of each matched resource: RDF/XML:
<rdfq:Query>
<rdfq:target>
<rdfq:Target>
<dc:title>
<rdfq:Value/>
</dc:title>
</rdfq:Target>
</rdfq:target>
</rdfq:Query>
Turtle: [a rdfq:Query; rdfq:target [a rdfq:Target; dc:title [a rdfq:Value]]]. or [:target [dc:title []]]. Match all resources having a dc:title defined, returning the variable bindings for 'target' and 'title' for each matched resource: RDF/XML:
<rdfq:Query>
<rdfq:select>
<rdf:List>
<rdf:first>target</rdf:first>
<rdf:rest>
<rdf:List>
<rdf:first>title</rdf:first>
<rdf:rest rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#nil"/>
</rdf:List>
</rdf:rest>
</rdf:List>
</rdfq:select>
<rdfq:target>
<rdfq:Target>
<rdfq:id>
target
</rdfq:id>
<dc:title>
<rdfq:Value>
<rdfq:id>
title
</rdfq:id>
</rdfq:Value>
</dc:title>
</rdfq:Target>
</rdfq:target>
</rdfq:Query>
Turtle:
[a rdfq:Query; rdfq:select ("target" "title");
rdfq:target [a rdfq:Target; rdfq:id "target"; dc:title [a rdfq:Value; rdfq:id "title"]]].
or
[:select ("target" "title"); :target [:id "target"; dc:title [:id "title"]]].
Match all resources which have no rdfs:comment defined: RDF/XML:
<rdfq:Query>
<rdfq:target>
<rdfq:Target>
<rdfs:comment rdf:resource="http://sw.nokia.com/RDFQ-1/null"/>
</rdfq:Target>
</rdfq:target>
</rdfq:Query>
Turtle: [a rdfq:Query; rdfq:target [a rdfq:Target; rdfs:comment rdfq:null]]. or [:target [rdfs:comment :null]]. Match all resources having any property with a value equal to ten: RDF/XML:
<rdfq:Query>
<rdfq:target>
<rdfq:Target>
<rdfq:property rdf:datatype="http://www.w3.org/2001/XMLSchema#integer">10</rdfq:property>
</rdfq:Target>
</rdfq:target>
</rdfq:Query>
Turtle: [a rdfq:Query; rdfq:target [a rdfq:Target; rdfq:property "10"^^xsd:integer]]. or [:target [:property "10"^^xsd:integer]]. Match all resources having a dc:language equal to English: RDF/XML:
<rdfq:Query>
<rdfq:target>
<rdfq:Target>
<dc:language rdf:datatype="http://www.w3.org/2001/XMLSchema#lang">en</dc:language>
</rdfq:Target>
</rdfq:target>
</rdfq:Query>
Turtle: [a rdfq:Query; rdfq:target [a rdfq:Target; dc:language "en"^^xsd:lang]]. or [:target [dc:language "en"^^xsd:lang]]. Match all resources having a dc:language not equal to English: RDF/XML:
<rdfq:Query>
<rdfq:target>
<rdfq:Target>
<dc:language>
<rdfq:Value>
<rdfq:ne rdf:datatype="http://www.w3.org/2001/XMLSchema#lang">en</rdfq:ne>
</rdfq:Value>
</dc:language>
</rdfq:Target>
</rdfq:target>
</rdfq:Query>
Turtle: [a rdfq:Query; rdfq:target [a rdfq:Target; dc:language [a rdfq:Value; rdfq:ne "en"^^xsd:lang]]]. or [:target [dc:language [:ne "en"^^xsd:lang]]]. Match all resources having an rdfs:label matching a particular regular expression: RDF/XML:
<rdfq:Query>
<rdfq:target>
<rdfq:Target>
<rdfs:label>
<rdfq:Value>
<rdfq:re>[a-zA-Z][-_a-zA-Z0-9]*</rdfq:re>
</rdfq:Value>
</rdfs:label>
</rdfq:Target>
</rdfq:target>
</rdfq:Query>
Turtle: [a rdfq:Query; rdfq:target [a rdfq:Target; rdfs:label [a rdfq:Value; rdfq:re "[a-zA-Z][-_a-zA-Z0-9]*"]]. or [:target [rdfs:label [:re "[a-zA-Z][-_a-zA-Z0-9]*"]]. Match all resources having an rdfs:label specified as Finnish: RDF/XML:
<rdfq:Query>
<rdfq:target>
<rdfq:Target>
<rdfs:label>
<rdfq:Value>
<rdfq:lang>fi</rdfq:lang>
</rdfq:Value>
</rdfs:label>
</rdfq:Target>
</rdfq:target>
</rdfq:Query>
Turtle: [a rdfq:Query; rdfq:target [a rdfq:Target; rdfs:label [a rdfq:Value; rdfq:lang "fi"]]. or [:target [rdfs:label [:lang "fi"]]. Match all resources where their dct:modified timestamp occurs between the specified timestamps (match exclusive): RDF/XML:
<rdfq:Query>
<rdfq:target>
<rdfq:Target>
<dct:modified>
<rdfq:Value>
<rdfq:gt rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">2001-08-11T10:30:00Z</rdfq:gt>
<rdfq:lt rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">2002-02-28T20:45:00Z</rdfq:lt>
</rdfq:Value>
</dct:modified>
</rdfq:Target>
</rdfq:target>
</rdfq:Query>
Turtle:
[a rdfq:Query;
rdfq:target
[a rdfq:Target;
dct:modified
[a rdfq:Value;
rdfq:gt "2001-08-11T10:30:00Z"^^xsd:dateTime;
rdfq:lt "2002-02-28T20:45:00Z"^^xsd:dateTime
]
]
].
or [:target [dct:modified [:gt "2001-08-11T10:30:00Z"^^xsd:dateTime; :lt "2002-02-28T20:45:00Z"^^xsd:dateTime]]]. Match all targets where their dct:modified timestamp occurs between, or equal to either of the specified timestamps (match inclusive): RDF/XML:
<rdfq:Query>
<rdfq:target>
<rdfq:Target>
<dct:modified>
<rdfq:Value>
<rdfq:ge rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">2001-08-11T10:30:00Z</rdfq:ge>
<rdfq:le rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">2002-02-28T20:45:00Z</rdfq:le>
</rdfq:Value>
</dct:modified>
</rdfq:Target>
</rdfq:target>
</rdfq:Query>
Turtle:
[a rdfq:Query;
rdfq:target
[a rdfq:Target;
dct:modified
[a rdfq:Value;
rdfq:ge "2001-08-11T10:30:00Z"^^xsd:dateTime;
rdfq:le "2002-02-28T20:45:00Z"^^xsd:dateTime
]
]
].
or [:target [dct:modified [:ge "2001-08-11T10:30:00Z"^^xsd:dateTime; :le "2002-02-28T20:45:00Z"^^xsd:dateTime]]]. Match all resources where the dct:modified value is between or equal to either of the two specified timestamps, and which have values defined for both dc:title and dc:creator: RDF/XML:
<rdfq:Query>
<rdfq:target>
<rdfq:Target>
<dct:modified>
<rdfq:Value>
<rdfq:ge rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">2001-08-11T10:30:00Z</rdfq:ge>
<rdfq:le rdf:datatype="http://www.w3.org/2001/XMLSchema#dateTime">2002-02-28T20:45:00Z</rdfq:le>
</rdfq:Value>
</dct:modified>
<dc:title>
<rdfq:Value/>
</dc:title>
<dc:creator>
<rdfq:Value/>
</dc:creator>
</rdfq:Target>
</rdfq:target>
</rdfq:Query>
Turtle:
[a rdfq:Query;
rdfq:target
[a rdfq:Target;
dct:modified
[a rdfq:Value;
rdfq:ge "2001-08-11T10:30:00Z"^^xsd:dateTime;
rdfq:le "2002-02-28T20:45:00Z"^^xsd:dateTime
];
dc:title
[a rdfq:Value];
dc:creator
[a rdfq:Value]
]
].
or
[:target [dct:modified [:ge "2001-08-11T10:30:00Z"^^xsd:dateTime; :le "2002-02-28T20:45:00Z"^^xsd:dateTime]
dc:title [];
dc:creator []]].
Match all resources where the dct:created value is equal to the dct:modified value: RDF/XML:
<rdfq:Query>
<rdfq:target>
<rdfq:Target>
<dct:created>
<rdfq:Value rdfq:id="x"/>
</dct:created>
<dct:modified>
<rdfq:Value rdfq:id="x"/>
</dct:modified>
</rdfq:Target>
</rdfq:target>
</rdfq:Query>
Turtle:
[a rdfq:Query;
rdfq:target
[a rdfq:Target;
dct:created [a rdfq:Value; rdfq:id "x"];
dct:modified [a rdfq:Value; rdfq:id "x"]
]
].
or [:target [dct:created [:id "x"]; dct:modified [:id "x"]]]. Match all resources where the dct:modified value is less than one week ago (i.e. all resources modified in the last week): RDF/XML:
<rdfq:Query>
<rdfq:target>
<rdfq:Target>
<dct:modified>
<rdfq:Value>
<rdfq:le rdf:resource="http://sw.nokia.com/RDFQ-1/one-week-ago"/>
</rdfq:Value>
</dct:modified>
</rdfq:Target>
</rdfq:target>
</rdfq:Query>
Turtle: [a rdfq:Query; rdfq:target [a rdfq:Target; dct:modified [a rdfq:Value; rdfq:le rdfq:one-week-ago]]]. or [:target [dct:modified [:le :one-week-ago]]]. Match all resources which have a dc:creator which an ex:Person who has a ex:firstName of "John", an ex:lastName of "Doe" and has an ex:age that is greater than 30: RDF/XML:
<rdfq:Query>
<rdfq:target>
<rdfq:Target>
<dc:creator>
<rdfq:Value>
<rdf:type rdf:resource="http://example.org/Person"/>
<ex:firstName>John</ex:firstName>
<ex:lastName>Doe</ex:lastName>
<ex:age>
<rdfq:Value>
<rdfq:gt rdf:datatype="http://www.w3.org/2001/XMLSchema#integer">30</rdfq:gt>
</rdfq:Value>
</ex:age>
</ex:Person>
</dct:modified>
</rdfq:Target>
</rdfq:target>
</rdfq:Query>
Turtle:
[a rdfq:Query;
rdfq:target
[a rdfq:Target;
dc:creator
[a rdfq:Value;
rdf:type ex:Person;
ex:firstName "John";
ex:lastName "Doe";
ex:age [a rdfq:Value; rdfq:gt "30"^^xsd:integer]
]
]
].
or [:target [dc:creator [a ex:Person; ex:firstName "John"; ex:lastName "Doe"; ex:age [:gt "30"^^xsd:integer]]]]. Return the descriptions of all of the explicitly specified resources: RDF/XML: <rdfq:Query> <rdfq:target rdf:resource="http://example.com/foo"/> <rdfq:target rdf:resource="http://example.com/bar"/> <rdfq:target rdf:resource="http://example.com/bas"/> <rdfq:target rdf:resource="http://example.com/boo"/> </rdfq:Query> Turtle: [a rdfq:Query; rdfq:target <http://example.com/foo>; rdfq:target <http://example.com/bar>; rdfq:target <http://example.com/bas>; rdfq:target <http://example.com/boo> ]. or [:target <http://example.com/foo>; :target <http://example.com/bar>; :target <http://example.com/bas>; :target <http://example.com/boo>]. Return the descriptions of all of the explicitly specified resources (equivalent to the above): RDF/XML:
<rdfq:Query>
<rdfq:target>
<rdfq:Target>
<rdfq:resource rdf:resource="http://example.com/foo"/>
</rdfq:Target>
</rdfq:target>
<rdfq:target>
<rdfq:Target>
<rdfq:resource rdf:resource="http://example.com/bar"/>
</rdfq:Target>
</rdfq:target>
<rdfq:target>
<rdfq:Target>
<rdfq:resource rdf:resource="http://example.com/bas"/>
</rdfq:Target>
</rdfq:target>
<rdfq:target>
<rdfq:Target>
<rdfq:resource rdf:resource="http://example.com/boo"/>
</rdfq:Target>
</rdfq:target>
</rdfq:Query>
Turtle: [a rdfq:Query; rdfq:target [a rdfq:Target; rdfq:resource <http://example.com/foo>]; rdfq:target [a rdfq:Target; rdfq:resource <http://example.com/bar>]; rdfq:target [a rdfq:Target; rdfq:resource <http://example.com/bas>]; rdfq:target [a rdfq:Target; rdfq:resource <http://example.com/boo>] ]. or [:target [:resource <http://example.com/foo>]; :target [:resource <http://example.com/bar>]; :target [:resource <http://example.com/bas>]; :target [:resource <http://example.com/boo>]]. Return a description of the explicitly specified resource, but only if it has a value defined for the dc:title property: RDF/XML:
<rdfq:Query>
<rdfq:target>
<rdfq:Target>
<rdfq:resource rdf:resource="http://example.com/foo"/>
<dc:title>
<rdfq:Value/>
</dc:title>
</rdfq:Target>
</rdfq:target>
</rdfq:Query>
Turtle:
[a rdfq:Query;
rdfq:target
[a rdfq:Target;
rdfq:resource <http://example.com/foo>;
dc:title [a rdfq:Value]
]
].
or [:target [:resource <http://example.com/foo>; dc:title []]]. Match all terms which belong to the specified vocabulary: RDF/XML:
<rdfq:Query>
<rdfq:target>
<rdfq:Target>
<rdf:type rdf:resource="http://sw.nokia.com/VOC-1/Term"/>
<voc:partOf rdf:resource="http://example.com/vocabulary/X"/>
</rdfq:Target>
</rdfq:target>
</rdfq:Query>
Turtle:
[a rdfq:Query;
rdfq:target [a rdfq:Target;
rdf:type voc:Term;
voc:partOf <http://example.com/vocabulary/X>
]
].
or [:target [a voc:Term; voc:partOf <http://example.com/vocabulary/X>]]. Match all resources where the dct:modified value is less than one week ago, and which have a value defined for both the dc:title and dc:description properties: RDF/XML:
<rdfq:Query>
<rdfq:target>
<rdfq:Target>
<dct:modified>
<rdfq:Value>
<rdfq:le rdf:resource="http://sw.nokia.com/RDFQ-1/one-week-ago"/>
</rdfq:Value>
</dct:modified>
<dc:title>
<rdfq:Value/>
</dc:title>
<dc:description>
<rdfq:Value/>
</dc:description>
</rdfq:Target>
</rdfq:target>
</rdfq:Query>
Turtle:
[a rdfq:Query;
rdfq:target
[a rdfq:Target;
dct:modified [a rdfq:Value; rdfq:le rdfq:one-week-ago];
dc:title [a rdfq:Value];
dc:description [a rdfq:Value]
]
].
or [:target [dct:modified [:le :one-week-ago]; dc:title []; dc:description []]]. Match all statements, returning the bindings to the variables "subject", "predicate", and "object": RDF/XML:
<rdfq:Query>
<rdfq:select>
<rdf:List>
<rdf:first>subject</rdf:first>
<rdf:rest>
<rdf:List>
<rdf:first>predicate</rdf:first>
<rdf:rest>
<rdf:List>
<rdf:first>object</rdf:first>
<rdf:rest rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#nil"/>
</rdf:List>
</rdf:rest>
</rdf:List>
</rdf:rest>
</rdf:List>
</rdfq:select>
<rdfq:target>
<rdfq:Target>
<rdfq:id>
subject
</rdfq:id>
<rdfq:property>
<rdfq:Value>
<rdfq:id>
object
</rdfq:id>
<rdfq:predicate>
<rdfq:Predicate>
<rdfq:id>
predicate
</rdfq:id>
</rdfq:Predicate>
</rdfq:predicate>
</rdfq:Value>
</dc:title>
</rdfq:Target>
</rdfq:target>
</rdfq:Query>
Turtle:
[a rdfq:Query; rdfq:select ("subject" "predicate" "object");
rdfq:target [a rdfq:Target;
rdfq:id "subject";
rdfq:property [a rdfq:Value;
rdfq:id "object";
rdfq:predicate [a rdfq:Predicate;
rdfq:id "predicate"]]]].
or
[:select ("subject" "predicate" "object");
:target [:id "subject"; :property [:id "object"; :predicate [:id "predicate"]]]].
Note the significant utility of compression provided by the minimal Turtle form in this last example!
|