- From: Simon Schenk <sschenk@uni-koblenz.de>
- Date: Tue, 25 Aug 2009 13:26:02 +0000
- To: Lee Feigenbaum <lee@thefigtrees.net>
- Cc: "Wood, Jamey" <Jamey.Wood@nrel.gov>, "public-sparql-dev@w3.org" <public-sparql-dev@w3.org>
- Message-Id: <1251206762.3694.154.camel@tweety>
This is not beautiful, but should work: PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> PREFIX ex: <http://example.org/vocabulary#> PREFIX : <http://example.org/exampleDocument#> SELECT ?person $age WHERE { GRAPH ?g1 { ?person rdf:type ex:LivingPerson . } GRAPH ?g2 { ?person ex:age ?age . } ?g1 ex:startDate ?ctx_startDate1 . ?g1 ex:endDate ?ctx_endDate1 . FILTER (("1840-04-01T00:00:00Z"^^xsd:dateTime >= xsd:dateTime(?ctx_startDate1)) && ("1840-04-01T00:00:00Z"^^xsd:dateTime <= xsd:dateTime(?ctx_endDate1))) ?g2 ex:startDate ?ctx_startDate2 . ?g2 ex:endDate ?ctx_endDate2 . FILTER (("1840-04-01T00:00:00Z"^^xsd:dateTime >= xsd:dateTime(?ctx_startDate2)) && ("1840-04-01T00:00:00Z"^^xsd:dateTime <= xsd:dateTime(?ctx_endDate2))) } Of cause, for longer queries it becomes a bit nasty. Cheers, Simon Am Dienstag, den 25.08.2009, 09:12 -0400 schrieb Lee Feigenbaum: > Hi Jamey, > > I don't think there's any way to do what you're looking for in SPARQL. > > In your particular example, you could query with the full contents of > the store merged as the query's default graph, but I realize that > doesn't work in the general case. > > Sorry I don't have a more helpful answer here! > > Lee > > Wood, Jamey wrote: > > I’m trying to find a good way to contextualize RDF statements (so that > > statements could be bound to a certain time period, licensing terms, etc). > > Named graphs seem to handle this pretty well. But I can’t find a good way > > to query across all named graphs which match some criteria. > > > > I’ll try to illustrate the issue I’m facing via an example. Suppose we have > > the following graphs: > > > > @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . > > @prefix xsd: <http://www.w3.org/2001/XMLSchema#> > > @prefix ex: <http://example.org/vocabulary#> . > > @prefix : <http://example.org/exampleDocument#> > > > > # default graph > > { > > <urn:g1> ex:startDate "1809-02-12T00:00:00Z"^^xsd:dateTime . > > <urn:g1> ex:endDate "1865-04-15T00:00:00Z"^^xsd:dateTime . > > <urn:g2> ex:startDate "1839-02-12T00:00:00Z"^^xsd:dateTime . > > <urn:g2> ex:endDate "1840-02-12T00:00:00Z"^^xsd:dateTime . > > <urn:g3> ex:startDate "1840-02-12T00:00:00Z"^^xsd:dateTime . > > <urn:g3> ex:endDate "1841-02-12T00:00:00Z"^^xsd:dateTime . > > } > > > > <urn:g1> { > > :Abraham_Lincoln rdf:type ex:LivingPerson . > > } > > > > <urn:g2> { > > :Abraham_Lincoln ex:age "30"^^http://www.w3.org/2001/XMLSchema#integer .. > > } > > > > <urn:g3> { > > :Abraham_Lincoln ex:age "31"^^http://www.w3.org/2001/XMLSchema#integer .. > > } > > > > (So the default graph just contains “context information” and the “real” data is in the named graphs.) > > > > Now suppose that I want to write a query to get the age of all living persons on a particular day. > > In other words, I'd like to do something kind of like this: > > > > PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> > > PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> > > PREFIX ex: <http://example.org/vocabulary#> > > PREFIX : <http://example.org/exampleDocument#> > > > > SELECT ?person $age > > WHERE { > > GRAPH ?g { > > ?person rdf:type ex:LivingPerson . > > ?person ex:age ?age . > > } > > ?g ex:startDate ?ctx_startDate . > > ?g ex:endDate ?ctx_endDate . > > FILTER (("1840-04-01T00:00:00Z"^^xsd:dateTime >= xsd:dateTime(?ctx_startDate)) && > > ("1840-04-01T00:00:00Z"^^xsd:dateTime <= xsd:dateTime(?ctx_endDate))) > > } > > > > ....except that won't work, since the "rdf:type ex:LivingPerson" and "ex:age 31" assertions > > live in two different graphs (even though each of those graphs represents a context which > > does contain April 1, 1840). > > > > Is there some way to make this work? Essentially, I think I'm looking for a way to > > have a query construct a dynamic merge of named graphs (without having to know the names > > of those graphs up-front). > > > > I’ve looked at the proposal for Composite Datasets > > (http://www.w3.org/2009/sparql/wiki/Feature:CompositeDatasets), and it sounds somewhat > > like what I’m seeking. But even with it, it sounds like I’d need to explicitly specify > > the graphs which I wanted to merge (instead of being able to just specify criteria about > > them, and letting the system find them). Correct? > > > > Also, I should note that I’m fairly new to semantic web technologies. So my apologies > > In advance if I’ve botched any of the above syntax or am just approaching this in a screwy > > way. > > > > Thanks, > > Jamey > > > > > -- Simon Schenk | ISWeb | Uni Koblenz http://isweb.uni-koblenz.de http://www.uni-koblenz.de/~sschenk Five sentences policy: http://five.sentenc.es/
Received on Tuesday, 25 August 2009 13:26:42 UTC