向DBPedia查询具有给定属性集的实体 [英] Querying DBPedia for entities having a given set of properties

查看:75
本文介绍了向DBPedia查询具有给定属性集的实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个介于5到100个属性之间的列表,想要查询具有这些属性(对值不感兴趣)的任何实体,这些实体之间的匹配项最多。如何使用SPARQL查询来实现?例如,假设我具有以下属性:

  dbpedia-owl:country 
dbpedia-owl:elevation
dbpedia-owl:领导
dbpprop:区域
dbpprop:标志
dbpprop:name

查询应返回具有所有这些属性值的所有资源,以及仅与某些属性匹配的资源。结果将在许多城市和国家/地区进行,但例如,它还应包括具有领导者和姓名,但没有标志,地区或海拔的组织。

解决方案

这是一种写起来很昂贵的查询,但是非常简单。您需要这样的东西:

 选择?subject(count(?property)为?numProperties),其中{
个值属性{
dbpedia-owl:country dbpedia-owl:elevation
dbpedia-owl:leader dbpprop:area dbpprop:flag
dbpprop:name
}
?subject属性?对象
}
分组?对象
顺序由desc(?numProperties)
限制10

实际上确实有一堆 dbpprop:name 值:

  select(count(distinct?name)as?numNames),其中{
< http://dbpedia.org/ resource / List_of_Advanced_Dungeons_& _Dragons_2nd_edition_monsters>
dbpprop:name?name
}




1971


SPARQL结果


I have a list of somewhere between 5 and 100 properties and want to query for any entities having these properties (not interested in the values), ranged by most matches. How can this be achieved with a SPARQL query? For instance, say I have the following properties:

dbpedia-owl:country
dbpedia-owl:elevation
dbpedia-owl:leader
dbpprop:area
dbpprop:flag
dbpprop:name
…

The query should return all resources having values for all of these these properties, as well as resources that match just some of the properties. The results will lots of cities and countries, but it should also include, for example, an organization that has a leader and name, but not a flag, area or elevation.

解决方案

This is sort of an expensive query to write, but it's pretty straightforward. You need something like this:

select ?subject (count(?property) as ?numProperties) where {
  values ?property {
    dbpedia-owl:country dbpedia-owl:elevation
    dbpedia-owl:leader dbpprop:area dbpprop:flag
    dbpprop:name
  }
  ?subject ?property ?object 
}
group by ?subject 
order by desc(?numProperties)
limit 10

SPARQL results

This says to find triples with any of the properties that you've enumerated and, for each ?subject, count the number of properties that there were values for and call it ?numProperties, and present the results ordered by ?numProperties (with greatest number of properties first).

Those numbers look rather high, but it's because those list pages have lots of values defined for certain properties. For instance, List of Advanced Dungeons & Dragons 2nd edition monsters really does have a whole bunch of dbpprop:name values:

select (count(distinct ?name) as ?numNames) where { 
  <http://dbpedia.org/resource/List_of_Advanced_Dungeons_&_Dragons_2nd_edition_monsters> 
    dbpprop:name ?name
}

1971

SPARQL results

这篇关于向DBPedia查询具有给定属性集的实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆