Query and Rule languages Use Cases and Examples

Produced: Thu Jun 17 10:46:59 CEST 2004

Alberto Reggiori and Andy Seaborne

1: Plot Cities on a Map  

Take Libby Miller her list of citys - and plot the onces starting with 'port' on a OpenGIS.org Web Mapping Server. See: http://demo.asemantics.com/biz/swad-e/rdqlplot.pl

See also: http://www.asemantics.com/showcase/wms.html

Published by Dirk-Willem van Gulik on 2003-11-14

Examples [ Add new example ]

1. Query example provided by Dirk Willem van Gulik on 2003-11-20 expressed using the RDQL language select
        ?uri,?name, ?lat, ?lon 
from 
        <http://swordfish.rdfweb.org/discovery/2003/11/cities/xmlrdf.jsp?query=port> 
where
        (?city, <rdfs:label>, ?name), 
        (?city, <rdfs:label>,?uri),
        (?city, <pos:lat>, ?lat), 
        (?city, <pos:long>, ?lon) 
using
        rdfs FOR   <http://www.w3.org/2000/01/rdf-schema#>,
        pos FOR <http://www.w3.org/2003/01/geo/wgs84_pos#>,
        doilair FOR <http://www.daml.org/2001/10/html/airport-ont#>,
        vcard FOR <http://www.w3.org/vcard-rdf/3.0#>
The above query can be run by using http://rdfstore.sourceforge.net.

2: Plot a Person onto a map  

Take a single FOAF - and plot it on a OpenGIS.org Web Mapping Server. See: http://demo.asemantics.com/biz/swad-e/rdqlplot.pl

See also: http://www.asemantics.com/showcase/wms.html

Published by Dirk-Willem van Gulik on 2003-11-14

Examples [ Add new example ]

1. Query example provided by Dirk Willem van Gulik on 2003-11-20 expressed using the RDQL language select
        ?uri,?name, ?lat, ?lon 
from 
        <http://foaf.asemantics.com/dirkx>
where
        (?person, <rdf:type>, <foaf:Person>), 
        (?person, <foaf:name>, ?name), 
        (?person, <foaf:based_near>, ?bn), 
        (?person, <foaf:mbox>,?uri),
        (?bn, <pos:lat>, ?lat), 
        (?bn, <pos:long>, ?lon) 
using
        rdf FOR <http://www.w3.org/1999/02/22-rdf-syntax-ns#>, 
        rdfs FOR <http://www.w3.org/2000/01/rdf-schema#>, 
        foaf FOR <http://xmlns.com/foaf/0.1/>, 
        dc FOR <http://purl.org/dc/elements/1.1/>, 
        pos FOR <http://www.w3.org/2003/01/geo/wgs84_pos#>
The above query can be run by using http://rdfstore.sourceforge.net.

3: Plot Airports onto a map  

Take an Airport Ontoogy - and plot them on a OpenGIS.org Web Mapping Server. See: http://demo.asemantics.com/biz/swad-e/rdqlplot.pl

See also: http://www.asemantics.com/showcase/wms.html

Published by Dirk-Willem van Gulik on 2003-11-14

Examples [ Add new example ]

1. Query example provided by Dirk Willem van Gulik on 2003-11-20 expressed using the RDQL language select
        ?uri,?name, ?lat, ?lon 
from 
      <http://foaf.asemantics.com//few.airports.rdf>
where
        (?airport, <airportonto:name>, ?name), 
        (?airport, <airportonto:location>,?uri),
        (?airport, <airportonto:longitude>, ?lon), 
        (?airport, <airportonto:latitude>, ?lat) 
using
        rdf FOR <http://www.w3.org/1999/02/22-rdf-syntax-ns#>, 
        rdfs FOR <http://www.w3.org/2000/01/rdf-schema#>, 
        foaf FOR <http://xmlns.com/foaf/0.1/>, 
        dc FOR <http://purl.org/dc/elements/1.1/>, 
        pos FOR <http://www.w3.org/2003/01/geo/wgs84_pos#>,
        airportonto FOR <http://www.daml.org/2001/10/html/airport-ont#>
The above query can be run by using http://rdfstore.sourceforge.net.

4: For the given resource find the title, the subject, the description and their languages together with the language of the resource and its URL  

For the given RDF DC/DCQ resource description find the dc:title, the dc:subject (encoded using the ETB multilingual thesaurus), the dc:description and their dc:language qualification; in addition retrieve the dc:language of the resource and dc:identifier given the URL pointing to it.

See also: http://etb.eun.org

Published by Alberto Reggiori on 2002-06-25

Examples [ Add new example ]

1. Query example provided by Tim Berners-Lee on 2003-03-02 expressed using the N3 language @prefix     rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
@prefix     dc:  <http://purl.org/dc/elements/1.1/>.
@prefix     dcq:  <http://purl.org/dc/terms/>.
@prefix     etbthes: <http://eun.org/etb/thesaurus/elements/>.

@prefix rss: <http://purl.org/rss/1.0/>.
@prefix log: <http://www.w3.org/2000/10/swap/log#>.
@prefix string: <http://www.w3.org/2000/10/swap/string#>.
@prefix : <#>.
@prefix result: <result#>.


{
  [   dc:title [
          rdf:value ?title_value;
          dc:language [dcq:RFC1766 ?title_language]];
      dc:subject [
          etbthes:ETBT [
              rdf:value ?subject_value;
              dc:language [dcq:RFC1766 ?subject_language]]];
      dc:description [
          rdf:value ?description_value;
          dc:language [dcq:RFC1766 ?description_language]];
      dc:identifier ?identifier;
      dc:language [dcq:RFC1766 ?language]].
} => {
      [  result:titleValue ?title_value;
         result:titleLanguage ?title_language;
   result:subjectValue ?subject_value;
         result:subjectLangauge ?subject_language;
   result:descriptionValue ?description_value;
         result:descriptionLangauge ?description_language;
         result:langauge ?language;
         result:identifier ?identifier].
}.
Notes: See http://www.w3.org/2000/10/swap/test/query/t08.n3The above query can be run by using http://www.w3.org/2000/10/swap/doc/cwm.
2. Query example provided by Uche Ogbuji on 2002-06-23 expressed using the Versa language distribute(all(),
 'distribute(.-dc:title->*,
             ".-rdf:value->*",
             "(.-dc:language->*)-dcq:RFC1766->*",
             )',
 'distribute((.-dc:subject->*)-etbthes:ETBT->*,
             ".-rdf:value->*",
             "(.-dc:language->*)-dcq:RFC1766->*",
             )',
 'distribute(.-dc:description->*,
             ".-rdf:value->*",
             "(.-dc:language->*)-dcq:RFC1766->*",
              )',
 'distribute(.-dc:identifier->*,
             ".-rdf:value->*",
             "(.-dc:language->*)-dcq:RFC1766->*",
             )',
)
Notes: I'm not sure I really follow this case. My example is based on trying to follow the logic of the RDQL example.The above query can be run by using http://uche.ogbuji.net/tech/rdf/versa.
3. Query example provided by Arjohn Kampman on 2003-04-04 expressed using the SeRQL language SELECT
      title_value, title_language,
      subject_value,subject_language,
      description_value, description_language,
      language,
      identifier
FROM
      {x} <dc:title> {} <rdf:value> {title_value};
                        <dc:language> {} <dcq:RFC1766> {title_language},

      {x} <dc:subject> {} <etbthes:ETBT> {} <rdf:value> {subject_value};
                                            <dc:language> {} <dcq:RFC1766> {subject_language},

      {x} <dc:description> {} <rdf:value> {description_value};
                              <dc:language> {} <dcq:RFC1766> {description_language},

      {x} <dc:identifier> {identifier},

      {x} <dc:language> {} <dcq:RFC1766> {language}
USING NAMESPACE
     dc = <!http://purl.org/dc/elements/1.1/>,
     dcq = <!http://purl.org/dc/terms/>,
     dct = <!http://purl.org/dc/dcmitype/>,
     etb = <!http://eun.org/etb/elements/>,
     etbthes = <!http://eun.org/etb/thesaurus/elements/>
The above query can be run by using http://sourceforge.net/projects/sesame/.
4. Query example provided by Dan Pokorny, Ginger Alliance on 2002-07-2 expressed using the RDQ language SELECT
      ?title_value, ?title_language,
      ?subject_value,?subject_language,
      ?description_value, ?description_language,
      ?language,
      ?x.dc:identifier
FROM  ?x.dc:title{?tt}.rdf:value{?title_value},
      ?tt.dc:language.dcq:RFC1766{?title_language},
      ?x.dc:subject.etbthes:ETBT{?ss2}.rdf:value{?subject_value},
      ?ss2.dc:language.dcq:RFC1766{?subject_language},
      ?x.dc:description{?dd}.rdf:value{?description_value},
      ?dd.dc:language.dcq:RFC1766{?description_language},
      ?x.dc:language.dcq:RFC1766{?language}
USE
     rdf for <http://www.w3.org/1999/02/22-rdf-syntax-ns#>,
     dc for <http://purl.org/dc/elements/1.1/>,
     dcq for <http://purl.org/dc/terms/>,
     etbthes for <http://eun.org/etb/thesaurus/elements/>
The above query can be run by using http://www.gingerall.cz/charlie/ga/xml/p_rdf.xml.
5. Query example provided by Nick Bassiliades on 2002-11-13 expressed using the R-DEVICE language (deductiverule
  ?x <- (? (dc:title ?tt) (dc:description ?dd) 
           ((etbthes:ETBT dc:subject) ?ss2) 
           (dc:identifier ?identifier) 
           ((dcq:RFC1766 dc:language) ?language))
  ?tt <- (? (rdf:value ?t_val) 
            ((dcq:RFC1766 dc:language) ?t_lang))
  ?ss2 <- (? (rdf:value ?subject_val) 
             ((dcq:RFC1766 dc:language) ?s_lang))
  ?dd <- (? (rdf:value ?desc_val) 
            ((dcq:RFC1766 dc:language) ?desc_lang))
=>
  (result (title_value ?t_val) 
          (title_language ?t_lang) 
          (subj_val ?subject_val) 
          (subj_lang ?s_lang)
  (desc_value ?desc_val) 
          (desc_lang ?desc_lang) 
          (language ?language)
          (identifier ?identifier))
)
The above query can be run by using http://www.csd.auth.gr/~lpis/systems/r-device.html.
6. Query example provided by Alberto Reggiori on 2002-06-25 expressed using the RDQL language SELECT
      ?title_value, ?title_language,
      ?subject_value,?subject_language,
      ?description_value, ?description_language,
      ?language,
      ?identifier
FROM
    <http://braveheart.eun.org/xml/rdf/example10.xml>
WHERE
      ( ?x, <dc:title>, ?tt),
      ( ?tt, <rdf:value>, ?title_value),
      ( ?tt, <dc:language>, ?ttl),
      ( ?ttl, <dcq:RFC1766>, ?title_language),
      ( ?x, <dc:subject>, ?ss1),
      ( ?ss1, <etbthes:ETBT>, ?ss2),
      ( ?ss2, <rdf:value>, ?subject_value),
      ( ?ss2, <dc:language>, ?ss3),
      ( ?ss3, <dcq:RFC1766>, ?subject_language),
      ( ?x, <dc:description>, ?dd),
      ( ?dd, <rdf:value>, ?description_value),
      ( ?dd, <dc:language>, ?ddl),
      ( ?ddl, <dcq:RFC1766>, ?description_language),
      ( ?x, <dc:identifier>, ?identifier),
      ( ?x, <dc:language>, ?ll1),
      ( ?ll1, <dcq:RFC1766>, ?language)
USING
     rdf for <http://www.w3.org/1999/02/22-rdf-syntax-ns#>,
     rdfs for <http://www.w3.org/2000/01/rdf-schema#>,
     dc for <http://purl.org/dc/elements/1.1/>,
     dcq for <http://purl.org/dc/terms/>,
     dct for <http://purl.org/dc/dcmitype/>,
     etb for <http://eun.org/etb/elements/>,
     etbthes for <http://eun.org/etb/thesaurus/elements/>
The above query can be run by using http://rdfstore.sourceforge.net.

5: Find the URL of the latest published articles on XMLHack.com Web site which title contains the word 'RDQL'  

Find the URL of the latest published articles on XMLHack.com Web site which title contains the word 'RDQL'

See also: file:query-use-cases.rdf

Published by Alberto Reggiori on 2002-06-25

Examples [ Add new example ]

1. Query example provided by Tim Berners-Lee on 2003-03-02 expressed using the N3 language @prefix rss: <http://purl.org/rss/1.0/>.
@prefix log: <http://www.w3.org/2000/10/swap/log#>.
@prefix string: <http://www.w3.org/2000/10/swap/string#>.
@prefix : <#>.


this log:forAll :t, :l.

{
    <http://xmlhack.com/rss10.php>.log:semantics log:includes {
        [] a rss:item; rss:title :t; rss:link :l.
  :t string:containsIgnoringCase "XML". }
} => {
     [] :title :t; :link :l
}.
Notes: See http://www.w3.org/2000/10/swap/test/query/t07.n3The above query can be run by using http://www.w3.org/2000/10/swap/doc/cwm.
2. Query example provided by Uche Ogbuji on 2002-06-23 expressed using the Versa language (type(rss:item) |-  rss:title -> contains('RDQL')) -> rss:link Notes: Again it's up to the environment to provide the RDF model and namespace mappings. But how are we measuring "latest" here? Just the stuff int he current RSS feed?The above query can be run by using http://uche.ogbuji.net/tech/rdf/versa. 3. Query example provided by Arjohn Kampman on 2003-04-04 expressed using the SeRQL language SELECT link
FROM
     {item} <rdf:type>  {<rss:item>};
            <rss:title> {title};
            <rss:link>  {link}
WHERE
    title like "*RDQL*"
USING NAMESPACE
    rss = <!http://purl.org/rss/1.0/>
Notes: SeRQL does not have a mechanism to specify a datasource in a query itself, instead, the query engine's context determines which data the query should be evaluated against.The above query can be run by using http://sourceforge.net/projects/sesame/.
4. Query example provided by Nick Bassiliades on 2002-11-13 expressed using the R-DEVICE language (deductiverule 
  (rss:item (rss:title ?title) (rss:link ?link))
  (test (str-index "RDQL" ?title))
=>
  (result (link ?link))
)
The above query can be run by using http://www.csd.auth.gr/~lpis/systems/r-device.html.
5. Query example provided by Alberto Reggiori on 2002-06-25 expressed using the RDQL/RDFStore language SELECT ?link
FROM <http://xmlhack.com/rss10.php>
WHERE
      (?item, <rdf:type>, <rss:item>),
      (?item, <rss::title>, ?title),
      (?item, <rss::link>, ?link)
AND ?title LIKE '/RDql/i'
USING
     rdf for <http://www.w3.org/1999/02/22-rdf-syntax-ns#>,
     rss for <http://purl.org/rss/1.0/>
Notes: Same as the previous example but less efficient requiring to read the whole results in memory and
then prune them; the first example instead will do the free-text triple selection while the actual
triple-patterns are processed (i.e. in the storage self)
The above query can be run by using http://rdfstore.sourceforge.net.
6. Query example provided by Alberto Reggiori on 2002-06-25 expressed using the RDQL/RDFStore language SELECT ?link
FROM <http://xmlhack.com/rss10.php>
WHERE
     (?item, <rdf:type>, <rss:item>),
     (?item, <rss::title>, %"RDQL"%),
     (?item, <rss::link>, ?link)
USING
     rdf for <http://www.w3.org/1999/02/22-rdf-syntax-ns#>,
     rss for <http://purl.org/rss/1.0/>
Notes: This query is leveraring on RDFStore free-text extensions to RDQL/SquishQLThe above query can be run by using http://rdfstore.sourceforge.net.

6: Find the title and URL of the latest published articles on XMLHack.com Web site  

Find the title and link (URL) of the latest published articles on XMLHack.com Web site published as RSS1.0

See also: file:query-use-cases.rdf

Published by Alberto Reggiori on 2002-06-25

Examples [ Add new example ]

1. Query example provided by Tim Berners-Lee on 2003-03-02 expressed using the N3 language @prefix rss: <http://purl.org/rss/1.0/>.
@prefix log: <http://www.w3.org/2000/10/swap/log#>.
@prefix : <#>.


this log:forAll :t, :l.

{
    <http://xmlhack.com/rss10.php>.log:semantics log:includes {
        [] a rss:item; rss:title :t; rss:link :l }
} => {
     [] :title :t; :link :l
}.
Notes: See http://www.w3.org/2000/10/swap/test/query/t06.n3The above query can be run by using http://www.w3.org/2000/10/swap/doc/cwm.
2. Query example provided by Uche Ogbuji on 2002-06-25 expressed using the Versa language distribute(type(rss:item),
           '. - rss:title -> *',
           '. - rss:link -> *')
Notes: Cool. An example whose RDF model I can divine. However, Versa does not define the method of setting the model. I really think that all these I/O matters cloud and reduce flexibility in a query language. Versa learns from the very successful XPath in its focus on the query, and not the environment.
In the 4Suite impl, I can do the following from the command line:
4versa -r http://xmlhack.com/rss10.php "distribute(type(rss:item),'. - rss:title -> *','. - rss:link -> *')"
The above query can be run by using http://uche.ogbuji.net/tech/rdf/versa.
3. Query example provided by Jeen Broekstra on 2003-04-04 expressed using the SeRQL language select title, link
from {item} <rdf:type> {<rss:item>};
            <rss:title> {title};
            <rss:link> {link}
using namespace
     rss = <!http://purl.org/rss/1.0/>
The above query can be run by using http://sourceforge.net/projects/sesame/.
4. Query example provided by Dan Pokorny, Ginger Alliance on 2002-07-2 expressed using the RDQ language SELECT ?title, ?link
FROM rss:item::?item.rss:title,
     ?item.rss:link{?link}
USE
     rss for [http://purl.org/rss/1.0/]
Notes: RDQ doesn't specify the data modelThe above query can be run by using http://www.gingerall.cz/charlie/ga/xml/p_rdf.xml.
5. Query example provided by Nick Bassiliades on 2002-11-13 expressed using the R-DEVICE language (deductiverule
  (rss:item (rss:title ?title) (rss:link ?link))
=>
  (result (title ?title) (link ?link))
)
The above query can be run by using http://www.csd.auth.gr/~lpis/systems/r-device.html.
6. Query example provided by Alberto Reggiori on 2002-06-25 expressed using the RDQL language SELECT ?title, ?link
FROM <http://xmlhack.com/rss10.php>
WHERE
     (?item, <rdf:type>, <rss:item>),
     (?item, <rss::title>, ?title),
     (?item, <rss::link>, ?link)
USING
     rdf for <http://www.w3.org/1999/02/22-rdf-syntax-ns#>,
     rss for <http://purl.org/rss/1.0/>
The above query can be run by using http://rdfstore.sourceforge.net.

7: Extract information from RDF for report generation  

Given an RDF database of various information, extract selected parts for generating (say) an HTML document from the content. The result of the query is a collection of variable bindings that are passed to a report formatter. This approach has been used in practice for the generation of Internet protocol registry documents.

See also: file:query-use-cases.rdf

Published by Graham Klyne on 2002-06-25

Examples [ Add new example ]

1. Query example provided by Tim Berners-Lee on 2003-03-02 expressed using the N3 language @prefix con: <http://www.w3.org/2000/10/swap/pim/contact#>.
@prefix string: <http://www.w3.org/2000/10/swap/string#>.
@prefix log: <http://www.w3.org/2000/10/swap/log#>.
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . 
@prefix data: <#>.
@prefix : <#>.

{  [] :Given ?g; :Family ?f; :favoriteSport ?s.
?s :label ?l.
("<tr><td>" ?g "</td><td>" ?f "</td><td>" ?l "\n" )
string:concatenation ?r } => { ?l log:outputString ?r }.

"000" log:outputString """<html><body>
<h1>Ordered by sport</h1>
<table>
""".

"ZZZ" log:outputString "</table></body></html>\n".

# test data:

:soccer :label "Soccer".
:tennis :label "Tennis".

[] :Given "Andrew";     :Family "Other";    :favoriteSport :soccer.
[] :Given "Jane";       :Family "Doe";      :favoriteSport :tennis.
[] :Given "Jane";       :Family "Smith";    :favoriteSport :soccer.
[] :Given "John";       :Family "Smith";    :favoriteSport :tennis.
[] :Given "Marmaduke";  :Family "Smith";    :favoriteSport :soccer.
[] :Given "Smith";      :Family "Robinson"; :favoriteSport :soccer.
Notes: See http://www.w3.org/2000/10/swap/test/query/t05.n3The above query can be run by using http://www.w3.org/2000/10/swap/doc/cwm.
2. Query example provided by Uche Ogbuji on 2002-06-23 expressed using the Versa language distribute(type(hdr:HeaderField),
           '. - hdr:fieldName -> *',
           '. - rdfs:label -> *',
           'distribute(. - hdr:protocol -> *,
                       ". - hdr:protocolName -> *",
                       ". - hdr:specification -> *",
                       ". - hdr:document -> *")
           )
Notes: I really need a decent explanation of this use case in order to have a chance of submitting anything supposedly equivalent to the other examples given. The description isn't much use. If I understand correctly, one of the keys here is host variable binding. Versa doesn't mandate output: that's left up to the host environment. This example merely renders the desired values.The above query can be run by using http://uche.ogbuji.net/tech/rdf/versa.
3. Query example provided by Arjohn Kampman on 2003-04-04 expressed using the SeRQL language SELECT *
FROM
   {Header} <rdf:type>      {HeaderField};
            <hdr:fieldName> {Name};
            <rdfs:label>    {Purpose};
            <hdr:protocol>  {P} <hdr:protocolName>  {Pname};
                                <hdr:specification> {Ps} <hdr:document> {Psdocument}
USING NAMESPACE
    hdr = <!foo://bar/>
The above query can be run by using http://sourceforge.net/projects/sesame/.
4. Query example provided by Dan Pokorny, Ginger Alliance on 2002-07-2 expressed using the RDQ language
SELECT 
  ?header,  
  ?header.hdr:fieldName,
  ?header.rdfs:label,
  ?p,
  ?p.hdr:protocolName,
  ?ps,
  ?ps.hdr:document
FROM hdr:HeaderField::?header.hdr:protocol{?p}.hdr:specification{?ps}}
The above query can be run by using http://www.gingerall.cz/charlie/ga/xml/p_rdf.xml.
5. Query example provided by Nick Bassiliades on 2002-11-13 expressed using the R-DEVICE language (deductiverule 
  ?Header <- (hdr:HeaderField (hdr:fieldName ?name) 
                              (rdfs:label ?purpose)
                              (hdr:protocol ?p))
   ?p <- (? (hdr:protocolName ?pn) (hdr:spec ?ps))
   ?ps <- (? (hdr:document ?psdocument))
=>
   (result (header ?Header) (name ?name) 
           (protocol ?p) (purpose ?purpose) 
           (pname ?pn) (spec ?ps) 
           (document ?psdocument))
)
The above query can be run by using http://www.csd.auth.gr/~lpis/systems/r-device.html.
6. Query example provided by Graham Klyne on 2002-06-25 expressed using the N3/RDF language hrep:HdrProtoPattern :-
  ( [ rep:var "header" ]
    [ rep:and
      ( [ rep:uri rdf:type ] [ rep:uri hdr:HeaderField ] ),
      ( [ rep:uri hdr:fieldName ] [ rep:var "name" ] ),
      ( [ rep:uri rdfs:label ] [ rep:var "purpose" ] ),
      ( [ rep:uri hdr:protocol ] [ rep:var "p" ]
        [ rep:and
          ( [ rep:uri hdr:protocolName] [ rep:var "pname" ] ),
          ( [ rep:uri hdr:specification] [ rep:var "ps" ]
            [ rep:uri hdr:document ] [ rep:var "psdocument" ] )
      ] )
   ] ) .
The above query can be run by using http://www.ninebynine.org/RDFNotes/RDFForLittleLanguages.htm.
7. Query example provided by Graham Klyne on 2002-06-25 expressed using the Custom language ( ?Header
  ( rdf:type hdr:HeaderField &
    hdr:fieldName ?name &
    rdfs:label ?purpose &
    hdr:protocol ?p
    ( hdr:protocolName ?pname &
      hdr:specification ?ps hdr:document ?psdocument ) ) )
The above query can be run by using http://www.ninebynine.org/RDFNotes/RDFForLittleLanguages.htm.

8: Find some values and the assoicated schema information  

For a known resource, find the values of properties which have range information in the schema.

Notes: If no range information from the schema is available, this query fails to match a property of resource .

See also: file:query-use-cases.rdf

Published by Andy Seaborne on 2002-06-25

Examples [ Add new example ]

1. Query example provided by Tim Berners-Lee on 2003-03-02 expressed using the N3 language # @@ would be nice to have this just use --mode=rsme --think
# to pick up hte schema data automatically
#
@prefix con: <http://www.w3.org/2000/10/swap/pim/contact#>.
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . 
@prefix data: <#>.
@prefix : <#>.

{data:x ?p ?v. ?p rdfs:range ?c} => {[] :prop ?p; :range ?c; :val ?v }.

# test data:

data:x  con:office [
con:address [ con:street "Lombard Street" ]];
  con:home [
con:address [ con:street "Islington Gardens"]].

# test metadata:  (a subset of the schema)

con:office rdfs:range con:Location.
con:home rdfs:range con:Location.
con:address rdfs:range con:Address.
Notes: See http://www.w3.org/2000/10/swap/test/query/t04.n3The above query can be run by using http://www.w3.org/2000/10/swap/doc/cwm.
2. Query example provided by Uche Ogbuji on 2002-06-23 expressed using the Versa language data:x - (all() |- rdfs:range -> *) -> * The above query can be run by using http://uche.ogbuji.net/tech/rdf/versa. 3. Query example provided by Geoff Chappell / Intellidimension on 2002-06-25 expressed using the RDFQL language session.namespaces["vcard"] = "http://www.w3.org/2001/vcard-rdf/3.0#";
session.namespaces["data"] = "file://test/";
session.namespaces["rdfs"] = "http://www.w3.org/2000/01/rdf-schema#";

select ?property, ?value, ?type using somedata where
{?property [data:x] ?value} and {[rdfs:range] ?property ?type}
The above query can be run by using http://www.intellidimension.com/RDFGateway/beta3/.
4. Query example provided by Jeen Broekstra on 2003-04-04 expressed using the SeRQL language select prop, val, type
from {<data:x>} prop {val}, 
     {prop} <rdfs:range> {type}
using namespace
    data = <!file://test/>
The above query can be run by using http://sourceforge.net/projects/sesame/.
5. Query example provided by Dan Pokorny, Ginger Alliance on 2002-07-2 expressed using the RDQ language SELECT ?property, ?value, ?type
FROM
  ?x.?property{?value},
  ?property.rdfs:range{?type}
USE 
  rdfs  FOR [http://www.w3.org/2000/01/rdf-schema#]
The above query can be run by using http://www.gingerall.cz/charlie/ga/xml/p_rdf.xml.
6. Query example provided by Nick Bassiliades on 2002-11-13 expressed using the R-DEVICE language (deductiverule 
 data:x <- (? (?property ?value))
 ?property <- (rdf:Property (rdfs:range $? ?t $?))
=>
 (result (property ?property) (value ?value)
         (type ?t))
)
The above query can be run by using http://www.csd.auth.gr/~lpis/systems/r-device.html.
7. Query example provided by Andy Seaborne on 2002-06-25 expressed using the RDQL language SELECT ?property, ?value, ?type
WHERE
  (<data:x>, ?property, ?value) ,
  (?property, <rdfs:range>, ?type)
USING 
  vcard FOR <http://www.w3.org/2001/vcard-rdf/3.0#>
  rdfs  FOR <http://www.w3.org/2000/01/rdf-schema#>
  rdf   FOR <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
  data  FOR <file://test/>
The above query can be run by using http://www.hpl.hp.com/semweb/.

9: Find some value in a data structure  

Find the a data value within a larger structure of RDF. For example: find the given name, where we know the family name.

Notes: This depends on the regularity of the data

See also: file:query-use-cases.rdf

Published by Andy Seaborne on 2002-06-25

Examples [ Add new example ]

1. Query example provided by Tim Berners-Lee on 2003-03-02 expressed using the N3 language @prefix this: <#>.
@prefix con: <http://www.w3.org/2000/10/swap/pim/contact#>.
@prefix vcard: <http://www.w3.org/2001/vcard-rdf/3.0#>.
@prefix : <http://www.w3.org/2001/vcard-rdf/3.0#>.

# @@ Test case is not schema-valid - see vcard schema.

{[] :Family "Smith"; :Given ?g } => { ?g a this:SmithFamilyMember }.

# test data:

[] :Given "Andrew";  :Family "Other".
[] :Given "Jane";  :Family "Doe".
[] :Given "Jane";  :Family "Smith".
[] :Given "John";  :Family "Smith".
[] :Given "Marmaduke";  :Family "Smith".
[] :Given "Smith";  :Family "Robinson".
Notes: See http://www.w3.org/2000/10/swap/test/query/t03.n3The above query can be run by using http://www.w3.org/2000/10/swap/doc/cwm.
2. Query example provided by Uche Ogbuji on 2002-06-23 expressed using the Versa language ("Smith" <- vcard:Family - *) - vcard:Given -> * Notes: Can also write (all() |- vcard:Family -> "Smith") - vcard:Given -> *The above query can be run by using http://uche.ogbuji.net/tech/rdf/versa. 3. Query example provided by Geoff Chappell / Intellidimension on 2002-06-23 expressed using the RDFQL language session.namespaces["vcard"] = "http://www.w3.org/2001/vcard-rdf/3.0#";

select ?v using somedata where {[vcard:N] ?x ?y} 
and {[vcard:Family] ?y 'Smith'} and {[vcard:Given] ?y ?v}
The above query can be run by using http://www.intellidimension.com/RDFGateway/beta3/.
4. Query example provided by Arjohn Kampman on 2003-04-04 expressed using the SeRQL language SELECT v
FROM
  {x} <vcard:N> {y} <vcard:Family> {"Smith"};
                    <vcard:Given> {v}
USING NAMESPACE
  vcard = <!http://www.w3.org/2001/vcard-rdf/3.0#>
Notes: The unused variables 'x' and 'y' can optionally be removed from the query, e.g.:
{} <vcard:N> {} <vcard:Family> {"Smith"};
<vcard:Given> {v}
The above query can be run by using http://sourceforge.net/projects/sesame/.
5. Query example provided by Arjohn Kampman on 2002-07-3 expressed using the RQL language SELECT v
FROM
  {x} vcard:N {y}. vcard:Family {fam}
  {y} vcard:Given {v}
WHERE
  fam = "Smith"
USING NAMESPACE
  vcard = http://www.w3.org/2001/vcard-rdf/3.0#
The above query can be run by using http://sourceforge.net/projects/sesame/.
6. Query example provided by Dan Pokorny, Ginger Alliance on 2002-07-2 expressed using the RDQ language SELECT ?v
FROM
  ?x.vcard:N{?y}.vcard:Family=>'Smith' ,
  ?y.vcard:Given{?v}
USE
  vcard FOR [http://www.w3.org/2001/vcard-rdf/3.0#]
The above query can be run by using http://www.gingerall.cz/charlie/ga/xml/p_rdf.xml.
7. Query example provided by Nick Bassiliades on 2002-11-13 expressed using the R-DEVICE language (deductiverule 
  ?x <- (? (vcard:N ?y))
  ?y <- (? (vcard:Family "Smith") (vcard:Given ?v))
=>
  (person (name ?v))
)
The above query can be run by using http://www.csd.auth.gr/~lpis/systems/r-device.html.
8. Query example provided by Andy Seaborne on 2002-06-25 expressed using the RDQL language SELECT ?v
WHERE
  (?x, <vcard:N>, ?y) ,
  (?y, <vcard:Family>, "Smith") ,
  (?y, <vcard:Given>, ?v)
USING 
  vcard FOR <http://www.w3.org/2001/vcard-rdf/3.0#>
The above query can be run by using http://www.hpl.hp.com/semweb/.

10: Find email message give message id  

Find an email messages, given some information about the message where the data records the message headers (RFC2822).

See also: file:query-use-cases.rdf

Published by Andy Seaborne on 2002-06-25

Examples [ Add new example ]

1. Query example provided by Tim Berners-Lee on 2003-03-02 expressed using the N3 language @prefix email: <http://www.hpl.hp.com/email/email#>.

{ ?x email:message-id "123456@example.com" }
 =>
{ ?x email:message-id "123456@example.com" }.


# test data


@prefix : <#>.

:m1235 email:message-id "814358768@example.com";
email:from "whoever@example.com".

:m1236 email:message-id "814358432168@example.com";
email:from "whoever@example.com".

:m12314 email:message-id "123456@example.com";
email:from "whoeverelse@example.com".
Notes: See http://www.w3.org/2000/10/swap/test/query/t02.n3The above query can be run by using http://www.w3.org/2000/10/swap/doc/cwm.
2. Query example provided by Uche Ogbuji on 2002-06-23 expressed using the Versa language all() |- email:message-id -> eq('123456@example.com') Notes: Versa, like XPath, does not define the method of namespace prefix to URI mapping. For instance, when Versa is embedded in XSLT, it uses the namespaces declared on the XSLT extension instruction.The above query can be run by using http://uche.ogbuji.net/tech/rdf/versa. 3. Query example provided by Jeen Broekstra on 2003-04-04 expressed using the SeRQL language select  x
from   {x} <email:message-id> {"123456@example.com"}
using namespace
      email = <!http://www.hpl.hp.com/email/email#>
The above query can be run by using http://sourceforge.net/projects/sesame.
4. Query example provided by Arjohn Kampman on 2002-07-3 expressed using the RQL language SELECT x
FROM  {x} email:message-id {id}
WHERE id = "123456@example.com"
USING NAMESPACE
      email = http://www.hpl.hp.com/email/email#
The above query can be run by using http://sourceforge.net/projects/sesame/.
5. Query example provided by Dan Pokorny, Ginger Alliance on 2002-07-2 expressed using the RDQ language SELECT ?x
FROM ?x.email:message_id=>'123456@example.com'
USE email FOR [http://www.hpl.hp.com/email/email#]
Notes: Note: It's still an open issue how to use dash in property names in RDQ. As a workaround we use full uri here:
SELECT ?x
FROM ?x.[http://www.hpl.hp.com/email/email#message-id]=>'123456@example.com'
The above query can be run by using http://www.gingerall.cz/charlie/ga/xml/p_rdf.xml.
6. Query example provided by Geoff Chappell / Intellidimension on 2002-06-23 expressed using the RDFQL language session.namespaces["pop3"] = "http://www.intellidimension.com/namespaces/pop3#";
session.namespaces["rdf"] = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
session.namespaces["rdfs"] = "http://www.w3.org/2000/01/rdf-schema#";


var ds = new DataSource("pop3?server=mail.somewhere.net&user=someuser&pass=xxxx&action=list");

select ?msg ?from using #ds where {[rdf:type] ?msg [pop3:Message]} and
{[pop3:property] ?msg ?prop} and {[rdfs:label] ?prop 'From'} and 
{[rdf:value] ?prop ?from} and regexp(?from, 'hotmail')<>''
Notes: Query uses rdf gateway pop3 dataservice. Docs at:
http://www.intellidimension.com/RDFGateway/Docs/dsguide.asp
The above query can be run by using http://www.intellidimension.com/RDFGateway/beta3/.
7. Query example provided by Nick Bassiliades on 2002-11-13 expressed using the R-DEVICE language (deductiverule 
  ?x <- (? (email:message-id '123456@example.com'))
=>
  (result (email ?x))
)
The above query can be run by using http://www.csd.auth.gr/~lpis/systems/r-device.html.
8. Query example provided by Andy Seaborne on 2002-06-23 expressed using the RDQL language SELECT ?x
WHERE (?x, <email:message-id>, '123456@example.com')
USING email FOR <http://www.hpl.hp.com/email/email#>
The above query can be run by using http://www.hpl.hp.com/semweb/.

11: RDF properties retrieval using provenance information (context/scope/formulae)  

RDF sources once parsed and stored into an RDF database are flatten down and at the query time you very often need to filter them based on the "context" where they have been asserted - i.e. source URL or some other RDF resource which could be further described.

Notes: The concept of statement "context" (scope/provenance) is out of the RDF model and has not been considered yet for inclusion into the RDF specifications. Some RDF toolkits out there allow to SELECT triples using one more dimension/component (s,p,o + c) - it is not clear at all to me where this "extension" is going to fit into the RDF framework (i.e. reification and higher-oder statements) but it is definitively needed as soon as you start writing real-world applications.

See also: http://www.ninebynine.org/RDFNotes/UsingContextsWithRDF.html

Published by Alberto Reggiori on 2003-04-20

Examples [ Add new example ]

1. Query example provided by Alberto Reggiori on 2003-11-14 expressed using the RDQL language SELECT
?x, ?title, ?date, ?description, ?section, ?acquired, ?source, ?ctx
FROM
<rdfstore://nb@demo.asemantics.com:1234>
WHERE
(?ctx, <dc:date>, "2003-11-14"@it),
(?ctx, <rdf:type>, <rdfstore:Context>),
(?x, <lmn:section>, %"international | national | gossip"%, ?ctx),
(?x, <rdf:type>, <rss:item>, ?ctx),
(?x, <rss:title>, ?title, ?ctx),
(?x, <dc:date>, ?date, ?ctx),
(?x, <rss:description>, ?description, ?ctx),
(?x, <lmn:acquired>, ?acquired, ?ctx),
(?x, <lmn:section>, ?section, ?ctx),
(?items, ?ii, ?x, ?ctx),
(?items, <rdf:type>, <rdf:Seq>, ?ctx),
(?s, <rss:items>, ?items, ?ctx),
(?s, <rdf:type>, <rss:channel>, ?ctx),
(?s, <rss:title>, ?source, ?ctx)
USING
rss FOR <http://purl.org/rss/1.0/>,
lmn FOR <http://www.asemantics.com/schemas/lastminutenews/>,
dc FOR <http://purl.org/dc/elements/1.1/>,
dctypes FOR <http://purl.org/dc/dcmitype/>,
h FOR <http://www.w3.org/1999/xhtml>,
rdf FOR <http://www.w3.org/1999/02/22-rdf-syntax-ns#>, rdfstore FOR <http://rdfstore.sourceforge.net/contexts/>
Notes: This is a real-world example taken from the NewsBlender http://demo.asemantics.com/biz/lmn/nb/ - see also other "insane" RDQL queries http://demo.asemantics.com/rdfstore/www2003/The above query can be run by using http://rdfstore.sourceforge.net.

12: An optional RDF property retrieval  

As soon as you start writing real-world RDF applications you need "partial matches", otherwise you have to go back to API and "build the query by hand"; because RDF data nature is generally irregular, incomplete, perhaps expressed using different data granularity, deeply nested. Show an optional property retrieval support in RDF query languages - see here for an RDF/XUL related example including some sample RDF/XML data.

Notes: One generalization is for queries to be in three parts: locate, extract and present. Locate is all exact matches of the (conjunctive) query graph pattern (c.f. QL98) and produces a number of solutions, where each solution is a set of variable bindings. Extract is zero or more optional patterns, each of which is tried for each exact match and can extend each variable binding set with new variables (need not do so for all solutions). Present deals with the form of the output. This may be the variables actually required, like in a SELECT clause, or it may be an RDF template where a graph has variables in it. The values of the variables are substituted to form a subgraphs for each solution. Example: In a system like cwm, the left-hand side of log:implies is the locate part, the right-hand side is the present part. There is no extract (optional bindings). Similarly in RDQL and Inkiling, the locate part is the WHERE clause, the present part is the SELECT clause (not RDF) and there is no extract part. DQL does have this optionality through the 'may bind' variables. Issue: this implicit model of query execution may be limited in tha optional variable bindings in the extract part do not take part in the locate process. What use cases does this miss? Is it compatible with a path-like view of query? What use cases does this miss? Is it compatible with a path-like view of query?

See also: http://esw.w3.org/topic/RDFQueryTestcasesRequirements

Published by Alberto Reggiori on 2003-04-20

Examples [ Add new example ]

1. Query example provided by Arjohn Kampman on 2003-10-28 expressed using the SeRQL language select
  NAME, STREET
from
  {} <nc:friends> {FRIENDS} <rdfs:member> {FRIEND},
  {FRIEND} <nc:name> {NAME};
          [<nc:address> {} <nc:street> {STREET}]
using namespace
   nc = <!http://home.netscape.com/NC-rdf#>
Notes: SeRQL supports optional path expressions which can be mixed with non-optional path expressions by surrounding them with square brackets. Optional path expressions can even be nested, which is required when several optional path expressions depend on another optional path expressions. More information about and examples for SeRQL's optional path expressions can be found at http://sesame.aidministrator.nl/publications/SeRQLmanual.htmlThe above query can be run by using http://sourceforge.net/projects/sesame/.

13: Authors of a paper with emails   

An example based on "A Comparison of RDF Query Languages" by Peter Haase et al, http://www.aifb.uni-karlsruhe.de/WBS/pha/rdf-query. some-paper is related by fact#:title to some-title that-paper is related by fact#:author to some-description that-description is related by some-rdf-node to some-home-page that-home-page is related by fact#:name to some-name that-home-page is related by fact#:email to some-email -------------------------------------------------------------- that-name is an author , with email that-email , of that-title

Notes: Notes: To run the query, and others, and to modify the example, please log in to the "demo" ID of the Internet Business Logic system at www.reengineeringllc.com . Pick RDFQueryLangComparison1, and view/change or run it using a browser.

See also: file:/www.reengineeringllc.com

Published by Adrian Walker on 2004-06-16

Examples [ Add new example ]


14: Schools Chemical Order Processing system  

new system must be quick, efficient service. ABle to ship orders. Able to order/query an order. same service to telesales. Able to track the order, check their status online, able to query their order, customer allowed to cancel their order. Notify the shipping agent of order being sent off. Re-ordering of chemicals must be triggered.

See also: file:query-use-cases.rdf

Published by The Chemical Component Company (CCC) on 2003-11-19

Examples [ Add new example ]


15: create roles  

assign roles

See also: file:query-use-cases.rdf

Published by rishi on 2004-02-18

Examples [ Add new example ]


16: Find the language specific value of a property  

Retrieve the value of a property for a particular language (as specified by xml:lang). Specifically, retrieve the english description of each class specified in http://www.w3.org/2000/01/rdf-schema#

See also: file:query-use-cases.rdf

Published by Geoff Chappell on 2002-06-25

Examples [ Add new example ]

1. Query example provided by Jeen Broekstra on 2003-04-04 expressed using the SeRQL language select 
    class, descr
from   
    {class} <rdf:type> {<rdfs:Class>}; 
            <rdfs:label> {descr}
where 
    lang(descr) = "en"
Notes: Not 100% sure if this was the intention of the example. This query retrieves for each class the corresponding english description.

The SeRQL language does not explicitly specify the source model.
The above query can be run by using http://sourceforge.net/projects/sesame.

17: Create Order  

i dont know

Notes: i dont know

See also: file:query-use-cases.rdf

Published by Sami Sharaiha on 2002-09-12

Examples [ Add new example ]


18: phone directoy  

Connection of phones

See also: file:query-use-cases.rdf

Published by stevens on 2003-09-17

Examples [ Add new example ]


19: Query an ordered container or list  

I have fiound it useful to be able to use a query expression to "traverse" (or recall) the elements of an RDF container or a daml:collection style of list; e.g. Container ?member . or List ?element .

Notes: This use-case arose from wanting to process a history of events relating to a document editing process (see: http://www.ninebynine.org/wip/DocIssues/RDFConceptIssues.n3, http://www.ninebynine.org/wip/DocIssues/RDFConceptIssues.html). Container and list queries for the above data have been implemented in my "RDF for little languages" report generator (see http://www.ninebynine.org/Software/Intro.html) The query itself is encoded in Notation3 in the source code file N3GenDocIssues.py.

See also: file:query-use-cases.rdf

Published by Graham Klyne on 2002-09-23

Examples [ Add new example ]


20: Query on Date Range  

Given a date "searchDate" (formatted as YYYY-MM-DD), query against a model which contains entities with a dc:date Property stored in XMLSchema dateTime format, find all entities (let's say all Individuals/Resources) created BEFORE "searchDate".

See also: file:query-use-cases.rdf

Published by Josh Daigle on 2004-05-26

Examples [ Add new example ]


21: queue management for the bank perspective  

there will be three main part admin who has the authority to monitor the tellers and can have the authority to set up the ip configuration the tellers can log on and log out and can press the next button and that updates the queue status. the third one is the customers who receive the token and give the ourouse input.

See also: file:query-use-cases.rdf

Published by shormi on 2004-09-04

Examples [ Add new example ]


22: Thermostat  

The system must be able to handle all common central heating and central air conditioning systems.

See also: file:query-use-cases.rdf

Published by school on 2003-02-12

Examples [ Add new example ]

1. Query example provided by Tim Berners-Lee on 2003-02-27 expressed using the N3 language @prefix therm: <http://www.example.com/thermal#>.
@prefix math: <http://www.w3.org/2000/10/swap/math#>.
@prefix : <myHouse#>.
@prefix my: <myHouse#>.


{ ?thermostat therm:temp ?t; therm:setting ?s .
  ?s  math:greaterThan ?t .
} => {
  ?thermostat a therm:CallingForHeat .
}.

{ [] a therm:CallingForHeat } => { :boiler therm:control "ON" }.

# test data:

:livingRoom  therm:temp  "22"; therm:setting "21".

:bedroom     therm:temp  "14"; therm:setting "18".

:hall        therm:temp  "22"; therm:setting "21".
Notes: See http://www.w3.org/2000/10/swap/test/query/t01.n3
original file with more comments
The above query can be run by using http://www.w3.org/2000/10/swap/doc/cwm.

23: Video Rental  

The system will be able to register all video rented and keep a record of all movements

See also: http://www.yahoo.com

Published by Emiliano Hernandez on 2003-07-30

Examples [ Add new example ]


24: XPath/XQuery query over an RDF graph  

Query an exisitng XML docuemnt or RDF/XML (or online source/daatabase/rdf-storage or whatever) using some XPath/XQuery (like/friendly) syntax. Better if the source RDF/XML or XML document comes from some real world dataset which people can easily pick up.

Notes: XPath (and XQuery) query is user-friendly and most developers (webmasters) like/use it every day - it is important that any RDF/XML query language be XML "friendly" in that sense

See also: http://rdfweb.org/people/damian/treehugger/

Published by Alberto Reggiori on 2003-11-14

Examples [ Add new example ]


25: linkfail  

link fails and the system reroutes traffic to the backup

See also: file:query-use-cases.rdf

Published by cm on 2004-02-17

Examples [ Add new example ]


Notes

This document was automatically generated from the RDF for the use cases.

To submit new use cases or change existing ones, please email Alberto Reggiori or Andy Seaborne.