Checking the language code for Wikimedia

I have a shell script that uses the Wikidata Query Service (WDQS) to get the required data. In the SPARQL query that runs WDQS, the language code of the input parameters is entered.

Is there a way to check the script shell if the input language code is a valid Wikimedia language code as the first column data in the link below https://www.wikidata.org/wiki/Help:Wikimedia_language_codes/lists/all

+1
source share
1 answer

These codes are possible values wdt:P424. From the offer:

- ISO 639-1?
- , ISO, . , , . , (als: ISO: tosk albanian, Wikimedia: Alemannic).

, SPARQL:

SELECT DISTINCT ?code { [] wdt:P424 ?code } ORDER BY ?code

!

, , , . is:

SELECT ?item ?c
(CONCAT("{","{#language:",?c,"}","}") as ?display)
(CONCAT("{","{#language:",?c,"|","en}","}") as ?displayEN)
(CONCAT("{","{#language:",?c,"|","fr}","}") as ?displayFR)
{
  ?item wdt:P424 ?c .
  MINUS{?item wdt:P31/wdt:P279* wd:Q14827288} #--exclude Wikimedia projects
  MINUS{?item wdt:P31/wdt:P279* wd:Q17442446} #--exclude Wikimedia internal stuff
}

:

  • script
  • script
  • ASK SPARQL .

:

#!/bin/sh
echo "Enter language code:"
read code
request="curl -g -s https://query.wikidata.org/sparql?query=ASK{?lang%20wdt:P424%20\"$code\"}"

if $request | grep -q "true"; then
    echo "Valid code";
else 
    echo "Invalid code";
fi
+2

Source: https://habr.com/ru/post/1686696/


All Articles