[英]How to search for rdfs:labels in dbpedia which are partial matches to a given term using SPARQL?
[英]SPARQL DBpedia by taxonomic term
使用以下有效的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
; 等
看着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 .
}
盡管Wikipedia具有許多科學的分類信息,但我認為DBpedia並沒有反映出很多信息。 例如,。 盡管有關Tuna的Wikipedia文章包含王國,門,等級,順序等,但我沒有在相應的DBpedia資源中看到該數據。
請注意,按照您的書面查詢,實際上不是合法的SPARQL(即使DBpedia使用的SPARQL端點Virtuoso接受了該查詢)。 投影變量之間不能有逗號。 同樣,一旦按一個變量分組 ,非分組變量就不會出現在變量列表中。 您可以采樣其他值。 例如,您應該以如下形式結束:
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.