Difference between revisions of "MatVoc:SPARQL"

From matvoc.nims.go.jp
Jump to navigation Jump to search
 
(4 intermediate revisions by 3 users not shown)
Line 1: Line 1:
This vocabulary can be queried by SPARQL at [{{SERVER}}/query the query service].  
+
語彙は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:
 
}}
 
}}
  
== Implemented in the batch system ==
+
=== 別名一覧をタブ区切りで返す ===
  
=== Query 01: 語彙定義 ===
+
skos:altLabel が存在する項目について、日・英の rdfs:label と、すべての skos:altLabel をタブ区切りにして返す。
{{SPARQL | query = # DPFC vocabulary delivery query 01 version 2019-08-21
+
{{SPARQL | query =  
SELECT ?linetype ?itemid ?dictid ?item ?enlabel ?jalabel ?datemodified
+
SELECT ?synonyms
 
WHERE {
 
WHERE {
   VALUES ?urlbase  {"http://voctest.nims.go.jp/entity/"}
+
   {
   VALUES ?linetype {"01"}
+
    SELECT ?item (GROUP_CONCAT (DISTINCT ?label ; separator = "\t") AS ?labels)
    
+
    WHERE {
   # Labels
+
      ?item rdfs:label ?label .
   OPTIONAL {?item rdfs:label ?enlabel FILTER (LANG(?enlabel) = "en") .}
+
    }
  OPTIONAL {?item rdfs:label ?jalabel FILTER (LANG(?jalabel) = "ja") .}
+
    GROUP BY ?item
    
+
  }
  # Belongs to which dictionary
+
  {
   OPTIONAL {?item wdt:P11 ?dict.}
+
    SELECT ?item (GROUP_CONCAT (DISTINCT ?altLabel ; separator = "\t") AS ?altLabels)
 
+
    WHERE {
   # Last modified timestamp
+
      ?item skos:altLabel ?altLabel.
   ?item schema:dateModified ?datemodified .
+
    }
    
+
    GROUP BY ?item
   # Exclude properties
+
  }
  FILTER NOT EXISTS {?item rdf:type <http://wikiba.se/ontology#Property>}
+
  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)
 +
}}
  
  # Post-process
+
=== グラフ表示 ===
  BIND (STRAFTER (STR(?item), ?urlbase) AS ?itemid)
+
{{SPARQL | query =
  BIND (STRAFTER (STR(?dict), ?urlbase) AS ?dictid) 
+
#defaultView:Graph
 
+
SELECT ?categ ?categLabel ?item ?itemLabel WHERE {
   # Fallback to preset string if no dictionary is defined?
+
   ?categ wdt:P8 wd:Q21 .
   # BIND (IF (BOUND(?dict), STRAFTER (STR(?dict), ?urlbase), "common") AS ?dictid)
+
   ?item wdt:P8 ?categ .
 
+
   SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . }
  # Wikibase Label Service not used for now
 
   # SERVICE wikibase:label { bd:serviceParam wikibase:language "en,ja" . }
 
 
}
 
}
ORDER BY ?itemid
 
 
}}
 
}}

Latest revision as of 08:49, 18 January 2023

語彙はSPARQLでクエリできます。 MatVoc can be queried by SPARQL.

MatVoc Query Service

なお本サービスは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

▶️ Try it!

別名一覧をタブ区切りで返す

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).
}

▶️ Try it!

英日どちらかのラベルが欠けている項目

# 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

▶️ Try it!

文がひとつもない項目 Items without any statements

SELECT * 
WHERE { 
  ?item wikibase:statements 0 .
}

▶️ Try it!

辞書ごとの項目数集計

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)

▶️ Try it!

グラフ表示

#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" . }
}

▶️ Try it!