Skip to content
Snippets Groups Projects
Commit 681c18d9 authored by wesenberg's avatar wesenberg
Browse files

amr_error

parent f42e5cde
No related branches found
No related tags found
No related merge requests found
from wesenberg import util, smatch
from wesenberg.DataAnalytics import DataAnalytics
from wesenberg.DataResults import DataResults
from wesenberg.util import get_amr_match_new
INT_SMATCH_SOURCE_SUMMARY = "1"
INT_SMATCH_GOLD_SUMMARY = "2"
......@@ -58,7 +59,7 @@ def calc_one_smatch(graph_source, graph_summary):
T is the total number of triples in the first AMR
G is the total number of triples in the second AMR"""
smatch.match_triple_dict = {}
smatch_pred = smatch.get_amr_match(cur_amr1=graph_source, cur_amr2=graph_summary)
smatch_pred = get_amr_match_new(cur_amr1=graph_source, cur_amr2=graph_summary)
return smatch_pred
......
This diff is collapsed.
from os.path import exists
import random
import os
from statistics import median, stdev, variance
import re
......@@ -11,9 +10,12 @@ import spacy
import pickle
import amr
from smatch import get_best_match
from wesenberg.Konstanten import LIST_SYMBOLS_TO_DELETE, ROOT_PATH, AMRLIB_PATH, \
LIST_MODEL_NAME, LOAD_SPARCY, ROUGE_TYPES, DIVIDER_PATH, BACKUP_SMATCH_ERROR_PATH, SAFE_SMATCH_ERROR, \
AMR_ERROR_PATH, SAFE_AMR_ERROR, GTOS_MODEL
AMR_ERROR_PATH, SAFE_AMR_ERROR
def remove_bugs(sentence):
......@@ -425,3 +427,56 @@ def safe_reward_list(path, name, safe_list, step, n=-1):
tmp += "Reward:\t\t" + str(reward) + '\n'
tmp += '\n'
txt.write(tmp)
def get_amr_match_new(cur_amr1, cur_amr2, sent_num=1, justinstance=False, justattribute=False, justrelation=False):
amr_pair = []
for i, cur_amr in (1, cur_amr1), (2, cur_amr2):
try:
amr_pair.append(amr.AMR.parse_AMR_line(cur_amr))
except Exception as e:
print("Error in parsing amr %d: %s" % (i, cur_amr))
print("Please check if the AMR is ill-formatted. Ignoring remaining AMRs")
print("Error message: %s" % e)
amr1, amr2 = amr_pair
prefix1 = "a"
prefix2 = "b"
# Rename node to "a1", "a2", .etc
amr1.rename_node(prefix1)
# Renaming node to "b1", "b2", .etc
amr2.rename_node(prefix2)
(instance1, attributes1, relation1) = amr1.get_triples()
(instance2, attributes2, relation2) = amr2.get_triples()
attributes1 = list(set(attributes1))
relation1 = list(set(relation1))
attributes2 = list(set(attributes2))
relation2 = list(set(relation2))
# optionally turn off some of the node comparison
doinstance = doattribute = dorelation = True
if justinstance:
doattribute = dorelation = False
if justattribute:
doinstance = dorelation = False
if justrelation:
doinstance = doattribute = False
(best_mapping, best_match_num) = get_best_match(instance1, attributes1, relation1,
instance2, attributes2, relation2,
prefix1, prefix2, doinstance=doinstance,
doattribute=doattribute, dorelation=dorelation)
if justinstance:
test_triple_num = len(instance1)
gold_triple_num = len(instance2)
elif justattribute:
test_triple_num = len(attributes1)
gold_triple_num = len(attributes2)
elif justrelation:
test_triple_num = len(relation1)
gold_triple_num = len(relation2)
else:
test_triple_num = len(instance1) + len(attributes1) + len(relation1)
gold_triple_num = len(instance2) + len(attributes2) + len(relation2)
return best_match_num, test_triple_num, gold_triple_num
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