在官方schema.org文档中,我可以看到每个类都继承了 Thing
类的属性,例如, Book
类也有 name
, image
等(来自 Thing
的属性) .
我的问题是,我可以获得schema.org数据存储区中每个实体( Thing
的子类)的 image
( Thing
属性)吗?例如, Book
类实体具有 <http://schema.org/Book/image>
等属性,但 VideoGame
实体具有 <http://schema.org/VideoGame/image>
. 我想创建一个SPARQL查询来获取其 name
属性中包含某个关键字的每个实体的 image
(遗憾的是,这又是一个 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\"))
}
在triplestore中, 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
的子类)?
感谢您的时间!
UPDATE
三元组由Web Data Commons提供,2016年10月语音库为schema.org(http://webdatacommons.org/structureddata/2016-10/stats/schema_org_subsets.html) . 更具体地说,我获取了所有示例文件并将它们合并到一个三重存储中 .
不幸的是,正如@Vladimir和@AKSW指出的那样,这个语料库中存在错误,并且 <http://schema.org/Book/image>
而不是 <http://schema.org/image>
的存在就是其中之一 .
我在Web Data Common的邮件列表中发现了其他用户提出的类似问题 . 在提取元数据时,它似乎是一个解析错误 .
感谢您的评论,至少我理解查询schema.org带注释的三元组的正确方法(当它们有效时:)) .
2 回答
从我的观点来看,数据有点奇怪,但你可以使用以下查询,虽然这可能是非常低效的:
首先在子SELECT中获取所有属性可能更有效,特别是对于更复杂的查询:
你的意思是哪家三重店?架构没有您提到的属性URL . 修复该数据(或询问谁制作它,修复它)