Help

Difference between revisions of "SPARQL"

Help:SPARQL gathers a list of SPARQL queries in the context of Lingua Libre, ready to use, alongside with beginner-friendly inline-comments, introductions to concepts, code snippets and a few tools. To dive into it, first check the content's structure visible in the outline. This page allows users not familiar with SPARQL to easily query the LinguaLibre knowledge graph, and to download or directly feed that data into an application. To fit with most frequent uses, the page focuses towards web development.

 
(159 intermediate revisions by 6 users not shown)
Line 1: Line 1:
{{#Subtitle:'''Help:SPARQL''' gather a list of basic SPARQL queries in the context of Lingua Libre, demoed and ready to test, together with beginners-friendly knowledges, inline-comments, introductions to concepts, code snippets and few tools. This page allows users not familiar with SPARQL to rapidly learn the basics of SPARQL, query the LinguaLibre database, and to download or directly feed that data to an application. To fit the with most frequent usages, the case of a web developper with basic Javascripts skill is taken.}}
+
{{#Subtitle:'''Help:SPARQL''' gathers a list of SPARQL queries in the context of Lingua Libre, ready to use, alongside with beginner-friendly inline-comments, introductions to concepts, code snippets and a few tools. To dive into it, first check the content's structure visible in the outline. This page allows users not familiar with SPARQL to easily query the LinguaLibre knowledge graph, and to download or directly feed that data into an application. To fit with most frequent uses, the page focuses towards web development.}}
[[Category:?]]
 
  
{{Draft|2021/12/10 : Work in progress. Please do not translate yet as some aspects stay to polish. You may help by: reading/fixing the page, testing queries [https://lingualibre.org/bigdata/#query here], replacing Q21 (French) by a smaller non-western language, harmonising in-line comments, adding the right category. --[[User:Yug|Yug]]}}
+
{{Draft|December 2021 rewriting : '''work in progress, '''please do not translate yet'''.
== Base ==  
+
<div style{{=}}"text-align:left;">
* [{{SERVER}}/bigdata/#query <span class="mw-ui-button mw-ui-progressive" role="button" aria-disabled="false">Endpoint</span>] – paste the SPARQL queries there to run, test them, and download the data as json, csv or tsv.
+
# '''NOW/Opened:''' General content review. You may help by: a) reading and copy-editing the page's English, b) testing queries on [https://lingualibre.org/bigdata/#query LLQS], edit in or [[Help talk:SPARQL|discuss improvements]], <s>3) increase comments' concistency</s>.
 +
# Legend: 🇶 minor aspects to improve, see hidden comment ; ❌ query too heavy to run in this page.
 +
# '''Later/not yet:''' translations.
 +
<!-- # '''Later:''' Improve Base section with core SPARQL concepts ? -->
 +
Help welcome.
 +
</div>
 +
}}
 +
 
 +
== Base ==
 +
=== Useful elements ===
 +
{| style="width:100%"
 +
|- style="vertical-align:top;"
 +
|style="padding: auto 3em auto auto;width:60%"|
 
* [[Special:ListProperties]] – exhaustive list of LinguaLibre's Wikibase properties.
 
* [[Special:ListProperties]] – exhaustive list of LinguaLibre's Wikibase properties.
 
* [[LinguaLibre:List of languages]] – exhaustive list of LinguaLibre's languages
 
* [[LinguaLibre:List of languages]] – exhaustive list of LinguaLibre's languages
* [[DataViz:Speakers]]
+
||
* [[DataViz:Records]]
+
<query _pagination="4" >
 +
#All properties with descriptions and aliases and types
 +
SELECT ?property ?propertyLabel ?propertyDescription
 +
# ?propertyType
 +
# ?propertyAltLabel
 +
WHERE {
 +
  ?property wikibase:propertyType ?propertyType .
 +
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
 +
}
 +
ORDER BY ASC(xsd:integer(STRAFTER(STR(?property), 'P')))
 +
</query>
 +
|}
 +
 
 +
=== Tools ===
 +
[[File:Wikidata_Query_-_Query_Helper_-_Build_query_from_scratch.webm|thumb|450px|On Wikidata, the WDQS allows to practice SPARQL queries creation in an intuitive way.]]
 +
* [{{SERVER}}/bigdata/#query <span class="mw-ui-button mw-ui-progressive" role="button" aria-disabled="false">Endpoint LinguaLibre</span>] [{{SERVER}}/bigdata/#query LinguaLibre Query Service (LLQS)] – run SPARQL Queries upon LinguaLibre. Run, test, download the data as json, csv or tsv.
 +
* [https://query.wikidata.org <span class="mw-ui-button mw-ui-progressive" role="button" aria-disabled="false">Endpoint Wikidata</span>] [https://query.wikidata.org Wikidata Query Service (WDQS)] – run SPARQL Queries upon Wikidata. Run, test, download the data as json, csv or tsv. Has advanced user-friendly features such as : word hovering too see a term's meaning, code optimization, etc.
 +
* [https://commons-query.wikimedia.org <span class="mw-ui-button mw-ui-progressive" role="button" aria-disabled="false">Endpoint Wikimedia Commons</span>] [https://commons-query.wikimedia.org Wikimedia Commons Query Service (WCQS)] run SPARQL Queries upon Wikimedia Commons wikibase (need to log in).
 +
* [https://sinaahmadi.github.io/posts/sparql-query-generator-for-lexicographical-data.html Wikidata Lexeme Queries generators] ([https://jsfiddle.net/hugolpz/rygo9s5b/ hack me]) by @sina_ahm – helps to create queries for Wikidata's Lexeme.
 +
* [[Special:ApiSandbox]] – API queries generator for Lingualibre wikipage and wikibase contents. An alternative to SPARQL queries.
 +
 
 +
=== References ===
 +
* [https://www.w3.org/TR/sparql11-query/ SPARQL 1.1 Query Language]
 +
* [https://www.iro.umontreal.ca/~lapalme/ift6281/sparql-1_1-cheat-sheet.pdf SPARQL Cheatsheet]
  
 
== Code snippets ==
 
== Code snippets ==
Line 17: Line 51:
  
 
'''Javascript:'''<br>
 
'''Javascript:'''<br>
At least 3 methods exists ([https://jsfiddle.net/hugolpz/tsg9ewa7/4/ code snippet]), example:  
+
At least 3 methods exists ([https://jsfiddle.net/hugolpz/tsg9ewa7/ code snippet]), example:  
 
{| style="width:100%"  
 
{| style="width:100%"  
 
|-
 
|-
Line 60: Line 94:
 
// Data from 3 sparql queries.
 
// Data from 3 sparql queries.
 
// Important: One key must be similar in all datasets, here: 'qid'
 
// Important: One key must be similar in all datasets, here: 'qid'
const langs = [{ qid: 'Q209', label: 'Breton', iso:'bre' }, { qid: 'Q21', label: 'French', iso: 'fra' }],
+
const langs = [{ qid: 'Q209', label: 'Breton', iso:'bre' }, { qid: 'Q34', label: 'Marathi', iso: 'mar' }],
     speakersFemales = [{ qid: 'Q209', genderF: 3, recordsF: 60 }, { qid: 'Q21', genderF: 21, recordsF:15046 }],
+
     speakersFemales = [{ qid: 'Q209', genderF: 3, recordsF: 60 }, { qid: 'Q34', genderF: 21, recordsF:5046 }],
     speakersMales = [{ qid: 'Q209', genderM: 7, recordsM: 112 }, { qid: 'Q21', genderM: 85, recordsM:82964 }];
+
     speakersMales = [{ qid: 'Q209', genderM: 7, recordsM: 218 }, { qid: 'Q34', genderM: 85, recordsM:32964 }];
 
// Toolbox for merging data by same id
 
// Toolbox for merging data by same id
 
var merge2ArraysBySameId = function(arr1,arr2,id1){
 
var merge2ArraysBySameId = function(arr1,arr2,id1){
Line 77: Line 111:
  
 
== Lingualibre's ground ==
 
== Lingualibre's ground ==
=== Is Language ([[Q4]]) → List existing languages ===
+
=== Is Language ([[d:Q34770]]) → List existing languages with: LL Qid, ISO 639-3, Name ===
 +
''This query has been UPDATED to work on Commons SPARQL Endpoint.''
 
{| style="width:100%"  
 
{| style="width:100%"  
 
|- style="vertical-align:top;"
 
|- style="vertical-align:top;"
 
|style="padding: 0 3em;width:60%"|
 
|style="padding: 0 3em;width:60%"|
 
<syntaxhighlight lang="sparql">
 
<syntaxhighlight lang="sparql">
SELECT ?lang ?iso ?langLabel WHERE {
+
#defaultEndpoint:Commons
   ?lang prop:P2 entity:Q4 .
+
SELECT ?lang ?iso ?langLabel
   ?lang prop:P13 ?iso .
+
WHERE {
 +
   # First get the relevant languages by first looking up all records
 +
  {
 +
    SELECT DISTINCT ?lang WHERE {
 +
      _:record wdt:P31 wd:Q108167708 ; # Filter to get wd:Q108167708 (pronunciation file)
 +
              wdt:P407 ?lang .       # For each pronunciation file, fetch the language
 +
    }
 +
  }
 +
 
 +
   # From this point on, ?lang is bound. Get the label and ISO code on Wikidata
 +
  SERVICE <https://query.wikidata.org/sparql> {
 +
    ?lang wdt:P31 wd:Q34770 .  # Filter: P31 'instance of' is Q1193409 'language or dialect'.
 +
    ?lang wdt:P220 ?iso .     # Assign value: P220 'ISO-639-3' into ?iso.
 +
  }
 +
 
 
   SERVICE wikibase:label {
 
   SERVICE wikibase:label {
 +
    # Add label to each variable used.
 +
    # ?lang now has twin variable ?langLabel
 
     bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
 
     bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
 
   }  
 
   }  
Line 92: Line 143:
 
||
 
||
 
<query _pagination="5" >
 
<query _pagination="5" >
SELECT ?lang ?iso ?langLabel WHERE {
+
#defaultEndpoint:Commons
   ?lang prop:P2 entity:Q4 .
+
SELECT ?lang ?iso ?langLabel
   ?lang prop:P13 ?iso .
+
WHERE {
 +
   # First get the relevant languages by first looking up all records
 +
  {
 +
    SELECT DISTINCT ?lang WHERE {
 +
      _:record wdt:P31 wd:Q108167708 ; # Filter to get wd:Q108167708 (pronunciation file)
 +
              wdt:P407 ?lang .       # For each pronunciation file, fetch the language
 +
    }
 +
  }
 +
 
 +
   # From this point on, ?lang is bound. Get the label and ISO code on Wikidata
 +
  SERVICE <https://query.wikidata.org/sparql> {
 +
    ?lang wdt:P31 wd:Q34770 .  # Filter: P31 'instance of' is Q1193409 'language or dialect'.
 +
    ?lang wdt:P220 ?iso .     # Assign value: P220 'ISO-639-3' into ?iso.
 +
  }
 +
 
 
   SERVICE wikibase:label {
 
   SERVICE wikibase:label {
 +
    # Add label to each variable used.
 +
    # ?lang now has twin variable ?langLabel
 
     bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
 
     bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
 
   }  
 
   }  
Line 102: Line 169:
 
|}
 
|}
  
=== ✅🇶 Is Speaker ([[Q3]]) → List existing speakers ===
+
=== Is Speaker ([[Q3]]) → List existing speakers ===
<!-- Q: add grouping per language ?-->
+
''This query is going to be DEPRECATED as the queried data will no longer be available.''
 
{| style="width:100%"  
 
{| style="width:100%"  
 
|- style="vertical-align:top;"
 
|- style="vertical-align:top;"
 
|style="padding: 0 3em;width:60%"|
 
|style="padding: 0 3em;width:60%"|
 
<syntaxhighlight lang="sparql">
 
<syntaxhighlight lang="sparql">
 +
#defaultEndpoint:Lingualibre
 
SELECT ?speaker ?speakerLabel
 
SELECT ?speaker ?speakerLabel
 
WHERE {
 
WHERE {
   ?speaker prop:P2 entity:Q3 .  # Condition 1, P2 'instance of' is Q3 'speaker'.
+
   ?speaker prop:P2 entity:Q3 .  # Filter: P2 'instance of' is Q3 'speaker'.
 +
  # Add labels to each variable used.
 
   SERVICE wikibase:label {
 
   SERVICE wikibase:label {
 
     bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
 
     bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
Line 118: Line 187:
 
||
 
||
 
<query _pagination="5" speaker="Item" speakerLabel="Speaker" langLabel="Language">
 
<query _pagination="5" speaker="Item" speakerLabel="Speaker" langLabel="Language">
 +
#defaultEndpoint:Lingualibre
 
SELECT ?speaker ?speakerLabel
 
SELECT ?speaker ?speakerLabel
WHERE {  
+
WHERE {
   ?speaker prop:P2 entity:Q3 .
+
   ?speaker prop:P2 entity:Q3 .  # Filter: P2 'instance of' is Q3 'speaker'.
 +
  # Add labels to each variable used.
 
   SERVICE wikibase:label {
 
   SERVICE wikibase:label {
 
     bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
 
     bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
Line 128: Line 199:
 
|}
 
|}
  
=== Is Language level ([[Q5]]) → List existing levels ===
+
=== Is Language level ([[Q5]]) → List existing levels ===
 +
''This query is going to be DEPRECATED as the queried data will no longer be available.''
 
{| style="width:100%"  
 
{| style="width:100%"  
 
|- style="vertical-align:top;"
 
|- style="vertical-align:top;"
 
|style="padding: 0 3em;width:60%"|
 
|style="padding: 0 3em;width:60%"|
 
<syntaxhighlight lang="sparql">
 
<syntaxhighlight lang="sparql">
 +
#defaultEndpoint:Lingualibre
 
SELECT ?item ?itemLabel
 
SELECT ?item ?itemLabel
 
WHERE {
 
WHERE {
   ?item prop:P2 entity:Q5    # Condition 1, P2 'instance of' is Q5 'language level'.
+
   ?item prop:P2 entity:Q5    # Filter: P2 'instance of' is Q5 'language level'.
 +
  # Add labels to each variable used.
 
   SERVICE wikibase:label {
 
   SERVICE wikibase:label {
 
     bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
 
     bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
Line 143: Line 217:
 
|
 
|
 
<query _pagination="6" item="Property" itemLabel="Values">
 
<query _pagination="6" item="Property" itemLabel="Values">
 +
#defaultEndpoint:Lingualibre
 
SELECT ?item ?itemLabel
 
SELECT ?item ?itemLabel
 
WHERE {
 
WHERE {
   ?item prop:P2 entity:Q5
+
   ?item prop:P2 entity:Q5   # Filter: P2 'instance of' is Q5 'language level'.
 +
  # Add labels to each variable used.
 
   SERVICE wikibase:label {
 
   SERVICE wikibase:label {
 
     bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
 
     bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
Line 153: Line 229:
 
|}
 
|}
  
=== Is Sex or Gender ([[Q7]]) → List existing sexes or genders ===
+
=== Is Sex or Gender ([[Q7]]) → List existing sexes or genders ===
 +
''This query is going to be DEPRECATED as the queried data will no longer be available.''
 
{| style="width:100%"  
 
{| style="width:100%"  
 
|- style="vertical-align:top;"
 
|- style="vertical-align:top;"
 
|style="padding: 0 3em;width:60%"|
 
|style="padding: 0 3em;width:60%"|
 
<syntaxhighlight lang="sparql">
 
<syntaxhighlight lang="sparql">
 +
#defaultEndpoint:Lingualibre
 
SELECT ?item ?itemLabel
 
SELECT ?item ?itemLabel
 
WHERE {
 
WHERE {
   ?item prop:P2 entity:Q7    # Condition 1, P2 'instance of' is Q7 'sex or gender'.
+
   ?item prop:P2 entity:Q7    # Filter: P2 'instance of' is Q7 'sex or gender'.
 +
  # Add labels to each variable used.
 
   SERVICE wikibase:label {
 
   SERVICE wikibase:label {
 
     bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
 
     bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
Line 168: Line 247:
 
|
 
|
 
<query _pagination="6" item="Property" itemLabel="Values">
 
<query _pagination="6" item="Property" itemLabel="Values">
 +
#defaultEndpoint:Lingualibre
 
SELECT ?item ?itemLabel
 
SELECT ?item ?itemLabel
 
WHERE {
 
WHERE {
   ?item prop:P2 entity:Q7
+
   ?item prop:P2 entity:Q7   # Filter: P2 'instance of' is Q7 'sex or gender'.
 +
  # Add labels to each variable used.
 
   SERVICE wikibase:label {
 
   SERVICE wikibase:label {
 
     bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
 
     bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
Line 179: Line 260:
  
 
== Speaker ==
 
== Speaker ==
=== Speaker name(s) → Speaker Qid(s) ===
+
=== 🇶 Speaker name(s) → Speaker Qid(s) ===
 
+
''This query is going to be DEPRECATED as the queried data will no longer be available.''
 +
<!-- REVIEW REQUIRED -->
 
{| style="width:100%"  
 
{| style="width:100%"  
 
|- style="vertical-align:top;"
 
|- style="vertical-align:top;"
 
|style="padding: 0 3em;width:60%"|
 
|style="padding: 0 3em;width:60%"|
 
<syntaxhighlight lang="sparql">
 
<syntaxhighlight lang="sparql">
 +
#defaultEndpoint:Lingualibre
 
SELECT ?speakerName ?speakerId
 
SELECT ?speakerName ?speakerId
 
WHERE {
 
WHERE {
   VALUES ?speakerName { "Yug" "VIGNERON" } # One or multiple values
+
   VALUES ?speakerName { "Yug" "VIGNERON" } # Assign value: one or multiple values
 +
  # note: need to comment BIND
 
   BIND ( STRLANG(?speakerName, "en") AS ?speakerLabel )
 
   BIND ( STRLANG(?speakerName, "en") AS ?speakerLabel )
   # P2: instance of; Q3: speaker.
+
   # Grammatical note: ';' allows to chain actions
   ?speakerId prop:P2 entity:Q3 ; rdfs:label ?speakerLabel .
+
   ?speakerId prop:P2 entity:Q3 ;       # Filter: P2 'instance of' is Q3 'speaker'.
 +
            rdfs:label ?speakerLabel . # Filter by value: label equal ?speakerLabel's value
 
}  
 
}  
 
</syntaxhighlight>
 
</syntaxhighlight>
Line 196: Line 281:
  
 
<query _pagination="5">
 
<query _pagination="5">
 +
#defaultEndpoint:Lingualibre
 
SELECT ?speakerName ?speakerId
 
SELECT ?speakerName ?speakerId
 
WHERE {
 
WHERE {
   VALUES ?speakerName { "Yug" "VIGNERON" } # One or multiple values
+
   VALUES ?speakerName { "Yug" "VIGNERON" }
 
   BIND ( STRLANG(?speakerName, "en") AS ?speakerLabel )
 
   BIND ( STRLANG(?speakerName, "en") AS ?speakerLabel )
  # P2: instance of; Q3: speaker.
+
   ?speakerId prop:P2 entity:Q3 ;
   ?speakerId prop:P2 entity:Q3 ; rdfs:label ?speakerLabel .
+
            rdfs:label ?speakerLabel .
 
}  
 
}  
 
</query>
 
</query>
 
|}
 
|}
  
=== ✅🇶 Speaker Qid ([[Q42]]) → Speaker data, all ===
+
=== 🇶 Speaker Qid ([[Q445757]]) → Speaker data, all ===
 +
''This query is going to be DEPRECATED as the queried data will no longer be available.''
 
<!-- Q: alternative words for "predicate" and "object". "property" and "value" ?-->
 
<!-- Q: alternative words for "predicate" and "object". "property" and "value" ?-->
 
{| style="width:100%"  
 
{| style="width:100%"  
Line 212: Line 299:
 
|style="padding: 0 3em;width:60%"|
 
|style="padding: 0 3em;width:60%"|
 
<syntaxhighlight lang="sparql">
 
<syntaxhighlight lang="sparql">
# Get Q42 (User:0x010C)'s data
+
#defaultEndpoint:Lingualibre
SELECT ?predicate ?object ?objectLabel
+
# Get Q445757 (User:SangeetaRH‎)'s data
 +
SELECT ?anyProperty ?anyValue ?anyValueLabel
 
WHERE {
 
WHERE {
   entity:Q42 ?predicate ?object .
+
   entity:Q445757 ?anyProperty ?anyValue . # Filter: of Q445757 'SangeetaRH‎', get any property and any values
 +
  # Add labels
 
   SERVICE wikibase:label {
 
   SERVICE wikibase:label {
 
     bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
 
     bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
Line 223: Line 312:
 
||
 
||
 
<query _pagination="10" >
 
<query _pagination="10" >
SELECT ?predicate ?object ?objectLabel
+
#defaultEndpoint:Lingualibre
 +
SELECT ?anyProperty ?anyValue ?anyValueLabel
 
WHERE {
 
WHERE {
   entity:Q42 ?predicate ?object .
+
   entity:Q445757 ?anyProperty ?anyValue . # Filter: of Q445757 'SangeetaRH‎', get any property and any values
 +
  # Add labels
 
   SERVICE wikibase:label {
 
   SERVICE wikibase:label {
 
     bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
 
     bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
Line 233: Line 324:
 
|}
 
|}
  
=== ✅🇶  Speaker Qid ([[Q42]]) → Speaker languages ([[Property:P4|P4]]) ===
+
=== 🇶 Speaker Qid ([[Q445757]]) → Speaker languages ([[Property:P4|P4]]) ===
 +
''This query is going to be DEPRECATED as the queried data will no longer be available.''
 
<!-- Q: Add languages iso P:13 -->
 
<!-- Q: Add languages iso P:13 -->
 
{| style="width:100%"  
 
{| style="width:100%"  
Line 239: Line 331:
 
|style="padding: 0 3em;width:60%"|
 
|style="padding: 0 3em;width:60%"|
 
<syntaxhighlight lang="sparql">
 
<syntaxhighlight lang="sparql">
 +
#defaultEndpoint:Lingualibre
 
SELECT ?languages ?languagesLabel
 
SELECT ?languages ?languagesLabel
 
WHERE {
 
WHERE {
   entity:Q42 prop:P4 ?languages .
+
   entity:Q445757 prop:P4 ?languages . # Assign value: for Q445757 'SangeetaRH‎', P4 'language' into ?languages
 +
  # Add labels
 
   SERVICE wikibase:label {
 
   SERVICE wikibase:label {
 
     bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
 
     bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
Line 249: Line 343:
 
||
 
||
 
<query _pagination="5" >
 
<query _pagination="5" >
 +
#defaultEndpoint:Lingualibre
 
SELECT ?languages ?languagesLabel
 
SELECT ?languages ?languagesLabel
 
WHERE {
 
WHERE {
   entity:Q42 prop:P4 ?languages .  
+
   entity:Q445757 prop:P4 ?languages . # Assign value: for Q445757 'SangeetaRH‎', P4 'language' into ?languages
 +
  # Add labels
 
   SERVICE wikibase:label {
 
   SERVICE wikibase:label {
 
     bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
 
     bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
Line 259: Line 355:
 
|}
 
|}
  
=== ✅ Speaker Qid + language Qid → List associated audios ===
+
=== 🇶 Count speaker gender ([[Property:P8|P8]]) ===
 +
 
 +
<!-- Q: Add languages iso P:13 -->
 
{| style="width:100%"  
 
{| style="width:100%"  
 
|- style="vertical-align:top;"
 
|- style="vertical-align:top;"
 
|style="padding: 0 3em;width:60%"|
 
|style="padding: 0 3em;width:60%"|
 
<syntaxhighlight lang="sparql">
 
<syntaxhighlight lang="sparql">
 +
#defaultEndpoint:Lingualibre
 +
SELECT ?genderLabel (count(?speaker) AS ?nb)
 +
WHERE {
 +
  ?speaker prop:P2 entity:Q3 ;
 +
          prop:P8 ?gender .
 +
  SERVICE wikibase:label {
 +
    bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
 +
  }
 +
}
 +
GROUP BY ?genderLabel
 +
</syntaxhighlight>
 +
||
 +
<query _pagination="5" >
 +
#defaultEndpoint:Lingualibre
 +
SELECT ?genderLabel (count(?speaker) AS ?nb)
 +
WHERE {
 +
  ?speaker prop:P2 entity:Q3 ;
 +
          prop:P8 ?gender .
 +
  SERVICE wikibase:label {
 +
    bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
 +
  }
 +
}
 +
GROUP BY ?genderLabel
 +
</query>
 +
|}
 +
 +
=== Speaker Qid (speakers/1 ???) + Language LL Qid ([[d:Q1571]]) → List records ===
 +
''This query is IN WORK for Commons SPARQL Endpoint. One Wikidata property is missing; please update this query with the right property URI.''
 +
{| style="width:100%"
 +
|- style="vertical-align:top;"
 +
|style="padding: 0 3em;width:60%"|
 +
<syntaxhighlight lang="sparql">
 +
#defaultEndpoint:Commons
 
SELECT ?audio ?audioLabel
 
SELECT ?audio ?audioLabel
 
WHERE {
 
WHERE {
   ?audio prop:P5 entity:Q42 .   # Condition 1, P5 Speaker is Q42 User:0x010C
+
   ?audio wdt:SPEAKER_PROPERTY_MISSING <http://lingualibre.org/speakers/1> ; # Filter: ??? 'speaker' P5 Speaker is User:SangeetaRH
  ?audio prop:P4 entity:Q21 .  # Condition 2, P4 language is Q21 French
+
        wdt:P407 wd:Q1571 .  # Filter: P407 'language' is Q1571 'Marathi'
   # Labels
+
 
 +
   # Add labels
 
   SERVICE wikibase:label {
 
   SERVICE wikibase:label {
 
     bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
 
     bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
Line 276: Line 408:
 
||
 
||
 
<query _pagination="5" >
 
<query _pagination="5" >
 +
#defaultEndpoint:Commons
 
SELECT ?audio ?audioLabel
 
SELECT ?audio ?audioLabel
 
WHERE {
 
WHERE {
   ?audio prop:P5 entity:Q42 .  # Condition 1, P5 Speaker is Q42 User:0x010C
+
   ?audio wdt:SPEAKER_PROPERTY_MISSING <http://lingualibre.org/speakers/1> ; # Filter: ??? 'speaker' P5 Speaker is User:SangeetaRH
   ?audio prop:P4 entity:Q21 .  # Condition 2, P4 language is Q21 French
+
        wdt:P407 wd:Q1571 .  # Filter: P407 'language' is Q1571 'Marathi'
   # Labels
+
 
 +
  # Add labels
 +
  SERVICE wikibase:label {
 +
    bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
 +
  }
 +
}
 +
</query>
 +
|}
 +
 
 +
=== Speaker Qid (speakers/1 ???) + Language LL Qid ([[d:Q1571]]) → Count records ===
 +
''This query is IN WORK for Commons SPARQL Endpoint. One Wikidata property is missing; please update this query with the right property URI.''
 +
{| style="width:100%"
 +
|- style="vertical-align:top;"
 +
|style="padding: 0 3em;width:60%"|
 +
<syntaxhighlight lang="sparql">
 +
#defaultEndpoint:Commons
 +
SELECT ?language ?speaker (COUNT(?audio) AS ?audio)
 +
WHERE {
 +
  # Comment out the below pattern to filter by language, e.g. Q1571 or others
 +
  # VALUES ?language { wd:Q1571 }  # Bind value: Q1571 'Marathi' into ?language
 +
  VALUES ?speaker { <http://lingualibre.org/speakers/1> }  # Assign value: ll.org/speakers/1 (for 'SangeetaRH') into ?speaker
 +
 
 +
  ?audio wdt:SPEAKER_PROPERTY_MISSING ?speaker ; # Filter: ??? 'speaker' is ?speaker
 +
        wdt:P407 ?language ;                    # Filter: P407 'language' bound to ?language
 +
        wdt:P31 wd:Q108167708 .                # Filter: P31 'instance of' is Q108167708 'pronunciation file'
 +
}
 +
GROUP BY ?language ?speaker  # Sorting first groups per language and speaker
 +
</syntaxhighlight>
 +
|
 +
<query _pagination="6" item="Property" itemLabel="Values">
 +
#defaultEndpoint:Commons
 +
SELECT ?language ?speaker (COUNT(?audio) AS ?audio)
 +
WHERE {
 +
  # Comment out the below pattern to filter by language.
 +
  # E.g. Q1571 or others
 +
 
 +
  # VALUES ?language { wd:Q1571 }  # Bind value: Q1571 'Marathi' into ?language
 +
  VALUES ?speaker { <http://lingualibre.org/speakers/1> }  # Assign value: ll.org/speakers/1 (for 'SangeetaRH') into ?speaker
 +
 
 +
  ?audio wdt:SPEAKER_PROPERTY_MISSING ?speaker ; # Filter: ??? 'speaker' is ?speaker
 +
        wdt:P407 ?language ;                    # Filter: P407 'language' bound to ?language
 +
        wdt:P31 wd:Q108167708 .                # Filter: P31 'instance of' is Q108167708 'pronunciation file'
 +
}
 +
GROUP BY ?language ?speaker  # Sorting first groups per language and speaker
 +
</query>
 +
|}
 +
 
 +
=== Is Speaker ([[Q3]]) → List of accounts and associated speakers ===
 +
''This query is going to be DEPRECATED as the queried data will no longer be available.''
 +
{| style="width:100%"
 +
|- style="vertical-align:top;"
 +
|style="padding: 0 3em;width:60%"|
 +
<syntaxhighlight lang="sparql">
 +
#defaultEndpoint:Lingualibre
 +
SELECT ?linkedUser ?speakerLabel (SUBSTR(STR(?speaker),32) AS ?speakerQid)
 +
WHERE {
 +
   ?speaker prop:P2 entity:Q3 .  # Filter: P2 'instance of' is Q3 'speaker'.
 +
  ?speaker prop:P11 ?linkedUser . # Assign value: P11 'linked users' into ?linkedUser.
 +
  # Add labels
 +
  SERVICE wikibase:label {
 +
    bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
 +
   }
 +
} ORDER BY DESC (?speakerLabel)
 +
</syntaxhighlight>
 +
|
 +
<query _pagination="6" item="Property" itemLabel="Values">
 +
#defaultEndpoint:Lingualibre
 +
SELECT ?linkedUser ?speakerLabel (SUBSTR(STR(?speaker),32) AS ?speakerQid)
 +
WHERE {
 +
  ?speaker prop:P2 entity:Q3 .  # Filter: P2 'instance of' is Q3 'speaker'.
 +
  ?speaker prop:P11 ?linkedUser . # Assign value: P11 'linked users' into ?linkedUser.
 +
   # Add labels
 
   SERVICE wikibase:label {
 
   SERVICE wikibase:label {
 
     bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
 
     bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
 +
  }
 +
} ORDER BY DESC (?speakerLabel)
 +
</query>
 +
|}
 +
 +
== Languages ==
 +
=== 🇶 LL Language (Q930) → List of words recorded ===
 +
''This query could be run on Wikimedia Commons MediaWiki API. See [[Help:APIs]].''
 +
<!-- Q: Change exact match by CONTAINS() -->
 +
{| style="width:100%"
 +
|- style="vertical-align:top;"
 +
|style="padding: 0 3em;width:60%"|
 +
<syntaxhighlight lang="sparql">
 +
#defaultEndpoint:Wikidata
 +
PREFIX prop: <https://lingualibre.org/prop/direct/>
 +
PREFIX entity: <https://lingualibre.org/entity/>
 +
SELECT ?writing WHERE {
 +
  SERVICE <https://lingualibre.org/sparql> {
 +
    SELECT ?writing WHERE {
 +
      ?record prop:P2 entity:Q2;
 +
        prop:P4 entity:Q930, ?language;
 +
        prop:P3 ?url;
 +
        prop:P7 ?writing.
 +
    # FILTER(CONTAINS(STR(?audio), "LL-Q35735")) # occitan
 +
      SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
 +
    }
 +
  }
 +
}
 +
</syntaxhighlight>
 +
||
 +
<query _pagination="5">
 +
#defaultEndpoint:Wikidata
 +
PREFIX prop: <https://lingualibre.org/prop/direct/>
 +
PREFIX entity: <https://lingualibre.org/entity/>
 +
SELECT ?writing WHERE {
 +
  SERVICE <https://lingualibre.org/sparql> {
 +
    SELECT ?writing WHERE {
 +
      ?record prop:P2 entity:Q2;
 +
        prop:P4 entity:Q930, ?language;
 +
        prop:P3 ?url;
 +
        prop:P7 ?writing.
 +
    # FILTER(CONTAINS(STR(?audio), "LL-Q35735")) # occitan
 +
      SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
 +
    }
 
   }
 
   }
 
}
 
}
Line 288: Line 536:
 
|}
 
|}
  
== Languages ==
+
=== 🇶 Language name(s) in English → Language LL Qid(s) ===
=== ?✅ Language's name(s) in English → Language Qid(s) ===
+
''This query has been UPDATED to work on Commons SPARQL Endpoint. ''
 
<!-- Q: Change exact match by CONTAINS() -->
 
<!-- Q: Change exact match by CONTAINS() -->
 
{| style="width:100%"  
 
{| style="width:100%"  
Line 295: Line 543:
 
|style="padding: 0 3em;width:60%"|
 
|style="padding: 0 3em;width:60%"|
 
<syntaxhighlight lang="sparql">
 
<syntaxhighlight lang="sparql">
SELECT ?languageId ?languageName
+
#defaultEndpoint:Commons
 +
SELECT ?languageId ?languageName  
 
WHERE {
 
WHERE {
   VALUES ?languageName { "Marathi" "Atikamekw" "Central Bikol" } # Target values
+
   SERVICE <https://query.wikidata.org/sparql> {
  ?languageId  
+
    VALUES ?languageName { "Marathi" "Atikamekw" "Central Bikol" } # Target values
    prop:P2 entity:Q4 ;         # Filter: P2 'instance of' is Q4 'language' AND
+
   
     rdfs:label ?languageLabel .  # Assign value label into ?languageLabel
+
    BIND ( STRLANG(?languageName, "en") AS ?languageLabel ) # Bind filter by English
   BIND ( STRLANG(?languageName, "en") AS ?languageLabel ) # Bind filter by English
+
   
}  
+
    ?languageId rdfs:label ?languageLabel ;  # Assign value label into ?languageLabel
 +
                wdt:P31 wd:Q34770 .         # Filter: P2 'instance of' is Q4 'language' AND
 +
      
 +
   }
 +
}
 
</syntaxhighlight>
 
</syntaxhighlight>
 
||
 
||
 
 
<query _pagination="5">
 
<query _pagination="5">
 +
#defaultEndpoint:Commons
 
SELECT ?languageId ?languageName  
 
SELECT ?languageId ?languageName  
 
WHERE {
 
WHERE {
   VALUES ?languageName { "Marathi" "Atikamekw" "Central Bikol" } # Target values
+
   SERVICE <https://query.wikidata.org/sparql> {
  ?languageId  
+
    VALUES ?languageName { "Marathi" "Atikamekw" "Central Bikol" } # Target values
    prop:P2 entity:Q4 ;         # Filter: P2 'instance of' is Q4 'language' AND
+
   
     rdfs:label ?languageLabel .  # Assign value label into ?languageLabel
+
    BIND ( STRLANG(?languageName, "en") AS ?languageLabel ) # Bind filter by English
   BIND ( STRLANG(?languageName, "en") AS ?languageLabel ) # Bind filter by English
+
   
}  
+
    ?languageId rdfs:label ?languageLabel ;  # Assign value label into ?languageLabel
 +
                wdt:P31 wd:Q34770 .         # Filter: P2 'instance of' is Q4 'language' AND
 +
      
 +
   }
 +
}
 
</query>
 
</query>
 
|}
 
|}
  
=== Language LL Qid (Q21) → Count items ===
+
=== Language ISO-639-3 → Language LL Qid(s), Wikidata Qid, Label ===
 +
''This query has been UPDATED to work on Commons SPARQL Endpoint.''
 
{| style="width:100%"  
 
{| style="width:100%"  
 
|- style="vertical-align:top;"
 
|- style="vertical-align:top;"
 
|style="padding: 0 3em;width:60%"|
 
|style="padding: 0 3em;width:60%"|
 
<syntaxhighlight lang="sparql">
 
<syntaxhighlight lang="sparql">
SELECT ?language (COUNT(?audio) AS ?nbAudio) WHERE {
+
#defaultEndpoint:Commons
   VALUES ?language { entity:Q21 }
+
SELECT ?langIso ?langId ?langIdLabel
   ?audio prop:P4 ?language .
+
WHERE {
 +
   SERVICE <https://query.wikidata.org/sparql> {
 +
    VALUES ?langIso { "mar" "bre" "bcl" "atj" "ban" } # Target ISO values
 +
    ?langId
 +
      wdt:P220 ?langIso ;    # Assign value: P13 'Iso-639-3' to ?langIso AND
 +
      wdt:P31 wd:Q34770 ;    # Filter: P2 'instance of' is Q4 'language'
 +
 
 +
  }
 +
 
 +
   # Labels
 +
  SERVICE wikibase:label {bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en"}
 
}
 
}
GROUP BY ?language
 
 
</syntaxhighlight>
 
</syntaxhighlight>
|
+
||
<query _pagination="6" item="Property" itemLabel="Values">
+
<query _pagination="5" >
SELECT ?language (COUNT(?audio) AS ?nbAudio) WHERE {
+
#defaultEndpoint:Commons
   VALUES ?language { entity:Q21 }
+
SELECT ?langIso ?langId ?langIdLabel
   ?audio prop:P4 ?language .
+
WHERE {
 +
   SERVICE <https://query.wikidata.org/sparql> {
 +
    VALUES ?langIso { "mar" "bre" "bcl" "atj" "ban" } # Target ISO values
 +
    ?langId
 +
      wdt:P220 ?langIso ;    # Assign value: P13 'Iso-639-3' to ?langIso AND
 +
      wdt:P31 wd:Q34770 ;    # Filter: P2 'instance of' is Q4 'language'
 +
 
 +
  }
 +
 
 +
   # Labels
 +
  SERVICE wikibase:label {bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en"}
 
}
 
}
GROUP BY ?language
 
 
</query>
 
</query>
 
|}
 
|}
=== Language LL Qid (Q21) → Count records ===
+
 
 +
=== Language LL All Languages → Count records ===
 +
''This query has been UPDATED to work on Commons SPARQL Endpoint.''
 
{| style="width:100%"  
 
{| style="width:100%"  
 
|- style="vertical-align:top;"
 
|- style="vertical-align:top;"
 
|style="padding: 0 3em;width:60%"|
 
|style="padding: 0 3em;width:60%"|
 
<syntaxhighlight lang="sparql">
 
<syntaxhighlight lang="sparql">
SELECT ?language (COUNT(?audio) AS ?audio) WHERE {
+
#defaultEndpoint:Commons
  VALUES ?language { entity:Q21 }
+
SELECT ?language ?languageLabel ?audios WHERE {
  ?audio prop:P2 entity:Q2 . # P2 'instance of' is Q2 'record'
+
  {
   ?audio prop:P4 ?language . # P4 'language' is Q21 'French'
+
    SELECT ?language (COUNT(?audio) AS ?audios) WHERE {
 +
    # Comment out the below statement to filter to only certain languages (e.g. Q34 or others)
 +
    # VALUES ?language { entity:Q34 }
 +
 
 +
    ?audio wdt:P31 wd:Q108167708 ; # Filter: P2 'instance of' is Q2 'record'
 +
          wdt:P407 ?language .
 +
   }
 +
  GROUP BY ?language
 +
  }
 +
 
 +
  SERVICE <https://query.wikidata.org/sparql> {
 +
    SERVICE wikibase:label {
 +
      bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en".
 +
      ?language rdfs:label ?languageLabel .
 +
    }
 +
  }
 
}
 
}
GROUP BY ?language
 
 
</syntaxhighlight>
 
</syntaxhighlight>
 
|
 
|
 
<query _pagination="6" item="Property" itemLabel="Values">
 
<query _pagination="6" item="Property" itemLabel="Values">
SELECT ?language (COUNT(?audio) AS ?audio) WHERE {
+
#defaultEndpoint:Commons
  VALUES ?language { entity:Q21 }
+
SELECT ?language ?languageLabel ?audios WHERE {
  ?audio prop:P2 entity:Q2 . # P2 'instance of' is Q2 'record'
+
  {
   ?audio prop:P4 ?language . # P4 'language' is Q21 'French'
+
    SELECT ?language (COUNT(?audio) AS ?audios) WHERE {
 +
    # Comment out the below statement to filter to only certain languages (e.g. Q34)
 +
    # VALUES ?language { entity:Q34 }
 +
 
 +
    ?audio wdt:P31 wd:Q108167708 ; # Filter: P2 'instance of' is Q2 'record'
 +
          wdt:P407 ?language .
 +
   }
 +
  GROUP BY ?language
 +
  }
 +
 
 +
  SERVICE <https://query.wikidata.org/sparql> {
 +
    SERVICE wikibase:label {
 +
      bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en".
 +
      ?language rdfs:label ?languageLabel .
 +
    }
 +
  }
 
}
 
}
GROUP BY ?language
 
 
</query>
 
</query>
 
|}
 
|}
  
=== ?✅ Language LL Qid (Q21) → Count unique words ===
+
=== 🇶 Language LL All Languages → Count unique words, audios, ratio ===
 +
''This query has been UPDATED to work on Commons SPARQL Endpoint.''
 
<!-- Use smaller language for higher speed -->
 
<!-- Use smaller language for higher speed -->
 
{| style="width:100%"  
 
{| style="width:100%"  
Line 367: Line 674:
 
|style="padding: 0 3em;width:60%"|
 
|style="padding: 0 3em;width:60%"|
 
<syntaxhighlight lang="sparql">
 
<syntaxhighlight lang="sparql">
SELECT ?language (COUNT(?audio) AS ?Audios) (COUNT(DISTINCT(?itemLabel)) AS ?Words)
+
#defaultEndpoint:Commons
(ROUND(10000*?Words/?Audios)/100 AS ?Percent)
+
SELECT ?language ?languageLabel ?words ?audios ?percent
 
WHERE {
 
WHERE {
   VALUES ?language { entity:Q21 }
+
   {
  ?audio prop:P2 entity:Q2 .  # P2 'instance of' is Q2 'record'
+
    SELECT ?language
  ?audio prop:P4 ?language . # P4 'language' is Q21 'French'
+
          (COUNT(DISTINCT(?itemLabel)) AS ?words)  # Count and assign value to ?Audio
   ?audio rdfs:label ?itemLabel. # Assign value: label to ?itemLabel
+
          (COUNT(?audio) as ?audios)
 +
          (ROUND(10000*?words/?audios)/100 AS ?percent)
 +
          WHERE {
 +
            # Uncomment the below line to filter languages (e.g Q34 or others)
 +
            # VALUES ?language { wd:Q34 }
 +
            ?audio wdt:P407 ?language ;      # Bind property P407 'language' to ?language
 +
                    wdt:P31 wd:Q108167708 ;  # Filter: P31 'instance of' Q108167708 (pronunciation file)
 +
                    wdt:P9533 ?itemLabel .   # Bind P9533 'transcription' to ?itemLabel.
 +
          }
 +
    GROUP BY ?language ?languageLabel
 +
   }
 +
 
 +
 +
    SERVICE <https://query.wikidata.org/sparql> {
 +
      SERVICE wikibase:label {
 +
        bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en".
 +
        ?language rdfs:label ?languageLabel .
 +
      }
 +
  }
 
}
 
}
GROUP BY ?language
 
 
</syntaxhighlight>
 
</syntaxhighlight>
 
|
 
|
 
<query _pagination="6" item="Property" itemLabel="Values">
 
<query _pagination="6" item="Property" itemLabel="Values">
SELECT ?language (COUNT(?audio) AS ?Audios) (COUNT(DISTINCT(?itemLabel)) AS ?Words) (ROUND(10000*?Words/?Audios)/100 AS ?Percent)
+
#defaultEndpoint:Commons
 +
SELECT ?language ?languageLabel ?words ?audios ?percent
 
WHERE {
 
WHERE {
   VALUES ?language { entity:Q21 }
+
   {
  ?audio prop:P2 entity:Q2 .  # P2 'instance of' is Q2 'record'
+
    SELECT ?language
  ?audio prop:P4 ?language . # P4 'language' is Q21 'French'
+
          (COUNT(DISTINCT(?itemLabel)) AS ?words)  # Count and assign value to ?Audio
   ?audio rdfs:label ?itemLabel. # Assign value: label to ?itemLabel
+
          (COUNT(?audio) as ?audios)
 +
          (ROUND(10000*?words/?audios)/100 AS ?percent)
 +
          WHERE {
 +
 
 +
            # VALUES ?language { entity:Q34 }
 +
            ?audio wdt:P407 ?language ;      # Bind property P407 'language' to ?language
 +
                    wdt:P31 wd:Q108167708 ;  # Filter: P31 'instance of' Q108167708 (pronunciation file)
 +
                    wdt:P9533 ?itemLabel .   # Bind P9533 'transcription' to ?itemLabel.
 +
          }
 +
    GROUP BY ?language ?languageLabel
 +
   }
 +
 
 +
 +
    SERVICE <https://query.wikidata.org/sparql> {
 +
      SERVICE wikibase:label {
 +
        bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en".
 +
        ?language rdfs:label ?languageLabel .
 +
      }
 +
  }
 
}
 
}
GROUP BY ?language
 
 
</query>
 
</query>
 
|}
 
|}
  
=== Language LL Qid (Q21) → Count speakers ===
+
=== Language LL All Languages → Count speakers ===
 +
''This query is IN WORK for Commons SPARQL Endpoint. One Wikidata property is missing; please update this query with the right property URI.''
 
{| style="width:100%"  
 
{| style="width:100%"  
 
|- style="vertical-align:top;"
 
|- style="vertical-align:top;"
 
|style="padding: 0 3em;width:60%"|
 
|style="padding: 0 3em;width:60%"|
 
<syntaxhighlight lang="sparql">
 
<syntaxhighlight lang="sparql">
SELECT ?language (COUNT(?audio) AS ?audio) WHERE {
+
#defaultEndpoint:Commons
  VALUES ?language { entity:Q21 }
+
SELECT ?language ?languageLabel ?speakers WHERE {
  ?audio prop:P2 entity:Q3 .  # P2 'instance of' is Q3 'speaker'
+
  {
   ?audio prop:P4 ?language . # P4 'language' is Q21 'French'
+
    SELECT ?language (COUNT(?speaker) AS ?speakers) WHERE {
 +
 
 +
      # Uncomment the below line to filter to specific languages
 +
      # E.g Q34 and others
 +
      # VALUES ?language { wd:Q34 }
 +
 
 +
      ?record wdt:P407 ?language ;                    # Bind P407 'language' to ?language (if unbound)
 +
              wdt:P31 wd:Q108167708 ;                # P31 'instance of' Q108167708 'pronunciation file'
 +
              wdt:SPEAKER_PROPERTY_MISSING ?speaker ; # Bind ??? 'speaker' to ?speaker
 +
    } GROUP BY ?language
 +
  }
 +
 
 +
   SERVICE <https://query.wikidata.org/sparql> {
 +
    SERVICE wikibase:label {
 +
      bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en".  
 +
      ?language rdfs:label ?languageLabel
 +
    }
 +
  }
 
}
 
}
GROUP BY ?language
 
 
</syntaxhighlight>
 
</syntaxhighlight>
 
|
 
|
 
<query _pagination="6" item="Property" itemLabel="Values">
 
<query _pagination="6" item="Property" itemLabel="Values">
SELECT ?language (COUNT(?audio) AS ?audio) WHERE {
+
#defaultEndpoint:Commons
  VALUES ?language { entity:Q21 }
+
SELECT ?language ?languageLabel ?speakers WHERE {
  ?audio prop:P2 entity:Q3 .  # P2 'instance of' is Q3 'speaker'
+
  {
   ?audio prop:P4 ?language . # P4 'language' is Q21 'French'
+
    SELECT ?language (COUNT(?speaker) AS ?speakers) WHERE {
 +
 
 +
      # Uncomment the below line to filter to specific languages
 +
      # E.g Q34 and others
 +
      # VALUES ?language { wd:Q34 }
 +
 
 +
      ?record wdt:P407 ?language ;                    # Bind P407 'language' to ?language (if unbound)
 +
              wdt:P31 wd:Q108167708 ;                # P31 'instance of' Q108167708 'pronunciation file'
 +
              wdt:SPEAKER_PROPERTY_MISSING ?speaker ; # Bind ??? 'speaker' to ?speaker
 +
    } GROUP BY ?language
 +
  }
 +
 
 +
   SERVICE <https://query.wikidata.org/sparql> {
 +
    SERVICE wikibase:label {
 +
      bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en".  
 +
      ?language rdfs:label ?languageLabel
 +
    }
 +
  }
 
}
 
}
GROUP BY ?language
 
 
</query>
 
</query>
 
|}
 
|}
  
=== Language LL Qid (Q209) → List speakers ===
+
=== Language LL Qid (Q209) → List speakers ===
 +
''This query is going to be DEPRECATED as the queried data will no longer be available.''
 
{| style="width:100%"  
 
{| style="width:100%"  
 
|- style="vertical-align:top;"
 
|- style="vertical-align:top;"
 
|style="padding: 0 3em;width:60%"|
 
|style="padding: 0 3em;width:60%"|
 
<syntaxhighlight lang="sparql">
 
<syntaxhighlight lang="sparql">
 +
#defaultEndpoint:Lingualibre
 
SELECT ?language ?speaker ?speakerLabel WHERE {
 
SELECT ?language ?speaker ?speakerLabel WHERE {
 
   VALUES ?language { entity:Q209 }
 
   VALUES ?language { entity:Q209 }
 
   ?speaker prop:P2 entity:Q3 .  # P2 'instance of' is Q3 'speaker'
 
   ?speaker prop:P2 entity:Q3 .  # P2 'instance of' is Q3 'speaker'
   ?speaker prop:P4 ?language .  # P4 'language' is Q21 'French'
+
   ?speaker prop:P4 ?language .  # P4 'language' is Q34 'Marathi'
 
   # Labels
 
   # Labels
 
   SERVICE wikibase:label {
 
   SERVICE wikibase:label {
Line 430: Line 807:
 
|
 
|
 
<query _pagination="6" item="Property" itemLabel="Values">
 
<query _pagination="6" item="Property" itemLabel="Values">
 +
#defaultEndpoint:Lingualibre
 
SELECT ?language ?speaker ?speakerLabel WHERE {
 
SELECT ?language ?speaker ?speakerLabel WHERE {
 
   VALUES ?language { entity:Q209 }
 
   VALUES ?language { entity:Q209 }
 
   ?speaker prop:P2 entity:Q3 .  # P2 'instance of' is Q3 'speaker'
 
   ?speaker prop:P2 entity:Q3 .  # P2 'instance of' is Q3 'speaker'
   ?speaker prop:P4 ?language .  # P4 'language' is Q21 'French'
+
   ?speaker prop:P4 ?language .  # P4 'language' is Q34 'Marathi'
 
   # Labels
 
   # Labels
 
   SERVICE wikibase:label {
 
   SERVICE wikibase:label {
Line 441: Line 819:
 
|}
 
|}
  
=== Language LL Qid ([[Q21]]) + Speaker ([[Q42]]) → Count records ===
+
=== Language LL Qid ([[d:Q12107]]) → Language data, all ===
 +
''This query has been UPDATED to work on Commons SPARQL Endpoint.''
 
{| style="width:100%"  
 
{| style="width:100%"  
 
|- style="vertical-align:top;"
 
|- style="vertical-align:top;"
 
|style="padding: 0 3em;width:60%"|
 
|style="padding: 0 3em;width:60%"|
 
<syntaxhighlight lang="sparql">
 
<syntaxhighlight lang="sparql">
SELECT ?language ?speakerLabel (COUNT(?audio) AS ?audio)
+
#defaultEndpoint:Commons
WHERE {
+
SELECT ?predicate ?object WHERE {
   VALUES ?language { entity:Q21 }
+
   SERVICE <https://query.wikidata.org/sparql> {
  VALUES ?speaker { entity:Q42 }
+
    # Given Q12107 language, get all properties and values
  ?audio prop:P4 ?language .  # P4 'language' is Q21 'French'
+
    wd:Q12107 ?predicate ?object .
  ?audio prop:P2 entity:Q2 .  # P2 'instance of' is Q2 'record'
+
   }
  ?audio prop:P5 ?speaker . # P5 'speaker' is Q42 '0x010C'
 
   # Labels
 
  SERVICE wikibase:label {bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en"}  
 
 
}
 
}
GROUP BY ?language ?speakerLabel
 
 
</syntaxhighlight>
 
</syntaxhighlight>
|
+
||
<query _pagination="6" item="Property" itemLabel="Values">
+
<query _pagination="10" >
SELECT ?language ?speakerLabel (COUNT(?audio) AS ?audio)
+
#defaultEndpoint:Commons
WHERE {
+
SELECT ?predicate ?object WHERE {
   VALUES ?language { entity:Q21 }
+
   SERVICE <https://query.wikidata.org/sparql> {
  VALUES ?speaker { entity:Q42 }
+
    # Given Q12107 language, get all properties and values
  ?audio prop:P4 ?language .  # P4 'language' is Q21 'French'
+
    wd:Q12107 ?predicate ?object .
  ?audio prop:P2 entity:Q2 .  # P2 'instance of' is Q2 'record'
+
   }
  ?audio prop:P5 ?speaker . # P5 'speaker' is Q42 '0x010C'
 
  # Labels
 
  SERVICE wikibase:label {
 
    bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
 
   }  
 
 
}
 
}
GROUP BY ?language ?speakerLabel
 
 
</query>
 
</query>
 
|}
 
|}
  
=== ✅ Languages List existing languages' iso-639-3 ===
+
=== Language LL Qid ([[d:Q12107]]) Language data, Literals ===
 
+
''This query has been UPDATED to work on Commons SPARQL Endpoint.''
 
{| style="width:100%"  
 
{| style="width:100%"  
 
|- style="vertical-align:top;"
 
|- style="vertical-align:top;"
 
|style="padding: 0 3em;width:60%"|
 
|style="padding: 0 3em;width:60%"|
 
<syntaxhighlight lang="sparql">
 
<syntaxhighlight lang="sparql">
 +
#defaultEndpoint:Commons
 
SELECT * WHERE {
 
SELECT * WHERE {
   ?lang prop:P13 ?code .
+
   SERVICE <https://query.wikidata.org/sparql> {
 +
    # Given Q12107 'Breton language', get only literals
 +
    wd:Q12107 ?predicate ?object .
 +
    ?predicate rdf:type owl:DatatypeProperty .
 +
  }
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>
 
||
 
||
<query _pagination="5" >
+
<query _pagination="10" >
 +
#defaultEndpoint:Commons
 
SELECT * WHERE {
 
SELECT * WHERE {
   ?lang prop:P13 ?code .
+
   SERVICE <https://query.wikidata.org/sparql> {
 +
    # Given Q12107 'Breton language', get only literals
 +
    wd:Q12107 ?predicate ?object .
 +
    ?predicate rdf:type owl:DatatypeProperty .
 +
  }
 
}
 
}
 
</query>
 
</query>
 
|}
 
|}
  
=== Language's ISO-639-3 → Language LL Qid ===
+
=== Language LL Qid ([[d:Q12107]]) → Property P220 (ISO 639-3) ===
 +
''This query has been UPDATED to work on Commons SPARQL Endpoint.''
 
{| style="width:100%"  
 
{| style="width:100%"  
 
|- style="vertical-align:top;"
 
|- style="vertical-align:top;"
 
|style="padding: 0 3em;width:60%"|
 
|style="padding: 0 3em;width:60%"|
 
<syntaxhighlight lang="sparql">
 
<syntaxhighlight lang="sparql">
SELECT ?langIso ?langId
+
#defaultEndpoint:Commons
WHERE {
+
SELECT * WHERE {
   VALUES ?langIso { "ban" "bre" } # One or multiple values
+
   SERVICE <https://query.wikidata.org/sparql> {
  # P2 'instance of'; Q4 'language'; P13 'ISO 639-3 code'
+
    wd:Q12107 wdt:P220 ?iso . # Assign value : Q209 'Breton', P13 'ISO 639-3', value into ?iso
   ?langId prop:P2 entity:Q4 ; prop:P13 ?langIso .
+
   }
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>
 
||
 
||
<query _pagination="5" >
+
<query _pagination="10" >
 +
#defaultEndpoint:Commons
 
SELECT * WHERE {
 
SELECT * WHERE {
   VALUES ?langIso { "ban" "bre" } # One or multiple values
+
   SERVICE <https://query.wikidata.org/sparql> {
  # P2 'instance of'; Q4 'language'; P13 'ISO 639-3 code'
+
    wd:Q12107 wdt:P220 ?iso . # Assign value : Q209 'Breton', P13 'ISO 639-3', value into ?iso
   ?langId prop:P2 entity:Q4 ; prop:P13 ?langIso .
+
   }
 
}
 
}
 
</query>
 
</query>
 
|}
 
|}
  
=== ✅ Language's ISO-639-3 → Language Wikidata Qid ===
+
=== Languages → List existing languages' iso-639-3 ===
 +
''This query has been UPDATED to work on Commons SPARQL Endpoint.''
 
{| style="width:100%"  
 
{| style="width:100%"  
 
|- style="vertical-align:top;"
 
|- style="vertical-align:top;"
 
|style="padding: 0 3em;width:60%"|
 
|style="padding: 0 3em;width:60%"|
 
<syntaxhighlight lang="sparql">
 
<syntaxhighlight lang="sparql">
SELECT *     # print all variables, synonymous to ?langId ?langIso ?langWDQid
+
#defaultEndpoint:Commons
WHERE {
+
SELECT * WHERE {
   VALUES ?langIso { "ban" "bre" } # One or multiple values
+
   SERVICE <https://query.wikidata.org/sparql> {
  ?langId
+
     ?lang wdt:P220 ?code .
     prop:P2 entity:Q4 ;    # Filter P2 'instance of' is Q4 'language' AND
+
  }
    prop:P13 ?langIso ;    # Assign value: P13 'Iso-639-3' to ?langIso AND
 
    prop:P12 ?langWDQid .  # Assign value: P12 'Iso-639-3' to ?langWDQid
 
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>
 
||
 
||
 
<query _pagination="5" >
 
<query _pagination="5" >
SELECT *     # print all variables, synonymous to ?langId ?langIso ?langWDQid
+
#defaultEndpoint:Commons
WHERE {
+
SELECT * WHERE {
   VALUES ?langIso { "ban" "bre" } # One or multiple values
+
   SERVICE <https://query.wikidata.org/sparql> {
  ?langId
+
     ?lang wdt:P220 ?code .
     prop:P2 entity:Q4 ;    # Filter P2 'instance of' is Q4 'language' AND
+
  }
    prop:P13 ?langIso ;    # Assign value: P13 'Iso-639-3' to ?langIso AND
 
    prop:P12 ?langWDQid .  # Assign value: P12 'Iso-639-3' to ?langWDQid
 
 
}
 
}
 
</query>
 
</query>
 
|}
 
|}
  
=== Language LL Qid ([[Q209]]) → Language data, all ===
+
=== 🇶 Language WD Qid → Language data, core ===
'''Case:'' Get for language Q209 'Breton' all its data.
+
''This query is going to be DEPRECATED as the queried data will no longer be available.''
 +
<!-- REQUIRE REVIEW FOR BETTER INLINE COMMENTS -->
 
{| style="width:100%"  
 
{| style="width:100%"  
 
|- style="vertical-align:top;"
 
|- style="vertical-align:top;"
 
|style="padding: 0 3em;width:60%"|
 
|style="padding: 0 3em;width:60%"|
 
<syntaxhighlight lang="sparql">
 
<syntaxhighlight lang="sparql">
 +
#defaultEndpoint:Lingualibre
 
SELECT * WHERE {
 
SELECT * WHERE {
   # Given Q209 'Breton language', get all properties and values
+
   ?lang prop:P12 "Q12107" .  # Filter: P12 'Wikidata id' is Wikidata's "Q12107"
   entity:Q209 ?predicate ?object .
+
   ?lang ?predicate ?object . #
 +
  ?predicate rdf:type owl:DatatypeProperty .
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>
 
||
 
||
 
<query _pagination="10" >
 
<query _pagination="10" >
 +
#defaultEndpoint:Lingualibre
 
SELECT * WHERE {
 
SELECT * WHERE {
   entity:Q209 ?predicate ?object .
+
   ?lang prop:P12 "Q12107" .
 +
  ?lang ?predicate ?object .
 +
  ?predicate rdf:type owl:DatatypeProperty .
 
}
 
}
 
</query>
 
</query>
 
|}
 
|}
  
=== ✅ Language LL Qid ([[Q209]]) → Language data, core ===
+
== Records ==
'''Case:'' Get for language Q209 'Breton' all its CORE data.
+
 
 +
=== Record LL Qid ([[sdc:M69288741]]) → Record data, all ===
 +
''This query has been UPDATED to work on Commons SPARQL Endpoint.''
 
{| style="width:100%"  
 
{| style="width:100%"  
 
|- style="vertical-align:top;"
 
|- style="vertical-align:top;"
 
|style="padding: 0 3em;width:60%"|
 
|style="padding: 0 3em;width:60%"|
 
<syntaxhighlight lang="sparql">
 
<syntaxhighlight lang="sparql">
 +
#defaultEndpoint:Commons
 
SELECT * WHERE {
 
SELECT * WHERE {
   # Given Q209 'Breton language', get all properties and values
+
   sdc:M69288741 ?predicate ?object .
  entity:Q209 ?predicate ?object .
 
  ?predicate rdf:type owl:DatatypeProperty .
 
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>
 
||
 
||
 
<query _pagination="10" >
 
<query _pagination="10" >
 +
#defaultEndpoint:Commons
 
SELECT * WHERE {
 
SELECT * WHERE {
   entity:Q209 ?predicate ?object .
+
   sdc:M69288741 ?predicate ?object .
  ?predicate rdf:type owl:DatatypeProperty .
 
 
}
 
}
 
</query>
 
</query>
 
|}
 
|}
  
=== ✅ Language WD Qid → Language data, core ===
+
=== Record LL Qid ([[sdc:M69288741]]) Record data, core ===
 +
''This query has been UPDATED to work on Commons SPARQL Endpoint.''
 
{| style="width:100%"  
 
{| style="width:100%"  
 
|- style="vertical-align:top;"
 
|- style="vertical-align:top;"
 
|style="padding: 0 3em;width:60%"|
 
|style="padding: 0 3em;width:60%"|
 
<syntaxhighlight lang="sparql">
 
<syntaxhighlight lang="sparql">
 +
#defaultEndpoint:Commons
 
SELECT * WHERE {
 
SELECT * WHERE {
   ?lang prop:P12 "Q12107" .  # P12 'Wikidata id' is Wikidata's "Q12107"
+
   sdc:M69288741 ?predicate ?object .
  ?lang ?predicate ?object . #
+
 
   ?predicate rdf:type owl:DatatypeProperty .
+
   SERVICE <https://query.wikidata.org/sparql> {
 +
    ?predicate rdf:type owl:DatatypeProperty .  
 +
  }
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>
 
||
 
||
 
<query _pagination="10" >
 
<query _pagination="10" >
 +
#defaultEndpoint:Commons
 
SELECT * WHERE {
 
SELECT * WHERE {
   ?lang prop:P12 "Q12107" .
+
   sdc:M69288741 ?predicate ?object .
  ?lang ?predicate ?object .
+
 
   ?predicate rdf:type owl:DatatypeProperty .
+
   SERVICE <https://query.wikidata.org/sparql> {
 +
    ?predicate rdf:type owl:DatatypeProperty .  
 +
  }
 
}
 
}
 
</query>
 
</query>
 
|}
 
|}
  
== Records ==
+
=== Language ([[d:Q1860]]) + String Record LL Qid(s) ===
=== ✅ Item name + language → Qid(s) ===
+
''This query has been UPDATED to work on Commons SPARQL Endpoint.''
 
{| style="width:100%"  
 
{| style="width:100%"  
 
|- style="vertical-align:top;"
 
|- style="vertical-align:top;"
 
|style="padding: 0 3em;width:60%"|
 
|style="padding: 0 3em;width:60%"|
 
<syntaxhighlight lang="sparql">
 
<syntaxhighlight lang="sparql">
SELECT ?itemLabel ?item
+
#defaultEndpoint:Commons
 +
SELECT ?item
 
WHERE {  
 
WHERE {  
   ?item prop:P2 entity:Q2 .   # Filter: P2 'instance of' Q3 'record'
+
   ?item wdt:P31 wd:Q108167708 . # Filter: P31 'instance of' Q108167708 'record'
   ?item rdfs:label ?itemLabel. # Assign value: label to ?itemLabel
+
   ?item wdt:P407 wd:Q1860 .     # Filter: P407 'language' is Q1860 'English'
   FILTER(CONTAINS(?itemLabel, "apple"@en)).  
+
   ?item wdt:P9533 "apple"@en.   # Filter: P9533 'transcription' is "apple"
} limit 10
+
}
 
</syntaxhighlight>
 
</syntaxhighlight>
 
||
 
||
 
<query _pagination="5">
 
<query _pagination="5">
SELECT ?itemLabel ?item
+
#defaultEndpoint:Commons
 +
SELECT ?item
 
WHERE {  
 
WHERE {  
   ?item prop:P2 entity:Q2 .   # Filter: P2 'instance of' Q3 'record'
+
   ?item wdt:P31 wd:Q108167708 . # Filter: P31 'instance of' Q108167708 'record'
   ?item rdfs:label ?itemLabel. # Assign value: label to ?itemLabel
+
   ?item wdt:P407 wd:Q1860 .     # Filter: P407 'language' is Q1860 'English'
   FILTER(CONTAINS(?itemLabel, "apple"@en)).  
+
   ?item wdt:P9533 "apple"@en. # Filter: P9533 'transcription' is "apple"
} limit 10
+
}  
 
</query>
 
</query>
 
|}
 
|}
  
=== Audio Qid → Audio data ===
+
=== Language ([[d:Q12107]]) + Speaker (/speakers/1 ??) + String (ni) → Record LL Qid ===
 +
''This query is IN WORK for Commons SPARQL Endpoint. One Wikidata property is missing; please update this query with the right property URI.''
  
=== ✅ Language ([[Q209]]) + speaker ([[Q584098]]) + word (ni) → Audio's Qid ===
 
 
'''Case:''' Search in Breton language, with speaker 'ThonyVezbe',  
 
'''Case:''' Search in Breton language, with speaker 'ThonyVezbe',  
 
{| style="width:100%"  
 
{| style="width:100%"  
Line 636: Line 1,030:
 
|style="padding: 0 3em;width:60%"|
 
|style="padding: 0 3em;width:60%"|
 
<syntaxhighlight lang="sparql">
 
<syntaxhighlight lang="sparql">
SELECT ?audio
+
SELECT ?audio ?urlPointer
 +
WHERE {
 +
  ?audio wdt:P407 wd:Q12107 ;                                                # P407 'language' is Q12107 'Breton'
 +
        wdt:SPEAKER_PROPERTY_MISSING <https://lingualibre.org/speakers/1> ; # ??? 'speaker' is ll.org/speakers/1 'ThonyVezbe'
 +
        wdt:P9533 "ni"@br ;
 +
        schema:url ?urlPointer .
 +
}
 +
</syntaxhighlight>
 +
||
 +
<query _pagination="5" >
 +
SELECT ?audio ?urlPointer
 +
WHERE {
 +
  ?audio wdt:P407 wd:Q12107 ;                                                # P407 'language' is Q12107 'Breton'
 +
        wdt:SPEAKER_PROPERTY_MISSING <https://lingualibre.org/speakers/1> ; # ??? 'speaker' is ll.org/speakers/1 'ThonyVezbe'
 +
        wdt:P9533 "ni"@br ;
 +
        schema:url ?urlPointer .
 +
}
 +
</query>
 +
|}
 +
 
 +
=== Language ([[d:Q150]]) + Speaker (/speakers/1 ??) + String → URL pointer, filename ===
 +
''This query is IN WORK for Commons SPARQL Endpoint. One Wikidata property is missing; please update this query with the right property URI.''
 +
{| style="width:100%"
 +
|- style="vertical-align:top;"
 +
|style="padding: 0 3em;width:60%"|
 +
<syntaxhighlight lang="sparql">
 +
SELECT ?audio ?urlPointer
 +
  (REPLACE(REPLACE(REPLACE(SUBSTR(STR(?urlPointer),52),"%20","_"),"%28","("),"%29",")") AS ?filename)
 
WHERE {
 
WHERE {
   ?audio prop:P4 entity:Q209 .    # P4 'language' is Q209 'Breton'
+
   ?audio wdt:P407 wd:Q150 ;                                                  # Filter: P407 'language' is Q150 'French'
  ?audio prop:P5 entity:Q584098 . # P5 'speaker' is Q584098 'ThonyVezbe'
+
        wdt:SPEARKER_PROPERTY_MISSING <https://lingualibre.org/speakers/1> ; # Filter: ??? 'speaker' is ll.org/speakers/1 'Aemines1'
  ?audio rdfs:label ?word . #word
+
        wdt:P9533 "pomme"@fr ; # Filter: P9533 'audio transcription' of "pomme" in French
  FILTER ( STR(?word) = "ni" )    # word = 'ni'
+
        schema:url ?urlPointer # Bind the URI to the file to ?urlPointer
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>
 
||
 
||
 
<query _pagination="5" >
 
<query _pagination="5" >
SELECT ?audio
+
SELECT ?audio ?urlPointer
 +
  (REPLACE(REPLACE(REPLACE(SUBSTR(STR(?urlPointer),52),"%20","_"),"%28","("),"%29",")") AS ?filename)
 
WHERE {
 
WHERE {
   ?audio prop:P4 entity:Q209 .
+
   ?audio wdt:P407 wd:Q150 ;                                                  # Filter: P407 'language' is Q150 'French'
  ?audio prop:P5 entity:Q584098 .
+
        wdt:SPEARKER_PROPERTY_MISSING <https://lingualibre.org/speakers/1> ; # Filter: ??? 'speaker' is ll.org/speakers/1 'Aemines1'
  ?audio rdfs:label ?word . #word
+
        wdt:P9533 "pomme"@fr ; # Filter: P9533 'audio transcription' of "pomme" in French
  FILTER ( STR(?word) = "ni" )
+
        schema:url ?urlPointer # Bind the URI to the file to ?urlPointer
 
}
 
}
 
</query>
 
</query>
 
|}
 
|}
  
=== <!--✅--> Langue + speaker + word → Audio's Commons url pointeur ([[Property:P3|P3]]) ===
+
=== Files on Commons about records in Punjabi with transcription and LinguaLibre identifier ===
 +
 
 +
<syntaxhighlight lang="sparql">
 +
#defaultEndpoint:Commons
 +
SELECT * WHERE {
 +
  ?m wdt:P31 wd:Q108167708 ; #record
 +
    wdt:P407 wd:Q58635 ; #in Punjabi
 +
    wdt:P9533 ?transcription ; #with transcription
 +
    wdt:P10369 ?idLili . #with LinguaLibre identifier
 +
}
 +
LIMIT 100
 +
</syntaxhighlight>
 +
 
 +
=== 🇶 Count records by gender of the speaker ([[Property:P8|P8]]) ===
 +
 
 
{| style="width:100%"  
 
{| style="width:100%"  
 
|- style="vertical-align:top;"
 
|- style="vertical-align:top;"
 
|style="padding: 0 3em;width:60%"|
 
|style="padding: 0 3em;width:60%"|
 
<syntaxhighlight lang="sparql">
 
<syntaxhighlight lang="sparql">
SELECT ?word ?audio ?url (STR(?url) AS ?urlStr)
+
SELECT ?genderLabel (count(?record) AS ?nb)
 
WHERE {
 
WHERE {
   ?audio prop:P4 entity:Q209 .   # P4 'language' is Q209 'Breton'
+
   ?record prop:P2 entity:Q2 ;
   ?audio prop:P5 entity:Q584098 . # P5 'speaker' is Q584098 'ThonyVezbe'
+
          prop:P5 ?speaker .
  ?audio rdfs:label ?word .       # word
+
   ?speaker prop:P2 entity:Q3 ;
   FILTER ( STR(?word) = "achantour" )    # Filter: word is 'achantour'
+
          prop:P8 ?gender .
   ?audio prop:P3 ?url
+
   # Add labels to each variable used.
 +
   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" . }
 
}
 
}
 +
GROUP BY ?genderLabel
 
</syntaxhighlight>
 
</syntaxhighlight>
 
||
 
||
 
<query _pagination="5" >
 
<query _pagination="5" >
SELECT ?word ?audio ?url (STR(?url) AS ?urlStr)
+
SELECT ?genderLabel (count(?record) AS ?nb)
 
WHERE {
 
WHERE {
   ?audio prop:P4 entity:Q209 .
+
   ?record prop:P2 entity:Q2 ;
   ?audio prop:P5 entity:Q584098 .
+
          prop:P5 ?speaker .
  ?audio rdfs:label ?word .
+
   ?speaker prop:P2 entity:Q3 ;
   FILTER ( STR(?word) = "achantour" )
+
          prop:P8 ?gender .
   ?audio prop:P3 ?url
+
   # Add labels to each variable used.
 +
   SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" . }
 
}
 
}
 +
GROUP BY ?genderLabel
 +
GROUP BY ?genderLabel
 
</query>
 
</query>
 
|}
 
|}
Line 694: Line 1,135:
 
|style="padding: 0 3em;width:60%"|
 
|style="padding: 0 3em;width:60%"|
 
<syntaxhighlight lang="sparql">
 
<syntaxhighlight lang="sparql">
 +
#defaultEndpoint:Lingualibre
 
SELECT ?languageQidLabel ?wdQid ?languageQid ?isoCode  
 
SELECT ?languageQidLabel ?wdQid ?languageQid ?isoCode  
 
(COUNT(DISTINCT(?record)) AS ?recordCount)
 
(COUNT(DISTINCT(?record)) AS ?recordCount)
Line 719: Line 1,161:
 
||
 
||
 
<pre>
 
<pre>
 +
#defaultEndpoint:Lingualibre
 
languageQidLabel wdQid languageQid isoCode recordCount speakerM speakerF
 
languageQidLabel wdQid languageQid isoCode recordCount speakerM speakerF
 
French Q150 Q21 fra 16761 0 18
 
French Q150 Q21 fra 16761 0 18
Line 729: Line 1,172:
 
=== ❌ Is Language ([[Q3]]) → list all languages with number of unique words and speakers ===
 
=== ❌ Is Language ([[Q3]]) → list all languages with number of unique words and speakers ===
 
<syntaxhighlight lang="sparql">
 
<syntaxhighlight lang="sparql">
 +
#defaultEndpoint:Lingualibre
 
SELECT ?language (COUNT(?audio) AS ?nbAudio) (COUNT(?speaker) AS ?nbSpeaker) WHERE {
 
SELECT ?language (COUNT(?audio) AS ?nbAudio) (COUNT(?speaker) AS ?nbSpeaker) WHERE {
 
   ?language prop:P2 entity:Q4 .
 
   ?language prop:P2 entity:Q4 .
Line 737: Line 1,181:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
== Tools ==
+
== Others ==
* [https://lingualibre.org/bigdata/#query LinguaLibre Query Service] – run SPARQL Queries to LinguaLibre here.
+
''(These old queries are not assessed yet.)''
* [[Special:ApiSandbox]] – API queries generator for Lingualibre wikipage and wikibase contents.
+
=== Language ([[Q209]]) → Record, speaker's language level ===
  
=== Wikidata lexemes===
+
{| style="width:100%"
:''You may [<tvar|hackme>https://jsfiddle.net/hugolpz/rygo9s5b/</> Hack me !]''
+
|- style="vertical-align:top;"
 +
|style="padding: 0 3em;width:60%"|
 +
<syntaxhighlight lang="sparql">
 +
#defaultEndpoint:Lingualibre
 +
select ?record ?recordLabel ?speakerLabel ?languageLabel ?languageLevelLabel
 +
where {
 +
  ?record prop:P2 entity:Q2  # Filter: P2 'instance of' is Q2 'record' AND P4
 +
; prop:P4 entity:Q209 .  # AND P4 'language' is Q209 'Breton'
 +
  ?record prop:P5 ?speaker .  # Assign value: record's P5 'speaker' into ?speaker
 +
  ?record prop:P4 ?language . # Assign value: record's P4 'language' into ?language
 +
 
 +
  ?speaker llp:P4 ?languageStatement .    # P4 'language'
 +
  ?languageStatement llv:P4 ?language .  # P4 'language'
 +
  ?languageStatement llq:P16 ?languageLevel . # P16 'language level'
 +
  # Adds labels
 +
  SERVICE wikibase:label {
 +
    bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
 +
  }
 +
} ORDER BY ?languageLabel ?languageLevelLabel
 +
</syntaxhighlight>
 +
||
 +
<query _pagination="5">
 +
#defaultEndpoint:Lingualibre
 +
select ?record ?recordLabel ?speakerLabel ?languageLabel ?languageLevelLabel
 +
where {
 +
  ?record prop:P2 entity:Q2  # Filter: P2 'instance of' is Q2 'record' AND P4
 +
; prop:P4 entity:Q209 .  # AND P4 'language' is Q209 'Breton'
 +
  ?record prop:P5 ?speaker .  # Assign value: record's P5 'speaker' into ?speaker
 +
  ?record prop:P4 ?language . # Assign value: record's P4 'language' into ?language
 +
 
 +
  ?speaker llp:P4 ?languageStatement .    # P4 'language'
 +
  ?languageStatement llv:P4 ?language .  # P4 'language'
 +
  ?languageStatement llq:P16 ?languageLevel . # P16 'language level'
 +
  # Adds labels
 +
  SERVICE wikibase:label {
 +
    bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
 +
  }
 +
} ORDER BY ?languageLabel ?languageLevelLabel
 +
</query>
 +
|}
  
It is possible to use Wikidata & Wiktionary to extract lexicographical information. Developer <tvar|sina_ahm>@sina_ahm</> created a SPARQL query generator, helping us to search words in both Wikidata & Dbnary. See demo there : <tvar|1>https://sinaahmadi.github.io/posts/sparql-query-generator-for-lexicographical-data.html</>
+
=== Language ([[Q34]]) → Records of Wikidata concepts with WD Qid ([[Property:P12|P12]]) ===
 +
:''Those items were proposed to Lingualibre's recorder at step 3 via a SPARQL query upon Wikidata, so those words have WD's Qids.''
 +
{| style="width:100%"
 +
|- style="vertical-align:top;"
 +
|style="padding: 0 3em;width:60%"|
 +
<syntaxhighlight lang="sparql">
 +
#defaultEndpoint:Lingualibre
 +
SELECT ?languageLabel ?recordLabel ?record ?wid
 +
WHERE {
 +
  ?record prop:P2 entity:Q2 .    # Filter: P2 'instance of' is Q2 'record'
 +
  ?record prop:P4 entity:Q34 .  # Filter: P4 'language' is Q34 'Marathi'
 +
  ?record prop:P4 ?language .    # Assign value: record's P4 'language' to variable ?language
 +
  ?record prop:P12 ?wid .        # Assign value: record's P12 'wikidata id' to variable ?wid
 +
  # Add labels capability
 +
  SERVICE wikibase:label {
 +
    bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
 +
  }
 +
}
 +
</syntaxhighlight>
 +
||
 +
<query _pagination="5">
 +
#defaultEndpoint:Lingualibre
 +
SELECT ?languageLabel ?recordLabel ?record ?wid
 +
WHERE {
 +
  ?record prop:P2 entity:Q2 .    # Filter: P2 'instance of' is Q2 'record'
 +
  ?record prop:P4 entity:Q34 .  # Filter: P4 'language' is Q34 'Marathi'
 +
  ?record prop:P4 ?language .    # Assign value: record's P4 'language' to variable ?language
 +
  ?record prop:P12 ?wid .       # Assign value: record's P12 'wikidata id' to variable ?wid
 +
  # Add labels capability
 +
  SERVICE wikibase:label {
 +
    bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
 +
  }
 +
}
 +
</query>
 +
|}
 +
 
 +
=== Records → Filter by date: late 2018 ===
 +
{| style="width:100%"
 +
|- style="vertical-align:top;"
 +
|style="padding: 0 3em;width:60%"|
 +
<syntaxhighlight lang="sparql">
 +
#defaultEndpoint:Lingualibre
 +
SELECT
 +
(COUNT(DISTINCT ?record) AS ?records)
 +
(COUNT(DISTINCT ?speaker) AS ?speakers)
 +
(COUNT(DISTINCT ?language) AS ?languages)
 +
WHERE {
 +
  ?record prop:P2 entity:Q2 .
 +
  ?record prop:P6 ?date .
 +
  ?record prop:P5 ?speaker .
 +
  ?record prop:P4 ?language .
 +
  # Filters:
 +
  FILTER(?date >= "2018-07-01T00:00:00Z"^^xsd:dateTime
 +
      && ?date < "2019-01-01T00:00:00Z"^^xsd:dateTime)
 +
}
 +
</syntaxhighlight>
 +
||
 +
<query>
 +
#defaultEndpoint:Lingualibre
 +
SELECT
 +
(COUNT(DISTINCT ?record) AS ?records)
 +
(COUNT(DISTINCT ?speaker) AS ?speakers)
 +
(COUNT(DISTINCT ?language) AS ?languages)
 +
WHERE {
 +
  ?record prop:P2 entity:Q2 .
 +
  ?record prop:P6 ?date .
 +
  ?record prop:P5 ?speaker .
 +
  ?record prop:P4 ?language .
 +
  # Filters:
 +
  FILTER(?date >= "2018-07-01T00:00:00Z"^^xsd:dateTime
 +
      && ?date < "2019-01-01T00:00:00Z"^^xsd:dateTime)
 +
}
 +
</query>
 +
|}
  
 
== See also ==
 
== See also ==
* [[Help:Querying Lingua Libre]]
+
* [[Help:SPARQL 2]] — next tutorial with focus on federate queries and Wikidata Lexemes.
* [[Help:APIs]]
+
** [[d:Wikidata:Lexicographical data/Ideas of queries|Lexicographical data/Ideas of queries]]
 +
** [[LinguaLibre:Wikidata]] — stub, help write it !
 +
* [[Help:Querying Lingua Libre]] — general review, redirecting users to rightful place.
 +
* [[Help:APIs]] — API queries over Wikimedia Commons or other Wikimedia wikis.
 +
* [[:mw:Manual:Developing extensions]] — PHP-based modules enhancing wikis, can pull data via SPARQL queries.
 +
 
 +
{{Technicals}}
 +
 
 
[[Category:Lingua Libre:Help{{#translation:}}]]
 
[[Category:Lingua Libre:Help{{#translation:}}]]

Latest revision as of 11:23, 28 April 2024


Draft
Twemoji12 1f3d7.svg
Twemoji12 1f3d7.svg

December 2021 rewriting : work in progress, please do not translate yet.
  1. NOW/Opened: General content review. You may help by: a) reading and copy-editing the page's English, b) testing queries on LLQS, edit in or discuss improvements, 3) increase comments' concistency.
  2. Legend: 🇶 minor aspects to improve, see hidden comment ; ❌ query too heavy to run in this page.
  3. Later/not yet: translations.

Help welcome.

Base

Useful elements

... Loading ...

Tools

On Wikidata, the WDQS allows to practice SPARQL queries creation in an intuitive way.

References

Code snippets

Fetch data using SPARQL

LinguaLibre data can be fetched using various coding languages such as Python, Javascript, R and others, returning JSON or other formats.

  • For code snippet in your language : open query.wikidata.org (WikiData Query Service, aka WDQS), run your SPARQL query, click "Code" : a pop up window appears with various implementations.
  • For downloading data, click "Download".

Javascript:
At least 3 methods exists (code snippet), example:

Query Result's basic unit
SPARQL:
SELECT ?item WHERE { ?item prop:P2 entity:Q5 } LIMIT 10
{  },
{
  "item": {
    "type": "uri",
    "value": "https://lingualibre.org/entity/Q12"
  },
  "itemLabel": {
    "xml:lang": "en",
    "type": "literal",
    "value": "beginner"
  }
},
{  }
Javascript:
var endpoint = 'https://lingualibre.org/sparql';
var sparql = 'SELECT ?item WHERE { ?item prop:P2 entity:Q5 } LIMIT 10';
$.getJSON(endpoint,
	{ query: sparql, format: 'json' },
	function(data){ console.log('JQuery: ',data)}
);

Merging data

Advanced SPARQL queries with COUNT() and others are often slow (>3secs, sometime >100secs). You are encouraged to do multiple smaller SPARQL queries to then merge their responded data. By example, the complementary Javascript snippet below would help web developers to do so.

// Data from 3 sparql queries.
// Important: One key must be similar in all datasets, here: 'qid'
const langs = [{ qid: 'Q209', label: 'Breton', iso:'bre' }, { qid: 'Q34', label: 'Marathi', iso: 'mar' }],
    speakersFemales = [{ qid: 'Q209', genderF: 3, recordsF: 60 }, { qid: 'Q34', genderF: 21, recordsF:5046 }],
    speakersMales = [{ qid: 'Q209', genderM: 7, recordsM: 218 }, { qid: 'Q34', genderM: 85, recordsM:32964 }];
// Toolbox for merging data by same id
var merge2ArraysBySameId = function(arr1,arr2,id1){
	return arr1.map( item1 => { 
  	var identical = arr2.find(obj => obj[id1] === item1[id1]); 
  	return Object.assign(identical, item1) 
  } );
}
// Mergings
var step1 = merge2ArraysBySameId(langs,speakersFemales,'qid');
var step2 = merge2ArraysBySameId(step1,speakersMales,'qid');
alert(JSON.stringify(step2))

Lingualibre's ground

Is Language (d:Q34770) → List existing languages with: LL Qid, ISO 639-3, Name

This query has been UPDATED to work on Commons SPARQL Endpoint.

#defaultEndpoint:Commons
SELECT ?lang ?iso ?langLabel
WHERE {
  # First get the relevant languages by first looking up all records
  {
    SELECT DISTINCT ?lang WHERE {
      _:record wdt:P31 wd:Q108167708 ; # Filter to get wd:Q108167708 (pronunciation file)
               wdt:P407 ?lang .        # For each pronunciation file, fetch the language
    }
  }
  
  # From this point on, ?lang is bound. Get the label and ISO code on Wikidata
  SERVICE <https://query.wikidata.org/sparql> {
    ?lang wdt:P31 wd:Q34770 .  # Filter: P31 'instance of' is Q1193409 'language or dialect'.
    ?lang wdt:P220 ?iso .      # Assign value: P220 'ISO-639-3' into ?iso.
  }

  SERVICE wikibase:label {
    # Add label to each variable used.
    # ?lang now has twin variable ?langLabel
    bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
  } 
}
... Loading ...

Is Speaker (speaker (Q3)) → List existing speakers

This query is going to be DEPRECATED as the queried data will no longer be available.

#defaultEndpoint:Lingualibre
SELECT ?speaker ?speakerLabel
WHERE {
  ?speaker prop:P2 entity:Q3 .  # Filter: P2 'instance of' is Q3 'speaker'.
  # Add labels to each variable used.
  SERVICE wikibase:label {
    bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
  } 
}
... Loading ...

Is Language level (language level (Q5)) → List existing levels

This query is going to be DEPRECATED as the queried data will no longer be available.

#defaultEndpoint:Lingualibre
SELECT ?item ?itemLabel
WHERE {
  ?item prop:P2 entity:Q5    # Filter: P2 'instance of' is Q5 'language level'.
  # Add labels to each variable used.
  SERVICE wikibase:label {
    bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
  } 
}
... Loading ...

Is Sex or Gender (sex or gender (Q7)) → List existing sexes or genders

This query is going to be DEPRECATED as the queried data will no longer be available.

#defaultEndpoint:Lingualibre
SELECT ?item ?itemLabel
WHERE {
  ?item prop:P2 entity:Q7    # Filter: P2 'instance of' is Q7 'sex or gender'.
  # Add labels to each variable used.
  SERVICE wikibase:label {
    bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
  } 
}
... Loading ...

Speaker

🇶 Speaker name(s) → Speaker Qid(s)

This query is going to be DEPRECATED as the queried data will no longer be available.

#defaultEndpoint:Lingualibre
SELECT ?speakerName ?speakerId
WHERE {
  VALUES ?speakerName { "Yug" "VIGNERON" } # Assign value: one or multiple values
  # note: need to comment BIND
  BIND ( STRLANG(?speakerName, "en") AS ?speakerLabel )
  # Grammatical note: ';' allows to chain actions 
  ?speakerId prop:P2 entity:Q3 ;        # Filter: P2 'instance of' is Q3 'speaker'.
             rdfs:label ?speakerLabel . # Filter by value: label equal ?speakerLabel's value
}
... Loading ...

🇶 Speaker Qid (SangeetaRH (Q445757)) → Speaker data, all

This query is going to be DEPRECATED as the queried data will no longer be available.

#defaultEndpoint:Lingualibre
# Get Q445757 (User:SangeetaRH‎)'s data
SELECT ?anyProperty ?anyValue ?anyValueLabel
WHERE {
  entity:Q445757 ?anyProperty ?anyValue .  # Filter: of Q445757 'SangeetaRH‎', get any property and any values
  # Add labels
  SERVICE wikibase:label {
    bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
  } 
}
... Loading ...

🇶 Speaker Qid (SangeetaRH (Q445757)) → Speaker languages (P4)

This query is going to be DEPRECATED as the queried data will no longer be available.

#defaultEndpoint:Lingualibre
SELECT ?languages ?languagesLabel
WHERE {
  entity:Q445757 prop:P4 ?languages . # Assign value: for Q445757 'SangeetaRH‎', P4 'language' into ?languages
  # Add labels
  SERVICE wikibase:label {
    bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
  } 
}
... Loading ...

🇶 Count speaker gender (P8)

#defaultEndpoint:Lingualibre
SELECT ?genderLabel (count(?speaker) AS ?nb)
WHERE {
  ?speaker prop:P2 entity:Q3 ;
           prop:P8 ?gender .
  SERVICE wikibase:label {
    bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
  } 
}
GROUP BY ?genderLabel
... Loading ...

Speaker Qid (speakers/1 ???) + Language LL Qid (d:Q1571) → List records

This query is IN WORK for Commons SPARQL Endpoint. One Wikidata property is missing; please update this query with the right property URI.

#defaultEndpoint:Commons
SELECT ?audio ?audioLabel
WHERE {
  ?audio wdt:SPEAKER_PROPERTY_MISSING <http://lingualibre.org/speakers/1> ; # Filter: ??? 'speaker' P5 Speaker is User:SangeetaRH
         wdt:P407 wd:Q1571 .   # Filter: P407 'language' is Q1571 'Marathi'
  
  # Add labels
  SERVICE wikibase:label {
    bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
  } 
}
... Loading ...

Speaker Qid (speakers/1 ???) + Language LL Qid (d:Q1571) → Count records

This query is IN WORK for Commons SPARQL Endpoint. One Wikidata property is missing; please update this query with the right property URI.

#defaultEndpoint:Commons
SELECT ?language ?speaker (COUNT(?audio) AS ?audio)
WHERE {
  # Comment out the below pattern to filter by language, e.g. Q1571 or others
  # VALUES ?language { wd:Q1571 }  # Bind value: Q1571 'Marathi' into ?language
  VALUES ?speaker { <http://lingualibre.org/speakers/1> }   # Assign value: ll.org/speakers/1 (for 'SangeetaRH') into ?speaker
  
  ?audio wdt:SPEAKER_PROPERTY_MISSING ?speaker ; # Filter: ??? 'speaker' is ?speaker
         wdt:P407 ?language ;                    # Filter: P407 'language' bound to ?language
         wdt:P31 wd:Q108167708 .                 # Filter: P31 'instance of' is Q108167708 'pronunciation file'
}
GROUP BY ?language ?speaker  # Sorting first groups per language and speaker
... Loading ...

Is Speaker (speaker (Q3)) → List of accounts and associated speakers

This query is going to be DEPRECATED as the queried data will no longer be available.

#defaultEndpoint:Lingualibre
SELECT ?linkedUser ?speakerLabel (SUBSTR(STR(?speaker),32) AS ?speakerQid)
WHERE {
  ?speaker prop:P2 entity:Q3 .  # Filter: P2 'instance of' is Q3 'speaker'.
  ?speaker prop:P11 ?linkedUser . # Assign value: P11 'linked users' into ?linkedUser.
  # Add labels
  SERVICE wikibase:label {
    bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
  } 
} ORDER BY DESC (?speakerLabel)
... Loading ...

Languages

🇶 LL Language (Q930) → List of words recorded

This query could be run on Wikimedia Commons MediaWiki API. See Help:APIs.

#defaultEndpoint:Wikidata
PREFIX prop: <https://lingualibre.org/prop/direct/>
PREFIX entity: <https://lingualibre.org/entity/>
SELECT ?writing WHERE {
  SERVICE <https://lingualibre.org/sparql> {
    SELECT ?writing WHERE {
      ?record prop:P2 entity:Q2;
        prop:P4 entity:Q930, ?language;
        prop:P3 ?url;
        prop:P7 ?writing.
    # FILTER(CONTAINS(STR(?audio), "LL-Q35735")) # occitan
      SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
    }
  }
}
... Loading ...

🇶 Language name(s) in English → Language LL Qid(s)

This query has been UPDATED to work on Commons SPARQL Endpoint.

#defaultEndpoint:Commons
SELECT ?languageId ?languageName 
WHERE {
  SERVICE <https://query.wikidata.org/sparql> {
    VALUES ?languageName { "Marathi" "Atikamekw" "Central Bikol" } # Target values
    
    BIND ( STRLANG(?languageName, "en") AS ?languageLabel ) # Bind filter by English
    
    ?languageId rdfs:label ?languageLabel ;  # Assign value label into ?languageLabel
                wdt:P31 wd:Q34770 .          # Filter: P2 'instance of' is Q4 'language' AND
    
  }
}
... Loading ...

Language ISO-639-3 → Language LL Qid(s), Wikidata Qid, Label

This query has been UPDATED to work on Commons SPARQL Endpoint.

#defaultEndpoint:Commons
SELECT ?langIso ?langId ?langIdLabel
WHERE {
  SERVICE <https://query.wikidata.org/sparql> {
    VALUES ?langIso { "mar" "bre" "bcl" "atj" "ban" } # Target ISO values
    ?langId 
      wdt:P220 ?langIso ;    # Assign value: P13 'Iso-639-3' to ?langIso AND
      wdt:P31 wd:Q34770 ;    # Filter: P2 'instance of' is Q4 'language' 

  }

  # Labels
  SERVICE wikibase:label {bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en"}
}
... Loading ...

Language LL All Languages → Count records

This query has been UPDATED to work on Commons SPARQL Endpoint.

#defaultEndpoint:Commons
SELECT ?language ?languageLabel ?audios WHERE {
  { 
    SELECT ?language (COUNT(?audio) AS ?audios) WHERE {
    # Comment out the below statement to filter to only certain languages (e.g. Q34 or others)
    # VALUES ?language { entity:Q34 }

    ?audio wdt:P31 wd:Q108167708 ;  # Filter: P2 'instance of' is Q2 'record'
           wdt:P407 ?language .
  }
   GROUP BY ?language
  }

  SERVICE <https://query.wikidata.org/sparql> {
    SERVICE wikibase:label { 
      bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en".
      ?language rdfs:label ?languageLabel .
    }
  }
}
... Loading ...

🇶 Language LL All Languages → Count unique words, audios, ratio

This query has been UPDATED to work on Commons SPARQL Endpoint.

#defaultEndpoint:Commons
SELECT ?language ?languageLabel ?words ?audios ?percent
WHERE {
  {
    SELECT ?language
           (COUNT(DISTINCT(?itemLabel)) AS ?words)  # Count and assign value to ?Audio
           (COUNT(?audio) as ?audios) 
           (ROUND(10000*?words/?audios)/100 AS ?percent)
           WHERE {
             # Uncomment the below line to filter languages (e.g Q34 or others)
             # VALUES ?language { wd:Q34 }
             ?audio wdt:P407 ?language ;      # Bind property P407 'language' to ?language
                    wdt:P31 wd:Q108167708 ;   # Filter: P31 'instance of' Q108167708 (pronunciation file)
                    wdt:P9533 ?itemLabel .   # Bind P9533 'transcription' to ?itemLabel.
           }
    GROUP BY ?language ?languageLabel
  }

 
    SERVICE <https://query.wikidata.org/sparql> {
      SERVICE wikibase:label { 
        bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en".
        ?language rdfs:label ?languageLabel .
      }
  }
}
... Loading ...

Language LL All Languages → Count speakers

This query is IN WORK for Commons SPARQL Endpoint. One Wikidata property is missing; please update this query with the right property URI.

#defaultEndpoint:Commons
SELECT ?language ?languageLabel ?speakers WHERE {
  {
    SELECT ?language (COUNT(?speaker) AS ?speakers) WHERE {

      # Uncomment the below line to filter to specific languages
      # E.g Q34 and others
      # VALUES ?language { wd:Q34 }

      ?record wdt:P407 ?language ;                    # Bind P407 'language' to ?language (if unbound)
              wdt:P31 wd:Q108167708 ;                 # P31 'instance of' Q108167708 'pronunciation file'
              wdt:SPEAKER_PROPERTY_MISSING ?speaker ; # Bind ??? 'speaker' to ?speaker
    } GROUP BY ?language
  }
  
  SERVICE <https://query.wikidata.org/sparql> {
    SERVICE wikibase:label { 
      bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". 
      ?language rdfs:label ?languageLabel
    }
  }
}
... Loading ...

Language LL Qid (Q209) → List speakers

This query is going to be DEPRECATED as the queried data will no longer be available.

#defaultEndpoint:Lingualibre
SELECT ?language ?speaker ?speakerLabel WHERE {
  VALUES ?language { entity:Q209 }
  ?speaker prop:P2 entity:Q3 .  # P2 'instance of' is Q3 'speaker'
  ?speaker prop:P4 ?language .  # P4 'language' is Q34 'Marathi'
  # Labels
  SERVICE wikibase:label {
    bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
  } 
}
... Loading ...

Language LL Qid (d:Q12107) → Language data, all

This query has been UPDATED to work on Commons SPARQL Endpoint.

#defaultEndpoint:Commons
SELECT ?predicate ?object WHERE {
  SERVICE <https://query.wikidata.org/sparql> {
    # Given Q12107 language, get all properties and values
    wd:Q12107 ?predicate ?object .
  }
}
... Loading ...

Language LL Qid (d:Q12107) → Language data, Literals

This query has been UPDATED to work on Commons SPARQL Endpoint.

#defaultEndpoint:Commons
SELECT * WHERE {
  SERVICE <https://query.wikidata.org/sparql> {
    # Given Q12107 'Breton language', get only literals
    wd:Q12107 ?predicate ?object .
    ?predicate rdf:type owl:DatatypeProperty .
  }
}
... Loading ...

Language LL Qid (d:Q12107) → Property P220 (ISO 639-3)

This query has been UPDATED to work on Commons SPARQL Endpoint.

#defaultEndpoint:Commons
SELECT * WHERE {
  SERVICE <https://query.wikidata.org/sparql> {
    wd:Q12107 wdt:P220 ?iso . # Assign value : Q209 'Breton', P13 'ISO 639-3', value into ?iso
  }
}
... Loading ...

Languages → List existing languages' iso-639-3

This query has been UPDATED to work on Commons SPARQL Endpoint.

#defaultEndpoint:Commons
SELECT * WHERE {
  SERVICE <https://query.wikidata.org/sparql> {
    ?lang wdt:P220 ?code .
  }
}
... Loading ...

🇶 Language WD Qid → Language data, core

This query is going to be DEPRECATED as the queried data will no longer be available.

#defaultEndpoint:Lingualibre
SELECT * WHERE {
  ?lang prop:P12 "Q12107" .  # Filter: P12 'Wikidata id' is Wikidata's "Q12107"
  ?lang ?predicate ?object . # 
  ?predicate rdf:type owl:DatatypeProperty .
}
... Loading ...

Records

Record LL Qid (sdc:M69288741) → Record data, all

This query has been UPDATED to work on Commons SPARQL Endpoint.

#defaultEndpoint:Commons
SELECT * WHERE {
  sdc:M69288741 ?predicate ?object .
}
... Loading ...

Record LL Qid (sdc:M69288741) → Record data, core

This query has been UPDATED to work on Commons SPARQL Endpoint.

#defaultEndpoint:Commons
SELECT * WHERE {
  sdc:M69288741 ?predicate ?object .

  SERVICE <https://query.wikidata.org/sparql> {
    ?predicate rdf:type owl:DatatypeProperty . 
  } 
}
... Loading ...

Language (d:Q1860) + String → Record LL Qid(s)

This query has been UPDATED to work on Commons SPARQL Endpoint.

#defaultEndpoint:Commons
SELECT ?item
WHERE { 
  ?item wdt:P31 wd:Q108167708 . # Filter: P31 'instance of' Q108167708 'record'
  ?item wdt:P407 wd:Q1860 .     # Filter: P407 'language' is Q1860 'English'
  ?item wdt:P9533 "apple"@en.   # Filter: P9533 'transcription' is "apple"
}
... Loading ...

Language (d:Q12107) + Speaker (/speakers/1 ??) + String (ni) → Record LL Qid

This query is IN WORK for Commons SPARQL Endpoint. One Wikidata property is missing; please update this query with the right property URI.

Case: Search in Breton language, with speaker 'ThonyVezbe',

SELECT ?audio ?urlPointer
WHERE {
  ?audio wdt:P407 wd:Q12107 ;                                                # P407 'language' is Q12107 'Breton'
         wdt:SPEAKER_PROPERTY_MISSING <https://lingualibre.org/speakers/1> ; # ??? 'speaker' is ll.org/speakers/1 'ThonyVezbe'
         wdt:P9533 "ni"@br ;
         schema:url ?urlPointer .
}
... Loading ...

Language (d:Q150) + Speaker (/speakers/1 ??) + String → URL pointer, filename

This query is IN WORK for Commons SPARQL Endpoint. One Wikidata property is missing; please update this query with the right property URI.

SELECT ?audio ?urlPointer
  (REPLACE(REPLACE(REPLACE(SUBSTR(STR(?urlPointer),52),"%20","_"),"%28","("),"%29",")") AS ?filename)
WHERE {
  ?audio wdt:P407 wd:Q150 ;                                                   # Filter: P407 'language' is Q150 'French'
         wdt:SPEARKER_PROPERTY_MISSING <https://lingualibre.org/speakers/1> ; # Filter: ??? 'speaker' is ll.org/speakers/1 'Aemines1'
         wdt:P9533 "pomme"@fr ; # Filter: P9533 'audio transcription' of "pomme" in French
         schema:url ?urlPointer # Bind the URI to the file to ?urlPointer
}
... Loading ...

Files on Commons about records in Punjabi with transcription and LinguaLibre identifier

#defaultEndpoint:Commons
SELECT * WHERE {
  ?m wdt:P31 wd:Q108167708 ; #record
     wdt:P407 wd:Q58635 ; #in Punjabi
     wdt:P9533 ?transcription ; #with transcription
     wdt:P10369 ?idLili . #with LinguaLibre identifier
}
LIMIT 100

🇶 Count records by gender of the speaker (P8)

SELECT ?genderLabel (count(?record) AS ?nb)
WHERE {
  ?record prop:P2 entity:Q2 ;
          prop:P5 ?speaker .
  ?speaker prop:P2 entity:Q3 ;
           prop:P8 ?gender .
  # Add labels to each variable used.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" . } 
}
GROUP BY ?genderLabel
... Loading ...

Heavy queries

Queries below are too large to run on LinguaLibre's wikipages, or even on Lingualibre Query Service).
To do: do smaller sub-queries, with one COUNT() function.

❌ Languages → Name, Wikidata Qid, LLQid, Iso-639-3, and genders

Query Result
#defaultEndpoint:Lingualibre
SELECT ?languageQidLabel ?wdQid ?languageQid ?isoCode 
(COUNT(DISTINCT(?record)) AS ?recordCount)
(COUNT(DISTINCT(?speakerLangM)) AS ?speakerM) 
(COUNT(DISTINCT(?speakerLangF)) AS ?speakerF)
wWHERE{
  ?record prop:P2 entity:Q2 .     # Filter: items where P2 'instance of' is Q2 'record'
  ?record prop:P4 ?languageQid .  # Assign value: P4 'language' into variable ?language
  ?languageQid prop:P12 ?wdQid .  # Assign value: P12 'wikidata id' into variable ?WD
  ?languageQid prop:P13 ?isoCode. # Assign value: P13 'iso639-3' into ?isoCode
  
  #?record prop:P5 ?speakerQidM .   # Assign value: P5 'speaker' into variable ?speakerQidM
  #?speakerQidM prop:P8 entity:Q16 .   # Filter: P8 'sex or gender' is Q16 'male
  #?speakerQidM prop:P4 ?speakerLangM .  # Assign value: P4 'language' into variable ?spakerLangM
  
  ?record prop:P5 ?speakerQidF .   # Assign value: P5 'speaker' into variable ?speakerQidF
  ?speakerQidF prop:P8 entity:Q17 .   # Filter: P8 'sex or gender' is Q17 'female
  ?speakerQidF prop:P4 ?speakerLangF .  # Assign value: P4 'language' into variable ?spakerLangF
  
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . } 
}
GROUP BY ?languageQidLabel ?languageQid ?wdQid ?isoCode
ORDER BY DESC(?recordCount)
#defaultEndpoint:Lingualibre
languageQidLabel	wdQid	languageQid	isoCode	recordCount	speakerM	speakerF
French	Q150	Q21	fra	16761	0	18
Marathi	Q1571	Q34	mar	13153	0	5
Polish	Q809	Q298	pol	11686	0	1
…

❌ Is Language (speaker (Q3)) → list all languages with number of unique words and speakers

#defaultEndpoint:Lingualibre
SELECT ?language (COUNT(?audio) AS ?nbAudio) (COUNT(?speaker) AS ?nbSpeaker) WHERE {
  ?language prop:P2 entity:Q4 .
  ?audio prop:P4 ?language .
  ?speaker prop:P4 ?language .
}
GROUP BY ?language

Others

(These old queries are not assessed yet.)

Language (Breton (Q209)) → Record, speaker's language level

#defaultEndpoint:Lingualibre
select ?record ?recordLabel ?speakerLabel ?languageLabel ?languageLevelLabel
where {
  ?record prop:P2 entity:Q2   # Filter: P2 'instance of' is Q2 'record' AND P4
	; prop:P4 entity:Q209 .   # AND P4 'language' is Q209 'Breton'
  ?record prop:P5 ?speaker .  # Assign value: record's P5 'speaker' into ?speaker
  ?record prop:P4 ?language . # Assign value: record's P4 'language' into ?language
  
  ?speaker llp:P4 ?languageStatement .    # P4 'language'
  ?languageStatement llv:P4 ?language .   # P4 'language'
  ?languageStatement llq:P16 ?languageLevel . # P16 'language level'
  # Adds labels
  SERVICE wikibase:label {
    bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
  } 
} ORDER BY ?languageLabel ?languageLevelLabel
... Loading ...

Language (Marathi (Q34)) → Records of Wikidata concepts with WD Qid (P12)

Those items were proposed to Lingualibre's recorder at step 3 via a SPARQL query upon Wikidata, so those words have WD's Qids.
#defaultEndpoint:Lingualibre
SELECT ?languageLabel ?recordLabel ?record ?wid
WHERE {
  ?record prop:P2 entity:Q2 .    # Filter: P2 'instance of' is Q2 'record'
  ?record prop:P4 entity:Q34 .  # Filter: P4 'language' is Q34 'Marathi'
  ?record prop:P4 ?language .    # Assign value: record's P4 'language' to variable ?language
  ?record prop:P12 ?wid .        # Assign value: record's P12 'wikidata id' to variable ?wid
  # Add labels capability
  SERVICE wikibase:label {
    bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
  } 
}
... Loading ...

Records → Filter by date: late 2018

#defaultEndpoint:Lingualibre
SELECT
(COUNT(DISTINCT ?record) AS ?records)
(COUNT(DISTINCT ?speaker) AS ?speakers)
(COUNT(DISTINCT ?language) AS ?languages)
WHERE {
  ?record prop:P2 entity:Q2 .
  ?record prop:P6 ?date .
  ?record prop:P5 ?speaker .
  ?record prop:P4 ?language .
  # Filters:
  FILTER(?date >= "2018-07-01T00:00:00Z"^^xsd:dateTime 
       && ?date < "2019-01-01T00:00:00Z"^^xsd:dateTime)
}
... Loading ...

See also

Lingua Libre technical helps
Template {{Speakers category}} • {{Recommended lists}} • {{To iso 639-2}} • {{To iso 639-3}} • {{Userbox-records}} • {{Bot steps}}
Audio files How to create a frequency list?Convert files formatsDenoise files with SoXRename and mass rename
Bots Help:BotsLinguaLibre:BotHelp:Log in to Lingua Libre with PywikibotLingua Libre Bot (gh) • OlafbotPamputtBotDragons Bot (gh)
MediaWiki MediaWiki: Help:Documentation opérationelle MediawikiHelp:Database structureHelp:CSSHelp:RenameHelp:OAuthLinguaLibre:User rights (rate limit) • Module:Lingua Libre record & {{Lingua Libre record}}JS scripts: MediaWiki:Common.jsLastAudios.jsSoundLibrary.jsItemsSugar.jsLexemeQueriesGenerator.js (pad) • Sparql2data.js (pad) • LanguagesGallery.js (pad) • Gadgets: Gadget-LinguaImporter.jsGadget-Demo.jsGadget-RecentNonAudio.jsLiLiZip.js
Queries Help:APIsHelp:SPARQLSPARQL (intermediate) (stub) • SPARQL for lexemes (stub) • SPARQL for maintenanceLingualibre:Wikidata (stub) • Help:SPARQL (HAL)
Reuses Help:Download datasetsHelp:Embed audio in HTML
Unstable & tests Help:SPARQL/test
Categories Category:Technical reports