查找资源的常见类别或超类别 [英] Finding common categories or supercategories of resources

查看:82
本文介绍了查找资源的常见类别或超类别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道我们是否可以知道DBpedia中的两个资源是否具有相同的类别或某个子类别(即,属于某些公共超类别的类别)?我在DBpedia端点中尝试了此查询,但这是错误的:

I'm wondering if we can know whether two resources have the same category or some subcategory (i.e., belong to categories of some common supercategory) in DBpedia? I tried this query in the DBpedia endpoint but it's wrong:

select distinct ?s ?s2 where {
?s skos:subject <http :// dbpedia.org/resource/ Category ?c.
?s2 skos:subject <http :// dbpedia.org/resource/ Category ?c2.
?c=?c2.
}

推荐答案

DBpedia不使用skos:subject作为资源,而是使用dcterms:subject将资源与其Wikipedia类别相关联.您可以通过浏览资源页面找出可用的数据.例如,您可以查看 http://dbpedia.org/resource/Mount_Monadnock .如果要查找两个资源共有的类别,只需使用相同的变量即可.例如,

DBpedia doesn't use skos:subject for resources, but rather relates resources to their Wikipedia categories using dcterms:subject. You can find out what data is available by browsing the resource pages. E.g., you might have a look at http://dbpedia.org/resource/Mount_Monadnock. If you want to find categories that two resources have in common, just use the same variable. E.g.,

?subject1 dcterms:subject ?category .
?subject2 dcterms:subject ?category .

您可以使用^property表示法和对象列表更简洁地编写该内容.编写o ^p s与编写s p o相同.对象列表使您可以编写s p o1, o2而不是s p o1. s p o2..将它们放在一起,我们可以写:

You can write that more concisely with the ^property notation and object lists. Writing o ^p s is the same as writing s p o. Object lists let you write s p o1, o2 instead of s p o1. s p o2.. Putting these together, we can write:

?category ^dcterms:subject ?subject1, ?subject2 .

例如,这是一个查询,该查询可找到Mount Monadnock和Spofford Lake的常见类别.只有一个结果是新罕布什尔州柴郡县的地貌,因为它们只有一个共同的类别.

E.g., here's a query that finds common categories of Mount Monadnock and Spofford Lake. There's just one result, Landforms of Cheshire County, New Hampshire, since they only have one category in common.

select * where {
  ?category ^dcterms:subject dbpedia:Mount_Monadnock, dbpedia:Spofford_Lake .
}

现在,类别与skos:broader在DBpedia中的超类别相关,如您在 http://dbpedia.org/page/Category:Landforms_of_Cheshire_County,_New_Hampshire ,其中有指向

Now, categories are related to their supercategories in DBpedia by skos:broader, as you can see in http://dbpedia.org/page/Category:Landforms_of_Cheshire_County,_New_Hampshire, where there are links to

  • http://dbpedia.org/resource/Category:Landforms_of_New_Hampshire_by_county and
  • http://dbpedia.org/resource/Category:Geography_of_Cheshire_County,_New_Hampshire

现在,这意味着如果两个事物具有某个共同的类别(或超类别),则每个事物都将通过该路径与该类别相关,该路径以dcterms:subject链接开头,然后是零个或多个skos:broader链接.因此,您可以使用类似

Now, this means that if two things have have some common category (or supercategory), each will be related to that category by a path starting with a dcterms:subject link and followed by zero or more skos:broader links. Thus, you could use a query like

select * where {
  ?category ^(dcterms:subject/skos:broader*) dbpedia:Mount_Monadnock, dbpedia:Spofford_Lake .
}

不幸的是,您会发现该查询的DBpedia端点遇到内存使用问题,因此您不能完全那样运行它.但是,DBpedia SPARQL端点支持实际上没有使其成为标准的属性路径功能.您可以编写p{n,m}来表示长度至少为n且最大为m的链.这意味着您可以放置​​一些范围,以获得与*相同的结果:

You'll find, unfortunately, that the DBpedia endpoint runs into memory usage problems with that query, so you can't run it exactly like that. However, the DBpedia SPARQL endpoint supports a property path feature that actually didn't make it into the standard; you can write p{n,m} to denote a chain of length at least n and at most m. This means you can put some ranges on that will get you most of the same results as *:

select distinct ?category where {
  ?category ^(dcterms:subject/(skos:broader{0,3})) dbpedia:Mount_Monadnock, dbpedia:Spofford_Lake .
}

这也适用于汤姆·克鲁斯(Tom Cruise)和麦当娜(Madonna),尽管由于内存问题,您需要缩小路径长度.例如,以下查询返回74个结果.

This works with Tom Cruise and Madonna as well, though you'll need to scale back the path length a bit because of the memory issues. For instance, the following query returns seventy-four results.

select distinct ?category where {
  ?category
      ^(dcterms:subject/(skos:broader{0,2}))
          <http://dbpedia.org/resource/Tom_Cruise>,
          <http://dbpedia.org/resource/Madonna_(entertainer)> .
}

但是,值得注意的是,维基百科类别不是类型.因此,尽管将这两种资源都正确地视为地貌,但 都不是地理,也不是新罕布什尔州(在后面的查询中将看到).维基百科的类别更多是关于主题,而不是类型层次结构.

It's worth noting, though, that Wikipedia categories aren't types. So while both of those resources are rightly considered to be landforms, neither is a geography or, as you'll see in the later query, New Hampshire. Wikipedia categories are much more about topic than a type hierarchy.

还有一个相关的(但不是很重复的问题)也可能会有所帮助:使用SPARQL来查找多次出现的主题具有相同的属性.

There's a related (but not quite duplicate question) that you might find helpful as well: Using SPARQL to locate a subject with multiple occurrences of same property.

这篇关于查找资源的常见类别或超类别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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