Skip to content
Snippets Groups Projects
Commit eb65d48c authored by Albin's avatar Albin
Browse files

Merge branch 'main' of gitlab.liu.se:tdde19-2022-1/codebase into main

parents a94f2ced 1e68d739
No related branches found
No related tags found
No related merge requests found
......@@ -13,7 +13,7 @@ import time
# :)
SPARQL_ENDPOINT = "http://sems-vm-1.informatik.uni-hamburg.de:443/api/endpoint/sparql"
SPARQL_ENDPOINT = "https://dbpedia.org/sparql"
test_data_file = sys.argv[1]
predicted_data_file = sys.argv[2]
......@@ -79,17 +79,24 @@ with open(test_data_file, "r", encoding = "utf-8") as data_f, open(predicted_dat
# if i > 20:
# break
time.sleep(0.5)
data = f"query={next(predicted)[1]}"
time.sleep(0.25)
query = next(predicted)[1]
print("Query: ", query)
print("Real query: ", question["query"]["sparql"])
params = {
"default-graph-uri": "http://dbpedia.org",
"query": query,
"format": "json"
}
# data = data.replace("/", "\/")
# data = data.encode("utf-8")
print(data)
# print(data)
# Escape quotes
# print(data)
try:
response = requests.post(SPARQL_ENDPOINT, headers=headers, data=data, timeout=5)
response = requests.get(SPARQL_ENDPOINT, headers=headers, params=params, timeout=15)
except:
print("Error while querying, probably timeout")
errors += 1
......@@ -98,12 +105,12 @@ with open(test_data_file, "r", encoding = "utf-8") as data_f, open(predicted_dat
# print(response.text)
if (response.status_code == 500):
errors += 1
print("Error", response.json()["message"])
# print("Error", response.json()["message"])
continue
try:
results = response.json()
except:
print("Error when parsing json", response.text)
# print("Error when parsing json", response.text)
errors += 1
continue
# print(results)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment