如何在维基数据SPARQL中获取电影成本货币?
How to get film cost currency in Wikidata SPARQL?
我知道如何获取指定影片的成本:
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
我查了下,在这些电影的页面上,有cost currency。
那么,我怎样才能获得货币呢?
好吧,当你要求单位的属性时,它有点复杂:
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 .
我知道如何获取指定影片的成本:
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
我查了下,在这些电影的页面上,有cost currency。
那么,我怎样才能获得货币呢?
好吧,当你要求单位的属性时,它有点复杂:
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 .