SPARQL - 按标签获取属性

时间:2016-12-17 17:27:52

标签: sparql dbpedia

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

举个例子:

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

2 个答案:

答案 0 :(得分:3)

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

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". }    
}

你得到几件物品:

enter image description here

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

因此,您需要指定一些额外的参数才能获得所需的项目。

答案 1 :(得分:2)

其他答案并没有从DBpedia获得结果,这就是您所说的。您还不清楚是否需要标记包含您已知字符串的资源的结果,或 您已知的字符串。

一些与查询表单和结果直接相关的示例,假设您只关心英文摘要和标签......

Label case-insensitively includes carlive 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"@enlive 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
相关问题