Skip to content

Instantly share code, notes, and snippets.

@dpriskorn
Forked from salgo60/getSAOB.py
Created December 27, 2020 07:49
Show Gist options
  • Save dpriskorn/c064db7b5fd2ee0dc06c001e72dbfd1f to your computer and use it in GitHub Desktop.
Save dpriskorn/c064db7b5fd2ee0dc06c001e72dbfd1f 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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment