SPARQL: extract distinct values from dbpedia

我是研究僧i 提交于 2019-12-11 04:44:45

问题


I want to extract graphs for 5 individuals who are Film(or movies) from DBPedia.

My query is:

ParameterizedSparqlString qs = new ParameterizedSparqlString( "" +
"construct{?s ?p ?o}"+ "where{?s a http://dbpedia.org/ontology/Film ."+ "?s ?p ?o"} OFFSET 0 LIMIT 5" );

I get the following result:

1- http://dbpedia.org/resource/1001_Inventions_and_the_World_of_Ibn_Al-Haytham http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://dbpedia.org/ontology/Film .

2- http://dbpedia.org/resource/1001_Inventions_and_the_World_of_Ibn_Al-Haytham http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://www.w3.org/2002/07/owl#Thing .

3- http://dbpedia.org/resource/1001_Inventions_and_the_World_of_Ibn_Al-Haytham http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://www.wikidata.org/entity/Q386724 .

4- http://dbpedia.org/resource/1001_Inventions_and_the_World_of_Ibn_Al-Haytham http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://dbpedia.org/ontology/Wikidata:Q11424 .

5- http://dbpedia.org/resource/1001_Inventions_and_the_World_of_Ibn_Al-Haytham http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://dbpedia.org/ontology/Work .

Problem: The same film is returned 5 times as all the class: Film, Thing, Q386724,WIKIdata:Q11424, and Work are equivalent class (or Subclass relation exist).

My question:

I want to return once the triple

 <http://dbpedia.org/resource/1001_Inventions_and_the_World_of_Ibn_Al-Haytham>    
 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> 
 <http://dbpedia.org/ontology/Film> .

and filter out the other 4 triples.

How do it please?

Thank you in advance


回答1:


I think you want this query

construct {?s a <http://dbpedia.org/ontology/Film> .}
where { ?s a <http://dbpedia.org/ontology/Film>. }
limit 5



回答2:


I think the following should work for you:

CONSTRUCT {?s ?p ?o}
WHERE {
  {  SELECT DISTINCT ?s
     WHERE {
        ?s a <http://dbpedia.org/ontology/Film> .
     } LIMIT 5
  }
  ?s ?p ?o .
}


来源:https://stackoverflow.com/questions/38249616/sparql-extract-distinct-values-from-dbpedia

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!