簡體   English   中英

SPARQL DBpedia按分類術語

[英]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

這是SNORQL上結果

這種方法可以找到名稱中帶有“魚”一詞的動物(例如:“海星”,它不是魚,而是棘皮動物門的成員)。

想要一個更精確的查詢,該查詢按系統,類別或順序等選擇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> }

SPARQL結果(10,000)

還有dbpedia-owl:Fish類,它將獲得更多結果:

select (count(*) as ?nFish) where {
  ?fish a dbpedia-owl:Fish .
}

SPARQL結果(17,420)

盡管Wikipedia具有許多科學的分類信息,但我認為DBpedia並沒有反映出很多信息。 例如,。 盡管有關TunaWikipedia文章包含王國,門,等級,順序等,但我沒有在相應的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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM