SPARQL:从dbpedia

时间:2016-07-07 15:33:54

标签: sparql dbpedia

我想从DBPedia中为5个电影(或电影)个人提取图表。

我的查询是:

ParameterizedSparqlString qs = new ParameterizedSparqlString(“”+
                    “构造{?s?p?o}”+                     “{{s s http://dbpedia.org/ontology/Film。”+                         “?s?p?o”} OFFSET 0 LIMIT 5“);

我得到以下结果:

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

问题: 同一部电影的回归次数为5次:Film,Thing,Q386724,WIKIdata:Q11424,而作品是同等级别(或存在子类关系)。

我的问题:

我想要三次

返回
 <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> .

并过滤掉其他4个三元组。

怎么样?

提前谢谢

2 个答案:

答案 0 :(得分:4)

我认为以下内容适合您:

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

答案 1 :(得分:1)

我想你想要这个查询

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