进行以下工作SPARQL
查询,从DBpedia中选择名称中包含字符串“fish”的项目。
SELECT ?name, ?kingdom, ?phylum, ?class, ?order, ?family, ?genus, ?species, ?subspecies, ?img, ?abstract
WHERE {
?s dbpedia2:regnum ?hasValue;
rdfs:label ?name
FILTER regex( ?name, "fish", "i" )
FILTER ( langMatches( lang( ?name ), "EN" ))
?animal dbpedia2:name ?name;
foaf:depiction ?img;
dbpedia2:regnum ?kingdom
OPTIONAL { ?animal dbpedia2:ordo ?order . }
OPTIONAL { ?animal dbpedia2:phylum ?phylum . }
OPTIONAL { ?animal dbpedia2:classis ?class . }
OPTIONAL { ?animal dbpedia2:familia ?family . }
OPTIONAL { ?animal dbpedia2:genus ?genus . }
OPTIONAL { ?animal dbpedia2:species ?species . }
OPTIONAL { ?animal dbpedia2:subspecies ?subspecies . }
OPTIONAL {
FILTER ( langMatches( lang( ?abstract ), "EN" ))
}
}
GROUP BY ?name
LIMIT 500
这种方法在其名称中找到了带有“鱼”字样的动物(例如:“海星”,它不是鱼,而是棘皮动物门的成员)。
想要一个更精确的查询,按门,按类或按顺序等选择DBpedia项目。
如何将查询更改为仅在dbpedia2:phylum
(Chordata)上搜索;在dbpedia2:classis
(Actinopterygii);在dbpedia2:familia
;等?
答案 0 :(得分:1)
查看Tuna,我看到该类有一个rdf:type断言
<强> http://umbel.org/umbel/rc/Fish 强>
看起来很有用。例如,
select ?fish { ?fish a <http://umbel.org/umbel/rc/Fish> }
还有 dbpedia-owl:Fish 类,它可以获得更多结果:
select (count(*) as ?nFish) where {
?fish a dbpedia-owl:Fish .
}
虽然维基百科有很多科学的分类信息,但我没有看到它在DBpedia中有太多反映。例如,。虽然Wikipedia article for Tuna有王国,门,阶级,秩序等,但我在the corresponding DBpedia resource中看不到这些数据。
请注意,您所写的查询实际上并不合法SPARQL(即使Virtuoso,DBpedia使用的SPARQL端点,也接受它)。投影变量之间不能有逗号。此外,一旦分组一个变量,非组变量就不会出现在变量列表中。您可以示例其他值。例如,你应该得到类似的东西:
SELECT
?name
(sample(?kingdom) as ?kingdom_)
(sample(?phylum) as ?phylum_)
#-- ...
(sample(?img) as ?img_)
(sample(?abstract) as ?abstract_)
WHERE {
?s dbpedia2:regnum ?hasValue;
rdfs:label ?name
FILTER regex( ?name, "fish", "i" )
FILTER ( langMatches( lang( ?name ), "EN" ))
?animal dbpedia2:name ?name;
foaf:depiction ?img;
dbpedia2:regnum ?kingdom
OPTIONAL { ?animal dbpedia2:ordo ?order . }
OPTIONAL { ?animal dbpedia2:phylum ?phylum . }
OPTIONAL { ?animal dbpedia2:classis ?class . }
OPTIONAL { ?animal dbpedia2:familia ?family . }
OPTIONAL { ?animal dbpedia2:genus ?genus . }
OPTIONAL { ?animal dbpedia2:species ?species . }
OPTIONAL { ?animal dbpedia2:subspecies ?subspecies . }
OPTIONAL {
FILTER ( langMatches( lang( ?abstract ), "EN" ))
}
}
GROUP BY ?name
LIMIT 500