Untested code to get labels from wikidata in all languages.
This commit is contained in:
parent
836098461e
commit
308d462e76
@ -1,7 +1,7 @@
|
|||||||
# generate a list of wikidata entities related to keywords
|
# generate a list of wikidata entities related to keywords
|
||||||
from os import path
|
from os import path
|
||||||
from sys import stdout
|
from sys import stdout
|
||||||
from wikidata_api_calls import search_wikidata
|
from wikidata_api_calls import search_wikidata, get_wikidata_api
|
||||||
|
|
||||||
class Wikidata_ResultSet(object):
|
class Wikidata_ResultSet(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -13,7 +13,7 @@ class Wikidata_ResultSet(object):
|
|||||||
|
|
||||||
def to_csv(self, outfile=None):
|
def to_csv(self, outfile=None):
|
||||||
|
|
||||||
header = ','.join(['search_term', 'entityid', 'pageid', 'search_position','timestamp'])
|
header = ','.join(['search_term', 'entityid', 'pageid', 'search_position','timestamp']) + '\n'
|
||||||
if outfile is None:
|
if outfile is None:
|
||||||
of = stdout
|
of = stdout
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
# File defines functions for making api calls to find translations and transliterations for key terms.
|
# File defines functions for making api calls to find translations and transliterations for key terms.
|
||||||
|
|
||||||
import mwapi
|
import mwapi
|
||||||
|
import requests
|
||||||
import sys
|
import sys
|
||||||
sys.path.append("..")
|
|
||||||
from defaults import user_agent
|
from defaults import user_agent
|
||||||
|
|
||||||
def get_wikidata_api():
|
def get_wikidata_api():
|
||||||
@ -27,3 +27,7 @@ def search_wikidata(session, term, *args, **kwargs):
|
|||||||
raise mwapi.session.APIError(f"No results for query: {term}")
|
raise mwapi.session.APIError(f"No results for query: {term}")
|
||||||
|
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
def run_sparql_query(q):
|
||||||
|
results = requests.get("https://query.wikidata.org/bigdata/namespace/wdq/sparql?query={q}&format=json")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user