从相同 class 的实例中检索属性及其描述
Retrieve properties and their descriptions from instances of the same class
我想检索具有相同类型 (class) 的实例的所有不同对象属性,从两个初始种子(wd:Q963 和 wd:Q42320)开始。首先,我询问此类种子的类型(可能还有子类型)。其次,检索相同 class 种子的所有实例。第三,检索实例的属性。最后,我想检索这些属性的描述,如果可能的话还有其他标签。我的查询如下:
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").
}
问题是我的实际查询需要花费大量时间,并且在 public 维基数据端点中失败。有谁能给我一些提示来优化这样的查询吗?
老实说,我无法理解您的查询目的。我想你对语义相似性或类似的东西感兴趣。
基本上,您可以减少连接数,只检索具有嵌套 SELECT DITINCT
.
的唯一 wdt-predicates
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" . }
}
即使 SERVICE wikibase:label
也足够快(~ 3 秒)。
另外,你 FILTER(strstarts(str(?property),str(wdt:)))
在 ?claimPredicate wikibase:directClaim ?property
之后。
至于 hint:Query hint:optimizer "None"
,此提示强制 Blazegraph 遵循标准 bottom-up evaluation order. In this particular query, hint:Query hint:optimizer "Runtime"
or hint:SubQuery hint:runOnce true
should also 工作。
我想检索具有相同类型 (class) 的实例的所有不同对象属性,从两个初始种子(wd:Q963 和 wd:Q42320)开始。首先,我询问此类种子的类型(可能还有子类型)。其次,检索相同 class 种子的所有实例。第三,检索实例的属性。最后,我想检索这些属性的描述,如果可能的话还有其他标签。我的查询如下:
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").
}
问题是我的实际查询需要花费大量时间,并且在 public 维基数据端点中失败。有谁能给我一些提示来优化这样的查询吗?
老实说,我无法理解您的查询目的。我想你对语义相似性或类似的东西感兴趣。
基本上,您可以减少连接数,只检索具有嵌套 SELECT DITINCT
.
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" . }
}
即使 SERVICE wikibase:label
也足够快(~ 3 秒)。
另外,你 FILTER(strstarts(str(?property),str(wdt:)))
在 ?claimPredicate wikibase:directClaim ?property
之后。
至于 hint:Query hint:optimizer "None"
,此提示强制 Blazegraph 遵循标准 bottom-up evaluation order. In this particular query, hint:Query hint:optimizer "Runtime"
or hint:SubQuery hint:runOnce true
should also 工作。