Sparql asks for collection and rdf: containers?

Hello to all rdf / sparql developers. There is a question that has been imposing on me for some time, but no one seems to have answered it exactly, since the rdf and sparql specifications were released.

To state this, RDF defines several ways to solve the multi-valued resource properties; from creating as many triples as possible with the same subjet predicate bias to collections or containers. This is good because each template has its own characteristics.

But, as can be seen from the point of view of SPARQL, it seems to me that querying these structures leads to overly complex queries that (even worse) cannot translate into a reasonable set of results: you cannot use variables for query of arbitrary length and thePath property does not save " natural "order.

In the naive form, in many SELECT or ASK queries, if I want to query or filter the values ​​of a container or list, I will not in most cases care about what the main template is (if any). For example:

<rdf:Description rdf:about="urn:1"> <rdfs:label> <rdf:Alt> <rdf:li xml:lang="fr">Exemple n°1</rdf:li> <rdf:li xml:lang="en">Example #1</rdf:li> </rdf:Alt> </rdfs:label> <my:release> <rdf:Seq> <rdf:li>10.0</rdf:li> <rdf:li>2.4</rdf:li> <rdf:li>1.1.2</rdf:li> <rdf:li>0.9</rdf:li> </rdf:Seq> </my:release> </rdf:Description> <rdf:Description rdf:about="urn:2"> <rdfs:label xml:lang="en">Example #2</rdfs:label> </rdf:Description> 

Obviously, I expected both resources to respond to the request:

 SELECT ?res WHERE { ?res rdfs:label ?label . FILTER ( contains(?label, 'Example'@en) } 

I would also expect a request:

 SELECT ?ver WHERE { <urn:1> my:release ?ver } 

to return rdf: Seq elements (or any rdf: Alt for that matter) in the original order (for other templates it doesn’t matter if the original order is preserved or not, so why not save it anyway?) - if not explicitly specified through the ORDER BY clause.

Of course, it would be necessary to maintain compatibility with the old way, so would it be possible to extend the propertyPath syntax with a new operator?

I feel this will simplify the everyday use of SPARQL.

Does that make sense to you? Also, do you see any reason why not try to implement it?

EDIT adjusted example urn: 2 rdfs: invalid label value

+7
source share
2 answers

RDF defines a dictionary for collections and containers, but they do not have much meaning in terms of interpreting the graphs containing them. They are not intended and are not suitable for representing ambiguous properties.

Generally speaking:

 :A :predicate [ a rdf:Alt ; rdf:_1 :B ; rdf:_2 :C ] . 

Not equivalent

 :A :predicate :B , :C . 

Say the predicate is an owl: sameAs:

 :A owl:sameAs [ a rdf:Alt ; rdf:_1 :B ; rdf:_2 :C ] . 

It is said above that: Individual names containing: B and: C, whereas:

 :A owl:sameAs :B , :C . 

says that: A ,: B and: C are the same.

SPARQL is independent of containers and collections (except for the syntax reduction for rdf: List). If you need a more convenient way to work with collections, many RDF APIs, including Jena and rdflib, have first-class views for them.

Adding

A method for modeling multi-valued properties, i.e. to simulate that both "Example n ° 1" @fr and "Example # 1" @en are labels for urn: 1 is just two facts:

 <rdf:Description rdf:about="urn:1"> <rdfs:label xml:lang="fr">Exemple n°1</rdfs:label> <rdfs:label xml:lang="en">Example #1</rdfs:label> ... </rdf:Description> 

And request:

 SELECT ?res WHERE { ?res rdfs:label ?label . FILTER ( contains(?label, 'Example'@en) ) } 

will match the English labels for <urn: 1> and <urn: 2>.

For the my: release property, where you have a multi-valued property and the order of its values, this is a bit more complicated. You can define a new property (for example) my: releases, whose value is rdf: List or rdf: Seq. my: release gives a direct relationship, and my: releases an indirect relationship indicating explicit ordering. With the output repository and the corresponding rule, you only need to provide the latter. Unfortunately, this does not facilitate the use of the order in SPARQL.

An approach that is easier to work in and without SPARQL repositories would be to make the versions themselves objects with properties that determine the order:

  <rdf:Description rdf:about="urn:1"> <rdfs:label xml:lang="fr">Exemple n&#xB0;1</rdfs:label> <rdfs:label xml:lang="en">Example #1</rdfs:label> <my:release> <my:Release> <dc:issued rdf:datatype="&xsd;date">2008-10-10/dc:issued> <my:version>10.0</my:version> </my:Release> </my:release> <my:release> <my:Release> <my:version>2.4</my:version> <dc:issued rdf:datatype="&xsd;date">2007-05-01</dc:issued> </my:Release> </my:release> ... </rdf:Description> 

In the above example, the date can be used to organize the results, since there is no explicit sequence. The query is a bit more complicated:

 SELECT ?ver WHERE { <urn:1> my:release [ my:version ?ver ; dc:issued ?date ] } ORDER BY ?date 
+4
source

I understand that this question already has an answer, but it's worth taking a look at what you can do here if you use RDF lists and not other types of RDF containers. First, the data you provided (after you provided namespace declarations) in Turtle:

 @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . @prefix my: <https://stackoverflow.com/q/16223095/1281433/> . <urn:2> rdfs:label "Example #2"@en . <urn:1> rdfs:label [ a rdf:Alt ; rdf:_1 "Exemple n°1"@fr ; rdf:_2 "Example #1"@en ] ; my:release [ a rdf:Seq ; rdf:_1 "10.0" ; rdf:_2 "2.4" ; rdf:_3 "1.1.2" ; rdf:_4 "0.9" ] . 

The rdf:_n properties are a difficulty here, as they are the only thing that provides any real order for the elements in the sequence. (Alt does not have a really important sequence, although it still uses the rdf:_n properties.) You can get all three shortcuts if you use the SPARQL property path, which makes the rdf:_n property optional:

 prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> select ?x ?label where { ?x rdfs:label/(rdf:_1|rdf:_2|rdf:_3)* ?label filter( isLiteral( ?label )) } 
 ------------------------------ | x | label | ============================== | <urn:1> | "Exemple n°1"@fr | | <urn:1> | "Example #1"@en | | <urn:2> | "Example #2"@en | ------------------------------ 

See what you can do with RDF lists. If you use lists, then you are data:

 @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . @prefix my: <https://stackoverflow.com/q/16223095/1281433/> . <urn:2> rdfs:label "Example #2"@en . <urn:1> rdfs:label ( "Exemple n°1"@fr "Example #1"@en ) ; my:release ( "10.0" "2.4" "1.1.2" "0.9" ) . 

Now you can easily get tags:

 prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> select ?x ?label where { ?x rdfs:label/(rdf:rest*/rdf:first)* ?label filter( isLiteral( ?label )) } 
 ------------------------------ | x | label | ============================== | <urn:1> | "Exemple n°1"@fr | | <urn:1> | "Example #1"@en | | <urn:2> | "Example #2"@en | ------------------------------ 

If you want the position of the labels in the list of labels, you can even get this, although this makes the query a little more complicated:

 prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> select ?x ?label (count(?mid)-1 as ?position) where { ?x rdfs:label ?y . ?y rdf:rest* ?mid . ?mid rdf:rest*/rdf:first? ?label . filter(isLiteral(?label)) } group by ?x ?label 
 ----------------------------------------- | x | label | position | ========================================= | <urn:1> | "Exemple n°1"@fr | 0 | | <urn:1> | "Example #1"@en | 1 | | <urn:2> | "Example #2"@en | 0 | ----------------------------------------- 

This uses the technique in Is it possible to get the position of an element in an RDF collection in SPARQL? to calculate the position of each value in the list, which is the rdfs:label object, starting at 0 and assigning 0 elements that are not on the list.

+3
source

All Articles