【发布时间】:2017-03-22 19:10:34
【问题描述】:
在schema.org官方文档上,我可以看到每个类都继承了Thing类的属性,例如Book类也有name、image等(属性来自@987654327 @)。
我的问题是,我能否获得 schema.org 数据存储中每个实体(Thing 的子类)的 image(Thing 属性)?例如Book 类实体具有<http://schema.org/Book/image> 等属性,但VideoGame 实体具有<http://schema.org/VideoGame/image>。我想做一个 SPARQL 查询来获取每个实体的 image,在其 name 属性中包含某个关键字(不幸的是,它又是 Thing 属性)
我试过这个:
String queryString ="select distinct ?graph ?img where {{?a <http://schema.org/name> ?obj. ?a <http://schema.org/image> ?img} union {GRAPH ?graph {?a <http://schema.org/name> ?obj. ?a <http://schema.org/image> ?img }} filter(regex(?obj, \""+keyword+"\",\"i\"))}";
select distinct ?graph ?img where {
{?a <http://schema.org/name> ?obj.
?a <http://schema.org/image> ?img}
union
{ GRAPH ?graph {
?a <http://schema.org/name> ?obj.
?a <http://schema.org/image> ?img
}
}
filter(regex(?obj, \""+keyword+"\",\"i\"))
}
altought 在三重存储中,Book 实体的image 属性具有<http://schema.org/Book/image> 等属性
以下方法有效,但仅限于 Book 实体:
String queryString ="select distinct ?graph ?img where {{?a <http://schema.org/Book/name> ?obj. ?a <http://schema.org/Book/image> ?img} union {GRAPH ?graph {?a <http://schema.org/Book/name> ?obj. ?a <http://schema.org/Book/image> ?img }} filter(regex(?obj, \""+keyword+"\",\"i\"))}";
select distinct ?graph ?img where {
{ ?a <http://schema.org/Book/name> ?obj.
?a <http://schema.org/Book/image> ?img }
union
{ GRAPH ?graph {
?a <http://schema.org/Book/name> ?obj.
?a <http://schema.org/Book/image> ?img
}
}
filter(regex(?obj, \""+keyword+"\",\"i\"))
}
有人知道我如何通过Thing 属性进行查询,而不管实体的类是什么(但实体仍然是Thing 的子类)?
感谢您的宝贵时间!
更新
三元组由 Web Data Commons 于 2016 年 10 月为 schema.org (http://webdatacommons.org/structureddata/2016-10/stats/schema_org_subsets.html) 提供。更具体地说,我获取了所有 sample 文件并将它们合并到一个三重存储中。
不幸的是,正如@Vladimir 和@AKSW 指出的那样,这个语料库中存在错误,<http://schema.org/Book/image> 而不是<http://schema.org/image> 的存在就是其中之一。
我在 Web Data Common 的邮件列表中发现了其他用户提出的类似问题。提取元数据时似乎是解析错误。
感谢您的 cmets,至少我理解了查询 schema.org 带注释三元组的正确方法(当它们有效时 :))。
【问题讨论】:
-
我不明白这个问题,但我对 SPARQL 不是很熟悉。从schema.org/Book 我可以看到书籍也使用相同的属性
http://schema.org/image来表示图像。那么每个类使用不同的 URI 是从哪里来的呢? -
三重存储包含如下语句:
<subject> <http://schema.org/Book/image> <object>,或<subject> <http://schema.org/VideoGame/image> <object>。考虑到image是从Thing继承而来的,我还期望它们是<http://schema.org/image>... -
好的,但是数据并不是真正的最佳建模。现在您想拥有所有图像而不限于特定类别?
标签: java sparql jena schema.org