Difference between revisions of "MatVoc:SPARQL"
Jump to navigation
Jump to search
(4 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
− | + | 語彙はSPARQLでクエリできます。 MatVoc can be queried by SPARQL. | |
+ | |||
+ | :<big>'''[{{SERVER}}/query MatVoc Query Service]'''</big> | ||
+ | |||
+ | なお本サービスは[https://www.wikidata.org/ Wikidata]のソフトウェアを利用した試験的な公開であり、クエリサービス内においてWikidataへの言及が残っているところがありますが、本サービスとWikidataの間にそれ以外の関係があるものではありません。 | ||
== Examples == | == Examples == | ||
+ | === 英日両方のラベルが存在する物質タイプ === | ||
{{SPARQL | query = # Sample query: Narrower concepts of `material types` where both enlabel and jalabel exist | {{SPARQL | query = # Sample query: Narrower concepts of `material types` where both enlabel and jalabel exist | ||
SELECT ?item ?enlabel ?jalabel | SELECT ?item ?enlabel ?jalabel | ||
Line 12: | Line 17: | ||
}} | }} | ||
− | == | + | === 別名一覧をタブ区切りで返す === |
− | + | skos:altLabel が存在する項目について、日・英の rdfs:label と、すべての skos:altLabel をタブ区切りにして返す。 | |
− | {{SPARQL | query = | + | {{SPARQL | query = |
− | SELECT ? | + | SELECT ?synonyms |
WHERE { | WHERE { | ||
− | + | { | |
− | + | SELECT ?item (GROUP_CONCAT (DISTINCT ?label ; separator = "\t") AS ?labels) | |
− | + | WHERE { | |
− | + | ?item rdfs:label ?label . | |
− | + | } | |
− | + | GROUP BY ?item | |
− | + | } | |
− | + | { | |
− | + | SELECT ?item (GROUP_CONCAT (DISTINCT ?altLabel ; separator = "\t") AS ?altLabels) | |
− | + | WHERE { | |
− | + | ?item skos:altLabel ?altLabel. | |
− | ? | + | } |
− | + | GROUP BY ?item | |
− | + | } | |
− | + | BIND(CONCAT(?labels,"\t",?altLabels) as ?synonyms). | |
+ | } | ||
+ | |||
+ | }} | ||
+ | |||
+ | === 英日どちらかのラベルが欠けている項目 === | ||
+ | |||
+ | {{SPARQL | query = | ||
+ | # only one of enlabel or jalabel exists | ||
+ | SELECT ?item ?enlabel ?jalabel | ||
+ | WHERE | ||
+ | { | ||
+ | { | ||
+ | ?item rdfs:label ?jalabel FILTER (LANG(?jalabel) = "ja") . | ||
+ | FILTER(NOT EXISTS {?item rdfs:label ?enlabel FILTER(LANG(?enlabel) = "en") } ) | ||
+ | } | ||
+ | UNION | ||
+ | { | ||
+ | ?item rdfs:label ?enlabel FILTER (LANG(?enlabel) = "en") . | ||
+ | FILTER(NOT EXISTS {?item rdfs:label ?jalabel FILTER(LANG(?jalabel) = "ja") } ) | ||
+ | } | ||
+ | } | ||
+ | ORDER BY ?item | ||
+ | }} | ||
+ | |||
+ | === 文がひとつもない項目 Items without any statements === | ||
+ | {{SPARQL | query = | ||
+ | SELECT * | ||
+ | WHERE { | ||
+ | ?item wikibase:statements 0 . | ||
+ | } | ||
+ | }} | ||
+ | |||
+ | === 辞書ごとの項目数集計 === | ||
+ | {{SPARQL | query = | ||
+ | SELECT * WHERE { | ||
+ | VALUES ?top { wd:Q21 wd:Q713 wd:Q1883 } | ||
+ | ?top rdfs:label ?label . | ||
+ | FILTER (LANG(?label)="ja") | ||
+ | { | ||
+ | SELECT ?top (COUNT(?child) AS ?childcount) WHERE { | ||
+ | ?child wdt:P8+ ?top . | ||
+ | } GROUP BY ?top | ||
+ | } | ||
+ | } ORDER BY DESC(?childcount) | ||
+ | }} | ||
− | + | === グラフ表示 === | |
− | + | {{SPARQL | query = | |
− | + | #defaultView:Graph | |
− | + | SELECT ?categ ?categLabel ?item ?itemLabel WHERE { | |
− | + | ?categ wdt:P8 wd:Q21 . | |
− | + | ?item wdt:P8 ?categ . | |
− | + | SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . } | |
− | |||
− | |||
} | } | ||
− | |||
}} | }} |
Latest revision as of 08:49, 18 January 2023
語彙はSPARQLでクエリできます。 MatVoc can be queried by SPARQL.
なお本サービスはWikidataのソフトウェアを利用した試験的な公開であり、クエリサービス内においてWikidataへの言及が残っているところがありますが、本サービスとWikidataの間にそれ以外の関係があるものではありません。
Examples
英日両方のラベルが存在する物質タイプ
# Sample query: Narrower concepts of `material types` where both enlabel and jalabel exist
SELECT ?item ?enlabel ?jalabel
WHERE {
?item wdt:P8 wd:Q26.
?item rdfs:label ?enlabel FILTER (LANG(?enlabel) = "en") .
?item rdfs:label ?jalabel FILTER (LANG(?jalabel) = "ja") .
}
ORDER BY ?enlabel
別名一覧をタブ区切りで返す
skos:altLabel が存在する項目について、日・英の rdfs:label と、すべての skos:altLabel をタブ区切りにして返す。
SELECT ?synonyms
WHERE {
{
SELECT ?item (GROUP_CONCAT (DISTINCT ?label ; separator = "\t") AS ?labels)
WHERE {
?item rdfs:label ?label .
}
GROUP BY ?item
}
{
SELECT ?item (GROUP_CONCAT (DISTINCT ?altLabel ; separator = "\t") AS ?altLabels)
WHERE {
?item skos:altLabel ?altLabel.
}
GROUP BY ?item
}
BIND(CONCAT(?labels,"\t",?altLabels) as ?synonyms).
}
英日どちらかのラベルが欠けている項目
# only one of enlabel or jalabel exists
SELECT ?item ?enlabel ?jalabel
WHERE
{
{
?item rdfs:label ?jalabel FILTER (LANG(?jalabel) = "ja") .
FILTER(NOT EXISTS {?item rdfs:label ?enlabel FILTER(LANG(?enlabel) = "en") } )
}
UNION
{
?item rdfs:label ?enlabel FILTER (LANG(?enlabel) = "en") .
FILTER(NOT EXISTS {?item rdfs:label ?jalabel FILTER(LANG(?jalabel) = "ja") } )
}
}
ORDER BY ?item
文がひとつもない項目 Items without any statements
SELECT *
WHERE {
?item wikibase:statements 0 .
}
辞書ごとの項目数集計
SELECT * WHERE {
VALUES ?top { wd:Q21 wd:Q713 wd:Q1883 }
?top rdfs:label ?label .
FILTER (LANG(?label)="ja")
{
SELECT ?top (COUNT(?child) AS ?childcount) WHERE {
?child wdt:P8+ ?top .
} GROUP BY ?top
}
} ORDER BY DESC(?childcount)
グラフ表示
#defaultView:Graph
SELECT ?categ ?categLabel ?item ?itemLabel WHERE {
?categ wdt:P8 wd:Q21 .
?item wdt:P8 ?categ .
SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . }
}