SPARQL/維基百科共享資源查詢服務
外觀
< SPARQL
維基百科共享資源的影像也使用結構化資料,請參閱 Commons 上的結構化資料 (SDoC) 。使用維基百科共享資源查詢服務 (WCQS),可以查詢這些資料。該服務於 2022 年 1 月 2 日在 https://commons-query.wikimedia.org/ 上推出。之前在 https://wcqs-beta.wmflabs.org/ 上以測試版形式提供。
以下是作為影像網格顯示的 Douglas Adams 肖像示例。
#Show images of Douglas Adams in an image grid
#defaultView:ImageGrid
SELECT ?file ?image WHERE {
?file wdt:P180 wd:Q42 .
?file schema:url ?image.
}
注意:在 sdc = Commons 上的結構化資料中使用 |project=sdc,預設值為 |project=wd 用於 Wikidata。
在 WCQS 本身檢視更多示例。
下面的查詢顯示了影像的所有屬性
# all properties of an image
SELECT DISTINCT ?file ?predicate ?pLabel ?o ?oLabel
WHERE {
VALUES ?file { sdc:M107651852 } # an example image
{ ?file ?predicate ?o.
BIND( IRI(REPLACE( STR(?predicate),"prop/direct/","entity/" )) AS ?p).
}
UNION
{ ?file ?predicate1 [ ?predicate ?o ]. # qualifiers
BIND( IRI((REPLACE( REPLACE( STR(?predicate), "(direct/|statement/|value/|value-normalized/|qualifier/|reference/)", ""),"prop/","entity/"))) AS ?p).
}
FILTER( CONTAINS( STR(?predicate), "/prop/direct/") || CONTAINS( STR(?predicate), "/prop/qualifier/") || CONTAINS( STR(?predicate), "/prop/reference/")
|| CONTAINS( STR(?predicate), "schema.org") || CONTAINS( STR(?predicate), "w3.org") )
SERVICE <https://query.wikidata.org/sparql> {
SERVICE wikibase:label {
bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
?p rdfs:label ?pLabel .
?o rdfs:label ?oLabel .
}
}
}
LIMIT 100
這揭示了一些隱藏的語句,例如:修改日期 / 寬度 / 高度 / 內容大小(位元組)。以下查詢提供了一個如何使用它的示例。
# show hidden statements
SELECT ?file ?instance_of ?instance_ofLabel ?inception_date ?dateModified ?width ?height ?contentSize
WHERE {
VALUES ?file { sdc:M107651852 } # an example image
OPTIONAL{ ?file wdt:P31 ?instance_of. }
OPTIONAL{ ?file wdt:P571 ?inception_date. }
OPTIONAL{ ?file schema:dateModified ?dateModified. }
OPTIONAL{ ?file schema:width ?width. }
OPTIONAL{ ?file schema:height ?height. }
OPTIONAL{ ?file schema:contentSize ?contentSize. }
SERVICE <https://query.wikidata.org/sparql> {
SERVICE wikibase:label {
bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
?instance_of rdfs:label ?instance_ofLabel .
}
}
}
此示例結合了 SERVICE - mwapi,展示了 Commons 中一個類別中檔案的荷蘭語標籤描述語句
SELECT ?file ?title ?depicts ?depicts_label
WITH
{ SELECT ?file ?title
WHERE
{ SERVICE wikibase:mwapi
{
bd:serviceParam wikibase:api "Generator" .
bd:serviceParam wikibase:endpoint "commons.wikimedia.org" .
bd:serviceParam mwapi:gcmtitle "Category:Historia Naturalis van Rudolf II" .
bd:serviceParam mwapi:generator "categorymembers" .
bd:serviceParam mwapi:gcmtype "file" .
bd:serviceParam mwapi:gcmlimit "max" .
?title wikibase:apiOutput mwapi:title .
?pageid wikibase:apiOutput "@pageid" .
}
BIND (URI(CONCAT('https://commons.wikimedia.org/entity/M', ?pageid)) AS ?file)
}
} AS %get_files
WHERE
{ INCLUDE %get_files
?file wdt:P180 ?depicts .
service <https://query.wikidata.org/sparql> {
OPTIONAL {?depicts rdfs:label ?depicts_label FILTER (lang(?depicts_label) = 'nl') }
}
}
- WCQSbeta2-release-notes,釋出日期為 2022 年 1 月 2 日
- Commons-l 關於 WCQS 的公告,釋出日期為 2020 年 7 月 22 日