【问题标题】:Retrieve properties and their descriptions from instances of the same class从同一类的实例中检索属性及其描述
【发布时间】:2018-03-22 02:08:45
【问题描述】:

我想检索具有相同类型(类)的实例的所有不同对象属性,从两个初始种子(wd:Q963 和 wd:Q42320)开始。首先,我询问此类种子的类型(可能还有子类型)。其次,检索同一类种子的所有实例。第三,检索实例的属性。最后,我想检索这些属性的描述以及可能的替代标签。我的查询如下:

select distinct ?property ?description ?label where{
  {     
    wd:Q963 wdt:P31 ?typesSubject . 
    ?instancesS (wdt:P31|wdt:P279) ?typesSubject .
    ?instancesS ?property ?unknown .
  }
 UNION
  { 
    wd:Q42320 wdt:P31 ?typesObject . 
    ?instancesO (wdt:P31|wdt:P279) ?typesObject . 
    ?unknown ?property ?instancesO . 
  }

 ?claimPredicate wikibase:directClaim ?property . 
 ?claimPredicate schema:description ?description .  
 ?claimPredicate rdfs:label ?label .  

   FILTER(strstarts(str(?property),str(wdt:)))
   FILTER(strstarts(str(?unknown),str(wd:)))

   FILTER(LANG(?description) = "en").  
   FILTER(LANG(?label) = "en"). 

}

问题是我的实际查询需要很长时间,并且在公共 Wikidata 端点中失败。有谁可以给​​我一些提示来优化这样的查询?

【问题讨论】:

  • 407 属性的检索大约需要 3 秒:select distinct ?property where{ { ?instancesS (wdt:P31|wdt:P279)/^wdt:P31 wd:Q963 . ?instancesS ?property ?unknown . FILTER(strstarts(str(?property),str(wdt:))) } UNION { ?instancesO (wdt:P31|wdt:P279)/^wdt:P31 wd:Q42320 . ?unknown ?property ?instancesO . FILTER(strstarts(str(?unknown),str(wd:))) } } 问题在于声明的加入
  • 谢谢@AKSW,你是对的,我不知道如何解决这样的加入问题

标签: properties query-optimization sparql union wikidata


【解决方案1】:

说实话,我无法理解您查询的目的。我想你对语义相似性或类似的东西感兴趣。

基本上,您可以减少连接数,仅检索具有嵌套 SELECT DITINCT 的唯一 wdt 谓词。

SELECT ?property ?claimPredicateLabel ?claimPredicateDescription 
WHERE {
  hint:Query hint:optimizer "None" .
  {  
  SELECT DISTINCT ?property {
    VALUES (?s) {(wd:Q963) (wd:Q42320)}
    ?s wdt:P31/^(wdt:P31|wdt:P279) ?instances .
    ?instances ?property ?unknown .
    }
  }
  ?claimPredicate wikibase:directClaim ?property . 
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . }
}

Try it!

即使使用SERVICE wikibase:label,这也足够快(~ 3 秒)。

另外,don't need FILTER(strstarts(str(?property),str(wdt:)))?claimPredicate wikibase:directClaim ?property 之后。


对于hint:Query hint:optimizer "None",此提示强制 Blazegraph 遵循标准的bottom-up 评估顺序。在这个特定的查询中,hint:Query hint:optimizer "Runtime"hint:SubQuery hint:runOnce true 应该 also 工作。

【讨论】:

  • 非常感谢@Stanislav,查询提示帮助很大。此外,我还将指令(GROUP_CONCAT(?alternative;separator="|") as ?altLabel)?claimPredicate skos:altLabel ?alternative .group by 一起包含,以便获得同一行中每个属性的所有可能的替代标签
猜你喜欢
  • 2011-10-24
  • 1970-01-01
  • 2012-09-17
  • 2020-03-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-03-03
相关资源
最近更新 更多