通过从事物继承的属性查询事物的子类



在官方 schema.org 文档中,我可以看到每个类都继承了Thing类的属性,例如,Book类也有nameimage等(来自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"))
}

在三重存储中,Book实体的image属性具有<http://schema.org/Book/image>

以下方法有效,但仅限于预订实体:

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)提供。更具体地说,我获取了所有示例文件并将它们合并到一个三重存储中。

不幸的是,正如@Vladimir和@AKSW指出的那样,这个语料库中存在错误,<http://schema.org/Book/image>而不是<http://schema.org/image>的存在就是其中之一。

我在Web Data Common的邮件列表中发现了其他用户提出的类似问题。这似乎是提取元数据时的解析错误。

感谢您的评论,至少我理解了查询 schema.org 注释三元组的正确方法(当它们:)有效时)。

从我的角度来看,数据建模有点奇怪,但您可以使用以下查询,尽管这可能效率很低:

SELECT  ?o
WHERE
{ ?s  ?p  ?o
FILTER strends(str(?p), "/image")
}

首先获取子 SELECT 中的所有属性可能是一种更有效的方法,特别是对于更复杂的查询:

SELECT  ?o
WHERE
{ # do some other stuff here
?s  ?p  ?o
...
# get the image properties here 
{ SELECT DISTINCT  ?p
WHERE
{ ?s  ?p  ?o
FILTER strends(str(?p), "/image")
}
}
}

你指的是哪家三重商店?架构没有您提到的属性 URL。修复该数据(或询问制作者修复它)

最新更新