Skip to content
Snippets Groups Projects
Commit 47bb60a5 authored by wesenberg's avatar wesenberg
Browse files

17.

parent b1ee3b82
No related branches found
No related tags found
No related merge requests found
......@@ -32,7 +32,7 @@ def calc_smatch_to_r(name, source, summary, graph_source, graph_summary):
smatch_pred = calc_one_smatch(graph_source=graph_source, graph_summary=graph_summary)
if smatch_pred[0] == 0:
if smatch_pred[0] == 0 and smatch_pred[1] != 0:
safe_smatch_error(name=name + "_null", one=source, two=summary, recall=0, precision=None, smatch_pred=smatch_pred,
graph_source=graph_source, graph_summary=graph_summary)
......
......@@ -20,7 +20,7 @@ from wesenberg.Konstanten import LIST_SYMBOLS_TO_DELETE, ROOT_PATH, AMRLIB_PATH,
def remove_bugs(sentence):
sentence = remove_all_hash_for_amr(sentence)
# replace with " " to find and between two removed chars
# replace with " " to find " and " between two removed chars
sentence = remove_single_char_for_amr(sentence, " ")
sentence = remove_minus_for_amr(sentence, " ")
sentence = remove_and_for_amr(sentence)
......@@ -38,7 +38,9 @@ def calc_one_amr(nlp, sentence, file_name):
else:
output = strip_amr_for_smatch(graphs[0])
except IndexError:
return ""
output = ""
safe_amr_error(file_name + "_empty", "", output, sentence)
if SAFE_AMR_ERROR:
output_list = output.split("\n")
......@@ -48,15 +50,21 @@ def calc_one_amr(nlp, sentence, file_name):
if item not in search_list:
search_list.append(item)
else:
path = os.path.join(AMR_ERROR_PATH)
if not os.path.exists(path):
os.makedirs(path)
with open(path + file_name + ".txt", 'a') as txt:
txt.write(sentence + "\n" + item + "\n" + output + "\n\n")
safe_amr_error(file_name, item, output, sentence)
break
return output
def safe_amr_error(file_name, item, output, sentence):
path = os.path.join(AMR_ERROR_PATH)
if not os.path.exists(path):
os.makedirs(path)
if item != "":
item = "\n" + item
with open(path + file_name + ".txt", 'a') as txt:
txt.write(sentence + item + "\n" + output + "\n\n")
def init_amr(stog_name):
amrlib.setup_spacy_extension()
nlp = spacy.load(LOAD_SPARCY)
......@@ -333,7 +341,8 @@ def calc_f_score_smatch(name, one, two, smatch_pred, graph_source, graph_summary
def calc_precision_smatch(name, one, two, smatch_pred, graph_source, graph_summary):
precision = smatch_pred[0] / smatch_pred[1]
if 1 < precision:
safe_smatch_error(name, one, two, None, precision, smatch_pred, graph_source, graph_summary)
safe_smatch_error(name=name, one=one, two=two, result=precision, smatch_pred=smatch_pred,
graph_source=graph_source, graph_summary=graph_summary)
precision = 1
return precision
......@@ -341,27 +350,21 @@ def calc_precision_smatch(name, one, two, smatch_pred, graph_source, graph_summa
def calc_recall_smatch(name, one, two, smatch_pred, graph_source, graph_summary):
recall = smatch_pred[0] / smatch_pred[2]
if 1 < recall:
safe_smatch_error(name=name, one=one, two=two, recall=recall, precision=None, smatch_pred=smatch_pred,
safe_smatch_error(name=name, one=one, two=two, result=recall, smatch_pred=smatch_pred,
graph_source=graph_source, graph_summary=graph_summary)
recall = 1
return recall
def safe_smatch_error(name, one, two, recall, precision, smatch_pred, graph_source, graph_summary):
def safe_smatch_error(name, one, two, result, smatch_pred, graph_source, graph_summary):
if SAFE_SMATCH_ERROR:
path = os.path.join(BACKUP_SMATCH_ERROR_PATH)
if not os.path.exists(path):
os.makedirs(path)
with open(path + name + ".txt", 'a') as txt:
if recall is not None:
txt.write(
"one:\t\t" + one + "\nTwo:\t\t" + two + "\nRecall:\t\t" + str(
recall) + "\nSmatch:\t\t" + str(
smatch_pred) + "\nSource:\n" + graph_source + "\nSummary:\n" + graph_summary + "\n\n")
if precision is not None:
txt.write(
"one:\t\t" + one + "\ntwo:\t\t" + two + "\nPrecision:\t" + str(
precision) + "\nSmatch:\t\t" + str(
"one:\t\t" + one + "\nTwo:\t\t" + two + "\nResult:\t\t" + str(
result) + "\nSmatch:\t\t" + str(
smatch_pred) + "\nSource:\n" + graph_source + "\nSummary:\n" + graph_summary + "\n\n")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment