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
|
||||
from os import path
|
||||
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):
|
||||
def __init__(self):
|
||||
@ -13,7 +13,7 @@ class Wikidata_ResultSet(object):
|
||||
|
||||
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:
|
||||
of = stdout
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
# File defines functions for making api calls to find translations and transliterations for key terms.
|
||||
|
||||
import mwapi
|
||||
import requests
|
||||
import sys
|
||||
sys.path.append("..")
|
||||
from defaults import user_agent
|
||||
|
||||
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}")
|
||||
|
||||
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