过滤具有相同值的两个属性
filter for two properties having the same value
我需要检索首都也是最大城市的南美洲国家列表。出于某种原因,我可以显示所有南美国家及其首都,但我无法使用过滤器选项将首都与最大城市进行比较:
SELECT DISTINCT ?country ?capital
WHERE {
?country a dbo:Country .
?country a <http://dbpedia.org/class/yago/SouthAmericanCountries>.
?country dbp:largestCity|dbo:largestCity ?capital.
}
对于第三个三元组,我使用了 2 个参数,因为并非所有国家/地区都有完整的数据。在 dbpedia 验证器上 运行 之后,我得到了这个:
http://dbpedia.org/sparql?default-graph-uri=http%3A%2F%2Fdbpedia.org&query=SELECT+DISTINCT+%3Fcountry+%3Fcapital%0D%0AWHERE+%7B%0D%0A%0D%0A++++%3Fcountry+a+dbo%3ACountry+.%0D%0A++++%3Fcountry+a+%3Chttp%3A%2F%2Fdbpedia.org%2Fclass%2Fyago%2FSouthAmericanCountries%3E.%0D%0A++++%0D%0A++++%3Fcountry+dbp%3AlargestCity%7Cdbo%3AlargestCity+%3Fcapital.%0D%0A%0D%0A++++%0D%0A%0D%0A%7D&format=text%2Fhtml&CXML_redir_for_subjs=121&CXML_redir_for_hrefs=&timeout=30000&debug=on
下一步是使用以下逻辑过滤国家:largestCity=capital。所以我用了:
FILTER (dbp:largestcity="capital")
但是 Viruoso 验证器向我发送了超过执行时间的异常。
有什么建议吗?
我不确定您希望过滤器执行什么操作。在 FILTER (dbp:largestcity="capital") 中,"capital" 是一个字符串,而 dbp:largestcity (这是not 与 dbp:largestCity 相同)是 IRI;他们永远不会平等。
现在,我 do 看到有时 dbp:largestCity 的值是 string "capital"@en,所以有一些字符串匹配可能会有帮助。不过,一般来说,DBpedia ontology 属性的数据比原始信息框属性要干净得多,所以如果可以的话,你应该更喜欢 dbo: 属性。在这里,我猜你会想要两者。
您需要查询来提取首都以及最大的城市,然后您想要过滤它们相等的情况,或者最大城市是字符串 "capital".
SELECT DISTINCT ?country ?capital WHERE {
?country a dbo:Country .
?country a <http://dbpedia.org/class/yago/SouthAmericanCountries>.
?country dbo:capital ?capital .
?country dbp:largestCity|dbo:largestCity ?largestCity .
filter (?largestCity = ?capital || str(?largestCity)= "capital")
}
我需要检索首都也是最大城市的南美洲国家列表。出于某种原因,我可以显示所有南美国家及其首都,但我无法使用过滤器选项将首都与最大城市进行比较:
SELECT DISTINCT ?country ?capital
WHERE {
?country a dbo:Country .
?country a <http://dbpedia.org/class/yago/SouthAmericanCountries>.
?country dbp:largestCity|dbo:largestCity ?capital.
}
对于第三个三元组,我使用了 2 个参数,因为并非所有国家/地区都有完整的数据。在 dbpedia 验证器上 运行 之后,我得到了这个: http://dbpedia.org/sparql?default-graph-uri=http%3A%2F%2Fdbpedia.org&query=SELECT+DISTINCT+%3Fcountry+%3Fcapital%0D%0AWHERE+%7B%0D%0A%0D%0A++++%3Fcountry+a+dbo%3ACountry+.%0D%0A++++%3Fcountry+a+%3Chttp%3A%2F%2Fdbpedia.org%2Fclass%2Fyago%2FSouthAmericanCountries%3E.%0D%0A++++%0D%0A++++%3Fcountry+dbp%3AlargestCity%7Cdbo%3AlargestCity+%3Fcapital.%0D%0A%0D%0A++++%0D%0A%0D%0A%7D&format=text%2Fhtml&CXML_redir_for_subjs=121&CXML_redir_for_hrefs=&timeout=30000&debug=on
下一步是使用以下逻辑过滤国家:largestCity=capital。所以我用了:
FILTER (dbp:largestcity="capital")
但是 Viruoso 验证器向我发送了超过执行时间的异常。 有什么建议吗?
我不确定您希望过滤器执行什么操作。在 FILTER (dbp:largestcity="capital") 中,"capital" 是一个字符串,而 dbp:largestcity (这是not 与 dbp:largestCity 相同)是 IRI;他们永远不会平等。
现在,我 do 看到有时 dbp:largestCity 的值是 string "capital"@en,所以有一些字符串匹配可能会有帮助。不过,一般来说,DBpedia ontology 属性的数据比原始信息框属性要干净得多,所以如果可以的话,你应该更喜欢 dbo: 属性。在这里,我猜你会想要两者。
您需要查询来提取首都以及最大的城市,然后您想要过滤它们相等的情况,或者最大城市是字符串 "capital".
SELECT DISTINCT ?country ?capital WHERE {
?country a dbo:Country .
?country a <http://dbpedia.org/class/yago/SouthAmericanCountries>.
?country dbo:capital ?capital .
?country dbp:largestCity|dbo:largestCity ?largestCity .
filter (?largestCity = ?capital || str(?largestCity)= "capital")
}