我知道如何获得指定电影的费用:
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT ?item (GROUP_CONCAT( ?_cost; SEPARATOR = "~~~") AS ?budget)
WHERE {
VALUES ?selectedMovies { wd:Q24515019 wd:Q20762698 }
?item wdt:P31/wdt:P279* wd:Q11424 filter (?item = ?selectedMovies).
OPTIONAL {
?item wdt:P2130 ?_cost.
}
}
GROUP BY ?item
但是当我试图获得成本的货币时,我什么也得不到:
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT ?item (GROUP_CONCAT( ?_cost; SEPARATOR = "~~~") AS ?budget)
(GROUP_CONCAT( ?_currency; SEPARATOR = "~~~") AS ?_currency)
WHERE {
VALUES ?selectedMovies { wd:Q24515019 wd:Q20762698 }
?item wdt:P31/wdt:P279* wd:Q11424 filter (?item = ?selectedMovies).
OPTIONAL {
?item wdt:P2130 ?_cost.
?_cost wdt:P2237 ?_currency.
}
}
GROUP BY ?item
我在这些电影的页面上查看了成本货币。
那么,我该如何获得货币?
答案 0 :(得分:4)
嗯,当你要求单位的属性时,它会有点复杂:
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT ?item (GROUP_CONCAT( DISTINCT ?cost_with_unit; SEPARATOR = "~~~") AS ?budget)
WHERE {
VALUES ?selectedMovies { wd:Q24515019 wd:Q20762698 }
?item wdt:P31/wdt:P279* wd:Q11424 filter (?item = ?selectedMovies).
OPTIONAL {
?item wdt:P2130 ?_cost.
# get the node to the cost statement
?item p:P2130 ?stmnode.
# then its value node
?stmnode psv:P2130 ?valuenode.
# then its unit, i.e. currency as entity
?valuenode wikibase:quantityUnit ?unit.
# then finally, its label
?unit rdfs:label ?unitLabel.
FILTER(LANGMATCHES(LANG(?unitLabel), 'en'))
# put everything together
BIND(CONCAT(str(?_cost), " ", str(?unitLabel)) as ?cost_with_unit)
}
}
GROUP BY ?item
要获取本机的ISO 4217代码,请替换
# then finally, its label
?unit rdfs:label ?unitLabel.
FILTER(LANGMATCHES(LANG(?unitLabel), 'en'))
与
# then finally, the ISO 4217 code of the unit, e.g. USD
?unit wdt:P498 ?unitLabel .