【问题标题】:Query sub-classes of Thing by properties inherited from Thing通过继承自 Thing 的属性查询 Thing 的子类
【发布时间】:2017-03-22 19:10:34
【问题描述】:

在schema.org官方文档上,我可以看到每个类都继承了Thing类的属性,例如Book类也有nameimage等(属性来自@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 属性具有&lt;http://schema.org/Book/image&gt; 等属性

以下方法有效,但仅限于 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 指出的那样,这个语料库中存在错误,&lt;http://schema.org/Book/image&gt; 而不是&lt;http://schema.org/image&gt; 的存在就是其中之一。

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

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

【问题讨论】:

  • 我不明白这个问题,但我对 SPARQL 不是很熟悉。从schema.org/Book 我可以看到书籍也使用相同的属性http://schema.org/image 来表示图像。那么每个类使用不同的 URI 是从哪里来的呢?
  • 三重存储包含如下语句:&lt;subject&gt; &lt;http://schema.org/Book/image&gt; &lt;object&gt;,&lt;subject&gt; &lt;http://schema.org/VideoGame/image&gt; &lt;object&gt;。考虑到image 是从Thing 继承而来的,我还期望它们是&lt;http://schema.org/image&gt;...
  • 好的,但是数据并不是真正的最佳建模。现在您想拥有所有图像而不限于特定类别?

标签: java sparql jena schema.org


【解决方案1】:

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

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")
        }
    }
  }

【讨论】:

  • 谢谢,我尝试了第一种方法。确实,三重存储包含一些无效语句(我添加了对我的问题的更新),但是如果我想克服错误并获得所需的结果,您的解决方案就可以工作。
【解决方案2】:

你是指哪家三联店? Schema 没有您提到的属性 URL。修复该数据(或询问制作它的人来修复它)

【讨论】:

  • 感谢您的回复!我搜索了更多,确实有些三元组无效。我为我的问题添加了更新
猜你喜欢
  • 2011-01-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-02-28
  • 2010-12-14
  • 2021-10-27
  • 2019-05-27
  • 1970-01-01
相关资源
最近更新 更多