SPARQL - 按标签获取属性

SPARQL - get properties by label

对于我当前的项目,我需要从 dbpedia 中提取信息。我唯一的信息是资源的标签。

举个例子:

我有资源"car"。现在我想得到例如摘要。 有没有办法用 SPARQL 解决这个问题?

如果您按标签查找,例如:

SELECT distinct ?item ?itemLabel ?itemDescription WHERE{  
  ?item ?label "Car"@en.    
  ?article schema:about ?item .
  ?article schema:inLanguage "en" .
  ?article schema:isPartOf <https://en.wikipedia.org/>. 
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }    
}

你得到了几个项目:

您可以在 Wikidata Query Page 上看到它。 (比起 DBpedia,我更喜欢维基数据查询服务)。

因此您需要指定一些额外的参数以仅获取所需的项目。

其他答案无法让您从 DBpedia 获得结果,这正是您所说的。也不清楚您是否想要标签 包含 您的已知字符串,或者 您的已知字符串的资源的结果。

几个示例,直接链接到查询表单和结果,假设您只关心英文摘要和标签...

Label case-insensitively includes car (live results)

PREFIX  rdfs:  <http://www.w3.org/2000/01/rdf-schema#>
PREFIX   dbo:  <http://dbpedia.org/ontology/>
PREFIX   bif:  <bif:>

SELECT DISTINCT ?itemLabel  
                ?item  
                ?itemDescription 
 WHERE
   {  
     ?item       rdfs:label    ?itemLabel .
     ?itemLabel  bif:contains  "car" .
     ?item       dbo:abstract  ?itemDescription .
     FILTER (lang(?itemDescription) = 'en')
     FILTER (lang(?itemLabel) = 'en')
   }
ORDER BY ?itemLabel

Label is exactly "Car"@en (live results)

PREFIX  rdfs:  <http://www.w3.org/2000/01/rdf-schema#>
PREFIX   dbo:  <http://dbpedia.org/ontology/>

SELECT DISTINCT *
 WHERE
   {  
     ?item       rdfs:label    ?itemLabel .
     FILTER ( ?itemLabel  =  "Car"@en ) .
     ?item       dbo:abstract  ?itemDescription .
     FILTER (lang(?itemDescription) = 'en')
   }
 ORDER BY ?itemLabel