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

这里是 result on SNORQL.

此方法查找名称中带有 "fish" 一词的动物(例如:"starfish",它不是鱼,而是棘皮动物门的成员)。

想要更精确的查询,按门、class 或顺序等选择 DBpedia 项目

如何将查询更改为仅搜索 dbpedia2:phylum (Chordata);在 dbpedia2:classis(放线纲);在 dbpedia2:familia 上;等 ?

查看 Tuna,我看到 rdf:type 断言 class

http://umbel.org/umbel/rc/Fish

看起来很有用。例如,

select ?fish { ?fish a <http://umbel.org/umbel/rc/Fish> }

SPARQL results (10,000)

还有 dbpedia-owl:Fish class,得到更多的结果:

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

SPARQL results (17,420)

虽然 Wikipedia 有很多科学 classification 信息,但我在 DBpedia 中并没有看到很多。例如,。而 Wikipedia article for Tuna has kingdom, phylum, class, order, etc., I don't see that data in the corresponding DBpedia resource.

备注

请注意,您编写的查询实际上不是合法的 SPARQL(即使 Virtuoso,DBpedia 使用的 SPARQL 端点接受它)。投影变量之间不能有逗号。另外,一旦你group by一个变量,非组变量就不能出现在变量列表中。不过,您可以 采样 其他值。例如,你应该以这样的方式结束:

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