Skip to content
Snippets Groups Projects
Commit 0426cd7d authored by Ludwig Forsberg's avatar Ludwig Forsberg
Browse files

Required qald-9

parent a5849fa7
No related branches found
No related tags found
No related merge requests found
Source diff could not be displayed: it is too large. Options to address this: view the blob.
This diff is collapsed.
from SPARQLWrapper import SPARQLWrapper, JSON
def query(q):
SPARQL_ENDPOINT = "http://localhost:8890/sparql"
sparql = SPARQLWrapper(SPARQL_ENDPOINT)
sparql.setQuery(q)
sparql.setReturnFormat(JSON)
results1 = sparql.query().convert()
if len(results1['results']['bindings'])==0:
return ""
else:
return results1['results']['bindings'][0]
import sys
import json
from queue import Queue
from threading import Thread
from tqdm import tqdm
import time
import query
data_file = sys.argv[1]
output_file = sys.argv[2]
data = {}
faults = 0
success = 0
empty = 0
class myThread (Thread):
def __init__(self, id):
Thread.__init__(self)
self.id = id
self.start_time = time.time()
def run(self):
global data
global success
global faults
global empty
try:
res = query.query(data['questions'][self.id]["query"]["sparql"])
if res == "":
empty += 1
else:
data['questions'][self.id]["answers"] = res
success += 1
except:
faults += 1
pbar.update(1)
threads = []
with open(data_file, 'r', encoding='utf-8') as json_file:
data = json.load(json_file)
pbar = tqdm(total=len(data['questions']))
for i in range(len(data['questions'])):
threads.append(myThread(i))
for t in threads:
t.start()
for t in threads:
t.join()
pbar.close()
print("Total: ", len(data['questions']))
print("Success: ", success)
print("Faults: ", faults)
print("Empty: ", empty)
with open(output_file, 'w', encoding='utf-8') as output:
json.dump(data, output)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment