Skip to content

Instantly share code, notes, and snippets.

@salgo60
Created December 26, 2020 23:26
Show Gist options
  • Save salgo60/56c1a898bc215297cdbb92ccf668ddef to your computer and use it in GitHub Desktop.
Save salgo60/56c1a898bc215297cdbb92ccf668ddef to your computer and use it in GitHub Desktop.
import requests
file = open("saob2020.csv", "r")
def createQSurl(SAOBid):
# https: // quickstatements.toolforge.org / # /v1=L349183%7CP8478%7C%22A_0787-0228.n0A3%22
urlbase = "https://quickstatements.toolforge.org/#/v1=LEXEME"
urlP8478 = f"%7CP8478%7C%22{SAOBid.strip()}%22"
return urlbase + urlP8478
def main():
print("start")
for x in file:
word = x.split(",")[1]
wordtype = x.split(",")[2]
wordSAOB = x.split(",")[4]
SAOBid = wordSAOB.replace("https://svenska.se/saob/?id=","").replace("&pz=5","")
# https://svenska.se/saob/?id=A_0001-0018.TWNA&pz=5
if wordtype == "subst":
print(wordtype, word, wordSAOB.strip())
print ("\t",createQSurl(SAOBid))
params = dict (
action='wbsearchentities',
format='json',
language='sv',
uselang='sv',
type='lexeme',
search=word
)
response = requests.get('https://www.wikidata.org/w/api.php?', params).json()
for l in response.get('search'):
print(l)
language = l['match']['language']
if language == "sv":
id = l['id']
url = "http:" + l['url']
label = l['label']
print("\t",id,url,label,language,"\n")
if __name__ == '__main__':
main()
@salgo60
Copy link
Author

salgo60 commented Dec 26, 2020

Exempel output

/usr/local/bin/python3.8 /Users/magnus/Documents/GitHub/wordlistSAOB/clientSAOB.py
start
subst ab https://svenska.se/saob/?id=A_0001-0005.nmG7&pz=5
https://quickstatements.toolforge.org/#/v1=LEXEME%7CP8478%7C%22A_0001-0005.nmG7%22
{'id': 'L13362', 'title': 'Lexeme:L13362', 'pageid': 56104628, 'repository': 'wikidata', 'url': '//www.wikidata.org/wiki/Lexeme:L13362', 'concepturi': 'http://www.wikidata.org/entity/L13362', 'label': 'ab', 'description': 'latin, preposition', 'match': {'type': 'label', 'language': 'la', 'text': 'ab'}}
{'id': 'L42601', 'title': 'Lexeme:L42601', 'pageid': 61565605, 'repository': 'wikidata', 'url': '//www.wikidata.org/wiki/Lexeme:L42601', 'concepturi': 'http://www.wikidata.org/entity/L42601', 'label': 'ab', 'description': 'danska, preposition', 'match': {'type': 'label', 'language': 'da', 'text': 'ab'}}
{'id': 'L302433', 'title': 'Lexeme:L302433', 'pageid': 95013263, 'repository': 'wikidata', 'url': '//www.wikidata.org/wiki/Lexeme:L302433', 'concepturi': 'http://www.wikidata.org/entity/L302433', 'label': 'ab', 'description': 'tyska, preposition', 'match': {'type': 'label', 'language': 'de', 'text': 'ab'}}
{'id': 'L245638', 'title': 'Lexeme:L245638', 'pageid': 84153230, 'repository': 'wikidata', 'url': '//www.wikidata.org/wiki/Lexeme:L245638', 'concepturi': 'http://www.wikidata.org/entity/L245638', 'label': 'ab', 'description': 'Äynu, substantiv', 'match': {'type': 'label', 'language': 'und', 'text': 'ab'}}
{'id': 'L30576', 'title': 'Lexeme:L30576', 'pageid': 57228843, 'repository': 'wikidata', 'url': '//www.wikidata.org/wiki/Lexeme:L30576', 'concepturi': 'http://www.wikidata.org/entity/L30576', 'label': 'aby', 'description': 'polska, konjunktion', 'match': {'type': 'label', 'language': 'pl', 'text': 'aby'}}
{'id': 'L30577', 'title': 'Lexeme:L30577', 'pageid': 57228849, 'repository': 'wikidata', 'url': '//www.wikidata.org/wiki/Lexeme:L30577', 'concepturi': 'http://www.wikidata.org/entity/L30577', 'label': 'aby', 'description': 'polska, partikel', 'match': {'type': 'label', 'language': 'pl', 'text': 'aby'}}
{'id': 'L7879', 'title': 'Lexeme:L7879', 'pageid': 55787699, 'repository': 'wikidata', 'url': '//www.wikidata.org/wiki/Lexeme:L7879', 'concepturi': 'http://www

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment