简体   繁体   中英

How to extract RDF triples with specific predicates using sparql

I uploaded a set of RDF triples onto a local Virtuoso endpoint.

Of all these triples, I would like to extract only those whose subjects have at least the predicates http://www.w3.org/2000/01/rdf-schema#label and http://www.w3.org/2000/01/rdf-schema#comment .

For example, from these triples:

<http://dbpedia.org/resource/AccessibleComputing> <http://www.w3.org/2000/01/rdf-schema#label> "AccessibleComputing"@en .
<http://dbpedia.org/resource/AfghanistanGeography> <http://www.w3.org/2000/01/rdf-schema#label> "AfghanistanGeography"@en .
<http://dbpedia.org/resource/AfghanistanGeography> <http://www.w3.org/2000/01/rdf-schema#comment> " ... " .
<http://dbpedia.org/resource/Austroasiatic_languages> <http://www.w3.org/2000/01/rdf-schema#comment> " ... " .
<http://dbpedia.org/resource/AccessibleComputing> <http://dbpedia.org/ontology/wikiPageWikiLink> <http://dbpedia.org/resource/Computer_accessibility> .
<http://dbpedia.org/resource/AfghanistanGeography> <http://dbpedia.org/ontology/wikiPageWikiLink> <http://dbpedia.org/resource/Afghanistan_Geography> .

I would like to get:

<http://dbpedia.org/resource/AfghanistanGeography> <http://www.w3.org/2000/01/rdf-schema#label> "AfghanistanGeography"@en .
<http://dbpedia.org/resource/AfghanistanGeography> <http://www.w3.org/2000/01/rdf-schema#comment> " ... " .
<http://dbpedia.org/resource/AfghanistanGeography> <http://dbpedia.org/ontology/wikiPageWikiLink> <http://dbpedia.org/resource/Afghanistan_Geography> .

Is it possible to do this with one (or more) SPARQL query?

Thank you for helping

This can be done with a CONSTRUCT WHERE query:

CONSTRUCT WHERE {
    ?s rdfs:label ?label.
    ?s rdfs:comment ?comment.
    ?s ?p ?o
}

This is a simplified form of CONSTRUCT that can be used when the CONSTRUCT {} part and the WHERE {} part are identical.

One way is to use DESCRIBE , eg:

DESCRIBE ?s 
WHERE {
  ?s rdfs:label ?label .
  ?s rdfs:comment ?comment .
}

or alternatively with CONSTRUCT :

CONSTRUCT { ?subject ?predicate ?object} 
WHERE {
  ?subject ?predicate ?object .
  FILTER EXISTS {
     ?subject rdfs:label ?label .
     ?subject rdfs:comment ?comment .
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM