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 ...@@ -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] test_data_file = sys.argv[1]
predicted_data_file = sys.argv[2] 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 ...@@ -79,17 +79,24 @@ with open(test_data_file, "r", encoding = "utf-8") as data_f, open(predicted_dat
# if i > 20: # if i > 20:
# break # break
time.sleep(0.5) time.sleep(0.25)
data = f"query={next(predicted)[1]}" 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.replace("/", "\/")
# data = data.encode("utf-8") # data = data.encode("utf-8")
print(data) # print(data)
# Escape quotes # Escape quotes
# print(data) # print(data)
try: try:
response = requests.post(SPARQL_ENDPOINT, headers=headers, data=data, timeout=5) response = requests.get(SPARQL_ENDPOINT, headers=headers, params=params, timeout=15)
except: except:
print("Error while querying, probably timeout") print("Error while querying, probably timeout")
errors += 1 errors += 1
...@@ -98,12 +105,12 @@ with open(test_data_file, "r", encoding = "utf-8") as data_f, open(predicted_dat ...@@ -98,12 +105,12 @@ with open(test_data_file, "r", encoding = "utf-8") as data_f, open(predicted_dat
# print(response.text) # print(response.text)
if (response.status_code == 500): if (response.status_code == 500):
errors += 1 errors += 1
print("Error", response.json()["message"]) # print("Error", response.json()["message"])
continue continue
try: try:
results = response.json() results = response.json()
except: except:
print("Error when parsing json", response.text) # print("Error when parsing json", response.text)
errors += 1 errors += 1
continue continue
# print(results) # print(results)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment