def test_generate_parent_list_vector_with_2_polarites(): amr_str = """(a / and~e.0 :op2 (p2 / practice-01~e.13 :ARG1 (l / loan-01~e.12 :ARG2 (p / person~e.11 :ARG0-of~e.11 (s / study-01~e.11))) :mod (s2 / sane~e.10 :polarity~e.10 -~e.10) :ARG1-of (i2 / identical-01~e.16 :ARG2~e.19 (p3 / practice-01~e.24 :ARG1 (l2 / loan-01~e.23 :ARG1 (m / mortgage-01~e.22)) :mod (s3 / sane~e.21 :polarity~e.21 -~e.21)) :manner (w / way~e.18 :mod (e / every~e.18))) :ARG0-of (c2 / cause-01~e.3,8 :ARG1 (b / be-located-at-91~e.5,7 :ARG1 (t / they~e.4) :ARG2 (t2 / there~e.6)) :mod (o / only~e.2))))""" amr: AMR = AMR.parse_string(amr_str) identified_concepts = IdentifiedConcepts() identified_concepts.create_from_amr('amr_2_polarities', amr) add_false_root(identified_concepts) generated_parent_list_vector = generate_parent_list_vector( amr, identified_concepts) # a o c2 t b t2 - s2 s p l p2 i2 e w - s3 m l2 p3 # 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 expected_parent_list_vector = [[-1], [0], [3], [12], [5], [3], [5], [8], [12], [10], [11], [12], [1], [12], [15], [13], [17], [20], [19], [20], [13]] assertion_message = str(generated_parent_list_vector) + ' should be' + str( expected_parent_list_vector) assert generated_parent_list_vector == expected_parent_list_vector, assertion_message
def test_pre_and_post_processing_eg_2(): sentence = 'It is Santorum that is the by far major nonRomney candidate and Newt would appear to be the spoiler .' amr_str = """(a / and~e.11 :op1 (c / candidate~e.10 :ARG1-of (m / major-02~e.8 :degree (b / by-far~e.6,7)) :mod (p3 / person~e.9 :polarity -~e.9 :wiki "Mitt_Romney"~e.9 :name (n2 / name~e.9 :op1 "Romney"~e.9)) :domain~e.1,4 (p2 / person :wiki "Rick_Santorum" :name (n / name :op1 "Santorum"~e.2))) :op2 (a2 / appear-02~e.14 :ARG1 (s / spoil-01~e.18 :ARG0 (p4 / person :wiki "Newt_Gingrich" :name (n3 / name :op1 "Newt"~e.12)))))""" amr: AMR = AMR.parse_string(amr_str) amr, new_sentence, metadata = train_pre_processing(amr, sentence) identified_concepts = IdentifiedConcepts() identified_concepts.create_from_amr('', amr) add_false_root(identified_concepts) vector_of_parents = generate_parent_list_vector(amr, identified_concepts) post_processing_on_parent_vector(identified_concepts, vector_of_parents, new_sentence, metadata) relations_dict = { ('and', 'candidate'): 'op1', ('and', 'appear-02'): 'op2', ('candidate', 'major-02'): 'ARG1-of', ('candidate', 'person'): 'mod', ('major-02', 'by-far'): 'degree', ('person', '-'): 'polarity', ('person', 'Mitt_Romney'): 'wiki', ('person', 'name'): 'name', ('person', 'Santorum'): 'wiki', ('name', 'Romney'): 'op1', ('name', 'Santorum'): 'op1', ('appear-02', 'spoil-01'): 'ARG1', ('spoil-01', 'person'): 'ARG0', ('person', 'Newt'): 'wiki', ('name', 'Newt'): 'op1' } amr_node: Node = generate_amr_node_for_vector_of_parents( identified_concepts, vector_of_parents, relations_dict) generated_amr_str = amr_node.amr_print_with_reentrancy() expected_amr_str = """(a / and~e.11 :op1 (c / candidate~e.10 :ARG1-of (m / major-02~e.8 :degree (b / by-far~e.6,7)) :mod (p3 / person~e.9 :polarity -~e.9 :wiki "Mitt_Romney"~e.9 :name (n2 / name~e.9 :op1 "Romney"~e.9)) :mod~e.1,4 (p2 / person :wiki "Santorum" :name (n / name :op1 "Santorum"~e.2))) :op2 (a2 / appear-02~e.14 :ARG1 (s / spoil-01~e.18 :ARG0 (p4 / person :wiki "Newt" :name (n3 / name :op1 "Newt"~e.12)))))""" smatch = calculate_smatch(generated_amr_str, expected_amr_str) assert smatch == 1
def test_generate_amr_node_for_vector_of_parents_example_1(): amr_str = """(s / suppose-01~e.1 :ARG0 (i / i~e.0) :ARG1 (p / possible-01~e.3 :ARG1 (a / add-02~e.4 :ARG0 (y / you~e.2) :ARG1 (p2 / probation~e.5 :ARG1-of (c / contrast-01~e.7 :ARG2 (r / replace-01~e.12 :ARG1 p2 :ARG2~e.13 (t / time~e.15 :mod (j / jail~e.14)) :mod (j2 / just~e.10)))))))""" amr_str1 = """(d1 / suppose-01~e.1 :ARG0 (i / i~e.0) :ARG1 (p / possible-01~e.3 :ARG1 (a / add-02~e.4 :ARG0 (y / you~e.2) :ARG1 (p2 / probation~e.5 :ARG1-of (c / contrast-01~e.7 :ARG2 (r / replace-01~e.12 :ARG1 p2 :mod (j2 / just~e.10) :ARG2~e.13 (t / time~e.15 :mod (j / jail~e.14)) ))))))""" amr: AMR = AMR.parse_string(amr_str) identified_concepts = IdentifiedConcepts() identified_concepts.create_from_amr('amr_1', amr) add_false_root(identified_concepts) vector_of_parents = generate_parent_list_vector(amr, identified_concepts) # transf parent vectors to vector of parents # i s y p a p2 c j2 r j t # 1 2 3 4 5 6 7 8 9 10 11 relations_dict = { ('suppose-01', 'i'): 'ARG0', ('suppose-01', 'possible-01'): 'ARG1', ('possible-01', 'add-02'): 'ARG1', ('add-02', 'you'): 'ARG0', ('add-02', 'probation'): 'ARG1', ('probation', 'contrast-01'): 'ARG1-of', ('contrast-01', 'replace-01'): 'ARG2', ('replace-01', 'probation'): 'ARG1', ('replace-01', 'time'): 'ARG2', ('replace-01', 'just'): 'mod', ('time', 'jail'): 'mod' } amr_node: Node = generate_amr_node_for_vector_of_parents( identified_concepts, vector_of_parents, relations_dict) generated_amr_str = amr_node.amr_print_with_reentrancy() smatch = calculate_smatch(generated_amr_str, amr_str) assert smatch == 1
def test_create_from_amr_example_reentrancy(): amr_str = """(r / receive-01~e.4 :ARG0 (w / we~e.0) :ARG1 (t / thing~e.7 :ARG0-of~e.7 (r2 / remind-01~e.7 :ARG1 (p / pay-01~e.6 :ARG0 w) :ARG2 w)) :ARG2~e.8 (h / hospital~e.10) :time (n / now~e.2) :time (a / already~e.3))""" amr = AMR.parse_string(amr_str) generated_concepts = IdentifiedConcepts() generated_concepts.create_from_amr('amr_id_reentrancy', amr) expected_concepts = IdentifiedConcepts() expected_concepts.amr_id = 'amr_id_reentrancy' expected_concepts.ordered_concepts = [ Concept('w', 'we'), Concept('n', 'now'), Concept('a', 'already'), Concept('r', 'receive-01'), Concept('p', 'pay-01'), Concept('r2', 'remind-01'), Concept('t', 'thing'), Concept('h', 'hospital') ] assert_identified_concepts(expected_concepts, generated_concepts)
def is_ok(self, filter_params: CustomizedAMRFilterParams): sentence = filter_params.sentence custom_amr = filter_params.custom_amr amr_id = filter_params.amr_id identified_concepts = IdentifiedConcepts() identified_concepts.create_from_amr(amr_id, custom_amr.amr_graph) # if I can't put in order all the concepts: if identified_concepts.ordered_concepts is None: return None # empty AMR, don't care about it, should not be many: if len(identified_concepts.ordered_concepts) == 0: return False return True
def test_create_from_amr_example_2(): amr_str = """(a / and~e.0 :op2 (p / possible-01~e.8 :ARG1 (a3 / avoid-01~e.10 :ARG0 (h / he~e.7) :ARG1 (c / censure-01~e.12 :ARG1 h)) :ARG1-of (a2 / actual-02~e.9) :manner (p2 / promise-01~e.5 :polarity~e.2 -~e.2 :ARG0 h :mod (a4 / any~e.4))))""" amr = AMR.parse_string(amr_str) custom_amr = CustomizedAMR() custom_amr.create_custom_AMR(amr) generated_concepts = IdentifiedConcepts() generated_concepts.create_from_amr('amr_id_2', amr) expected_concepts = IdentifiedConcepts() expected_concepts.amr_id = 'amr_id_2' expected_concepts.ordered_concepts = [ Concept('a', 'and'), Concept('-', '-', 0), Concept('a4', 'any'), Concept('p2', 'promise-01'), Concept('h', 'he'), Concept('p', 'possible-01'), Concept('a2', 'actual-02'), Concept('a3', 'avoid-01'), Concept('c', 'censure-01') ] assert_identified_concepts(expected_concepts, generated_concepts)
def test_post_processing_on_parent_vector(): sentence = 'Comrade PERSON once said that the Communist Party will not be overthrown - ' \ 'if it falls , it will be brought down from within the party itself .' metadata = {1: ['Deng', 'Xiaoping']} identified_concepts = IdentifiedConcepts() identified_concepts.ordered_concepts = [Concept('', 'ROOT'), Concept('c', 'comrade'), Concept('h', 'have-org-role-91'), Concept('p', 'PERSON'), Concept('o', 'once'), Concept('s', 'say-01'), Concept('p2', 'political-party'), Concept('Communist_Party_of_China', 'Communist_Party_of_China'), Concept('n2', 'name'), Concept('Communist', 'Communist'), Concept('Party', 'Party'), Concept('-', '-'), Concept('o', 'overthrow-01'), Concept('a', 'and'), Concept('f', 'fall-05'), Concept('b', 'bring-down'), Concept('p3', 'person'), Concept('h2', 'have-org-role-91') ] vector_of_parents = [[-1], [2], [3], [5], [5], [0], [12, 14, 15, 16, 17], [6], [6], [8], [8], [12], [13], [5], [15], [13], [15], [16]] post_processing_on_parent_vector(identified_concepts, vector_of_parents, sentence, metadata) expected_ordered_concepts = [Concept('', 'ROOT'), Concept('c', 'comrade'), Concept('h', 'have-org-role-91'), Concept('p', 'person'), Concept('o', 'once'), Concept('s', 'say-01'), Concept('p2', 'political-party'), Concept('Communist_Party_of_China', 'Communist_Party_of_China'), Concept('n2', 'name'), Concept('Communist', 'Communist'), Concept('Party', 'Party'), Concept('-', '-'), Concept('o', 'overthrow-01'), Concept('a', 'and'), Concept('f', 'fall-05'), Concept('b', 'bring-down'), Concept('p3', 'person'), Concept('h2', 'have-org-role-91'), Concept('Deng_Xiaoping', 'Deng_Xiaoping'), Concept('', 'name'), Concept('Deng', 'Deng'), Concept('Xiaoping', 'Xiaoping') ] expected_vector_of_parents = [[-1], [2], [3], [5], [5], [0], [12, 14, 15, 16, 17], [6], [6], [8], [8], [12], [13], [5], [15], [13], [15], [16], [3], [3], [19], [19]] assert identified_concepts.ordered_concepts == expected_ordered_concepts assert vector_of_parents == expected_vector_of_parents
def test_generate_parent_vector_example_2(): amr_str = """(m / man~e.2 :ARG1-of (m2 / marry-01~e.1) :ARG0-of (l / love-01~e.9 :ARG1~e.10 (y / you~e.11) :ARG1-of (r / real-04~e.6) :condition-of~e.4 (a3 / and~e.16 :op1 (g / go-06~e.14 :ARG2 (a / ahead~e.15) :mod (j / just~e.13)) :op2 (o2 / or~e.22 :op1 (f / file-01~e.17 :ARG4~e.18 (d / divorce-01~e.19) :time (n / now~e.20)) :op2 (m3 / move-01~e.25 :ARG2 (o / out-06~e.26 :ARG2~e.27 (h / house~e.29 :poss~e.28 m~e.28)) :time n~e.30 :mod (a2 / at-least~e.23,24))))))""" amr: AMR = AMR.parse_string(amr_str) identified_concepts = IdentifiedConcepts() identified_concepts.ordered_concepts = [ Concept('', 'ROOT'), # 0 Concept('m2', 'marry-01'), # 1 Concept('m', 'man'), # 2 Concept('r', 'real-04'), # 3 Concept('l', 'love-01'), # 4 Concept('y', 'you'), # 5 Concept('j', 'just'), # 6 Concept('g', 'go-06'), # 7 Concept('a', 'ahead'), # 8 Concept('a3', 'and'), # 9 Concept('f', 'file-01'), # 10 Concept('d', 'divorce-01'), # 11 Concept('n', 'now'), # 12 Concept('o2', 'or'), # 13 Concept('a2', 'at-least'), # 14 Concept('m3', 'move-01'), # 15 Concept('o', 'out-06'), # 16 Concept('h', 'house') # 17 ] generated_parent_vector = generate_parent_vectors(amr, identified_concepts, 2) expected_parent_vector = [ (-1, 2, 0, 4, 2, 4, 7, 9, 7, 4, 13, 10, 10, 9, 15, 13, 15, 16), (-1, 2, 0, 4, 2, 4, 7, 9, 7, 4, 13, 10, 15, 9, 15, 13, 15, 16) ] assert_parent_vectors(expected_parent_vector, generated_parent_vector)
def test_generate_parent_vector_example_2(): amr_str = """(r / recommend-01~e.1 :ARG1 (a / advocate-01~e.4 :ARG1 (i / it~e.0) :manner~e.2 (v / vigorous~e.3)))""" amr: AMR = AMR.parse_string(amr_str) identified_concepts = IdentifiedConcepts() identified_concepts.ordered_concepts = [ Concept('', 'ROOT'), Concept('i', 'it'), Concept('r', 'recommend-01'), Concept('v', 'vigorous'), Concept('a', 'advocate-01') ] generated_parent_vector = generate_parent_vectors(amr, identified_concepts) expected_parent_vector = [[-1, 4, 0, 4, 2]] assert_parent_vectors(expected_parent_vector, generated_parent_vector)
def test_generate_dataset_entry(): amr_str = """(r / recommend-01~e.1 :ARG1 (a / advocate-01~e.4 :ARG1 (i / it~e.0) :manner~e.2 (v / vigorous~e.3)))""" sentence = """It should be vigorously advocated .""" generated_entry: ArcsTrainingEntry = generate_dataset_entry('amr_id', amr_str, sentence, 0, 1, False, False) expected_identified_concepts = IdentifiedConcepts() expected_identified_concepts.amr_id = 'amr_id' expected_identified_concepts.ordered_concepts = [Concept('', 'ROOT'), Concept('i', 'it'), Concept('r', 'recommend-01'), Concept('v', 'vigorous'), Concept('a', 'advocate-01')] expected_parent_vectors = [(-1, 4, 0, 4, 2)] assert_identified_concepts(expected_identified_concepts, generated_entry.identified_concepts) assert_parent_vectors(expected_parent_vectors, generated_entry.parent_vectors)
def test_generate_parent_list_vector_ex_1(): amr_str = """(r / recommend-01~e.1 :ARG1 (a / advocate-01~e.4 :ARG1 (i / it~e.0) :manner~e.2 (v / vigorous~e.3)))""" amr = AMR.parse_string(amr_str) identified_concepts = IdentifiedConcepts() identified_concepts.create_from_amr('amr_id_1', amr) add_false_root(identified_concepts) generated_parent_list_vector = generate_parent_list_vector( amr, identified_concepts) # i r v a # 1 2 3 4 expected_parent_list_vector = [[-1], [4], [0], [4], [2]] assertion_message = str(generated_parent_list_vector) + ' should be' + str( expected_parent_list_vector) assert generated_parent_list_vector == expected_parent_list_vector, assertion_message
def test_generate_parent_list_vector_with_polarity(): amr_str = """(y2 / year~e.4 :time-of~e.5 (r / recover-01~e.7 :ARG1-of (e / expect-01~e.6 :polarity -~e.6)) :ARG1-of (p / possible-01~e.1) :domain~e.2 (d / date-entity~e.4 :year~e.4 2012~e.0))""" amr: AMR = AMR.parse_string(amr_str) identified_concepts = IdentifiedConcepts() identified_concepts.create_from_amr('amr_polarity', amr) add_false_root(identified_concepts) generated_parent_list_vector = generate_parent_list_vector( amr, identified_concepts) # 2012 p d y2 - e r # 1 2 3 4 5 6 7 expected_parent_list_vector = [[-1], [3], [4], [4], [0], [6], [7], [4]] assertion_message = str(generated_parent_list_vector) + ' should be' + str( expected_parent_list_vector) assert generated_parent_list_vector == expected_parent_list_vector, assertion_message
def test_generate_parent_list_vector_reentrancy_ex_2(): amr_str = """(f / foolish~e.3 :mode~e.7 interrogative~e.7 :domain~e.0,2 (i / i~e.1) :condition~e.4 (d / do-02~e.5 :ARG0 i :ARG1 (t / this~e.6)))""" amr = AMR.parse_string(amr_str) identified_concepts = IdentifiedConcepts() identified_concepts.create_from_amr('amr_2_reentrancy', amr) add_false_root(identified_concepts) generated_parent_list_vector = generate_parent_list_vector( amr, identified_concepts) # i f d t interogative # 1 2 3 4 5 expected_parent_list_vector = [[-1], [3, 2], [0], [2], [3], [2]] assertion_message = str(generated_parent_list_vector) + ' should be' + str( expected_parent_list_vector) assert generated_parent_list_vector == expected_parent_list_vector, assertion_message
def test_pre_and_post_processing_for_organization(): sentence = 'Some propaganda activities of ZF have soon become viewed as jokes by the people .' amr_str = """(b / become-01~e.7 :ARG1 a :ARG2 (v / view-02~e.8 :ARG0~e.11 (p2 / person~e.13) :ARG1 (a / activity-06~e.2 :ARG0~e.3 (o / organization :wiki ZF :name (n / name :op1 "ZF"~e.4)) :ARG1 (p / propaganda~e.1) :quant (s / some~e.0)) :ARG2~e.9 (t / thing~e.10 :ARG2-of~e.10 (j / joke-01~e.10))) :time~e.9 (s2 / soon~e.6))""" amr: AMR = AMR.parse_string(amr_str) amr, new_sentence, metadata = train_pre_processing(amr, sentence) identified_concepts = IdentifiedConcepts() identified_concepts.create_from_amr('', amr) add_false_root(identified_concepts) vector_of_parents = generate_parent_list_vector(amr, identified_concepts) post_processing_on_parent_vector(identified_concepts, vector_of_parents, new_sentence, metadata) relations_dict = { ('become-01', 'activity-06'): 'ARG1', ('become-01', 'view-02'): 'ARG2', ('become-01', 'soon'): 'time', ('view-02', 'person'): 'ARG0', ('view-02', 'activity-06'): 'ARG1', ('view-02', 'thing'): 'ARG2', ('activity-06', 'organization'): 'ARG0', ('activity-06', 'propaganda'): 'ARG1', ('activity-06', 'some'): 'quant', ('organization', 'ZF'): 'wiki', ('organization', 'name'): 'name', ('name', 'ZF'): 'op1', ('thing', 'joke-01'): 'ARG2-of' } amr_node: Node = generate_amr_node_for_vector_of_parents( identified_concepts, vector_of_parents, relations_dict) generated_amr_str = amr_node.amr_print_with_reentrancy() smatch = calculate_smatch(generated_amr_str, amr_str) assert smatch == 1
def test_generate_parent_list_vector_reentrancy_ex_3(): amr_str = """(c2 / convince-01~e.1 :ARG0 (i / i~e.0) :ARG1~e.2 (s / she~e.2) :concession-of~e.4 (s2 / shallow~e.10 :ARG1-of (c / conviction-02~e.6 :ARG0~e.5 i~e.5 :ARG2 c2)))""" amr = AMR.parse_string(amr_str) identified_concepts = IdentifiedConcepts() identified_concepts.create_from_amr('amr_3_reentrancy', amr) add_false_root(identified_concepts) generated_parent_list_vector = generate_parent_list_vector( amr, identified_concepts) # c2 s i c s2 # 1 2 3 4 5 expected_parent_list_vector = [[-1], [0, 4], [1], [4, 1], [5], [1]] assertion_message = str(generated_parent_list_vector) + ' should be' + str( expected_parent_list_vector) assert generated_parent_list_vector == expected_parent_list_vector, assertion_message
def test_generate_parent_vector(): amr: AMR = AMR() amr.roots = ['r'] amr.reentrance_triples = [] amr.node_to_concepts = {'i': 'it', 'v': 'vigorous', 'a': 'advocate-01', 'r': 'recommend-01'} amr.node_to_tokens = {'i': ['0'], 'v': ['3'], 'a': ['4'], 'r': ['1']} amr.relation_to_tokens = {'manner': [('2', 'a')]} amr['i'] = {} amr['v'] = {} amr['a'] = {'ARG1': [('i',)], 'manner': [('v',)]} amr['r'] = {'ARG1': [('a',)]} identified_concepts = IdentifiedConcepts() identified_concepts.ordered_concepts = [Concept('', 'ROOT'), Concept('i', 'it'), Concept('r', 'recommend-01'), Concept('v', 'vigorous'), Concept('a', 'advocate-01')] generated_parent_vector = generate_parent_vectors(amr, identified_concepts, 1) expected_parent_vector = [(-1, 4, 0, 4, 2)] assert_parent_vectors(expected_parent_vector, generated_parent_vector)
def test_create_from_amr_example_4(): amr_str = """(i / intensify-01~e.7 :li~e.0 -1~e.0 :ARG1 (c / contradiction~e.3) :ARG0-of (m / make-02~e.9 :ARG1 (c2 / control-01~e.12,13,14 :polarity - :ARG1 (s / situation~e.11))) :ARG1-of (b / bind-02~e.5))""" amr = AMR.parse_string(amr_str) generated_concepts = IdentifiedConcepts() generated_concepts.create_from_amr('amr_id_3', amr) expected_concepts = IdentifiedConcepts() expected_concepts.amr_id = 'amr_id_3' # return None as not all concepts are aligned + unalignment tolerance is default (0) expected_concepts.ordered_concepts = None assert_identified_concepts(expected_concepts, generated_concepts)
def test_create_from_custom_amr_example_1(): amr: AMR = AMR() amr.node_to_concepts = {'i': 'it', 'v': 'vigorous', 'a': 'advocate-01', 'r': 'recommend-01'} amr.node_to_tokens = {'i': ['0'], 'v': ['3'], 'a': ['4'], 'r': ['1']} amr.relation_to_tokens = {'manner': [('2', 'a')]} amr['i'] = {} amr['v'] = {} amr['a'] = {'ARG1': [('i',)], 'manner': [('v',)]} amr['r'] = {'ARG1': [('a',)]} generated_concepts = IdentifiedConcepts() generated_concepts.create_from_amr('amr_id_1', amr) expected_concepts = IdentifiedConcepts() expected_concepts.amr_id = 'amr_id_1' expected_concepts.ordered_concepts = [Concept('i', 'it'), Concept('r', 'recommend-01'), Concept('v', 'vigorous'), Concept('a', 'advocate-01')] assert_identified_concepts(expected_concepts, generated_concepts)
def test__create_from_amr_with_2_polarites(): amr_str = """(a / and~e.0 :op2 (p2 / practice-01~e.13 :ARG1 (l / loan-01~e.12 :ARG2 (p / person~e.11 :ARG0-of~e.11 (s / study-01~e.11))) :mod (s2 / sane~e.10 :polarity~e.10 -~e.10) :ARG1-of (i2 / identical-01~e.16 :ARG2~e.19 (p3 / practice-01~e.24 :ARG1 (l2 / loan-01~e.23 :ARG1 (m / mortgage-01~e.22)) :mod (s3 / sane~e.21 :polarity~e.21 -~e.21)) :manner (w / way~e.18 :mod (e / every~e.18))) :ARG0-of (c2 / cause-01~e.3,8 :ARG1 (b / be-located-at-91~e.5,7 :ARG1 (t / they~e.4) :ARG2 (t2 / there~e.6)) :mod (o / only~e.2))))""" amr: AMR = AMR.parse_string(amr_str) generated_concepts = IdentifiedConcepts() generated_concepts.create_from_amr('amr_2_polarities', amr) expected_concepts = IdentifiedConcepts() expected_concepts.amr_id = 'amr_2_polarities' expected_concepts.ordered_concepts = [ Concept('a', 'and'), Concept('o', 'only'), Concept('c2', 'cause-01'), Concept('t', 'they'), Concept('b', 'be-located-at-91'), Concept('t2', 'there'), Concept('-', '-', 0), Concept('s2', 'sane'), Concept('s', 'study-01'), Concept('p', 'person'), Concept('l', 'loan-01'), Concept('p2', 'practice-01'), Concept('i2', 'identical-01'), Concept('e', 'every'), Concept('w', 'way'), Concept('-', '-', 1), Concept('s3', 'sane'), Concept('m', 'mortgage-01'), Concept('l2', 'loan-01'), Concept('p3', 'practice-01') ] assert_identified_concepts(expected_concepts, generated_concepts)
def test_generate_parent_list_vector_reentrancy(): amr_str = """(r / receive-01~e.4 :ARG0 (w / we~e.0) :ARG1 (t / thing~e.7 :ARG0-of~e.7 (r2 / remind-01~e.7 :ARG1 (p / pay-01~e.6 :ARG0 w) :ARG2 w)) :ARG2~e.8 (h / hospital~e.10) :time (n / now~e.2) :time (a / already~e.3))""" amr = AMR.parse_string(amr_str) identified_concepts = IdentifiedConcepts() identified_concepts.create_from_amr('amr_2_polarities', amr) add_false_root(identified_concepts) generated_parent_list_vector = generate_parent_list_vector( amr, identified_concepts) # w n a r p r2 t h # 1 2 3 4 5 6 7 8 expected_parent_list_vector = [[-1], [5, 6, 4], [4], [4], [0], [6], [7], [4], [4]] assertion_message = str(generated_parent_list_vector) + ' should be' + str( expected_parent_list_vector) assert generated_parent_list_vector == expected_parent_list_vector, assertion_message
def test_create_from_amr_example_1(): amr_str = """(r / recommend-01~e.1 :ARG1 (a / advocate-01~e.4 :ARG1 (i / it~e.0) :manner~e.2 (v / vigorous~e.3)))""" amr = AMR.parse_string(amr_str) generated_concepts = IdentifiedConcepts() generated_concepts.create_from_amr('amr_id_1', amr) expected_concepts = IdentifiedConcepts() expected_concepts.amr_id = 'amr_id_1' expected_concepts.ordered_concepts = [ Concept('i', 'it'), Concept('r', 'recommend-01'), Concept('v', 'vigorous'), Concept('a', 'advocate-01') ] assert_identified_concepts(expected_concepts, generated_concepts)
def test_create_from_amr_example_3(): amr_str = """(d / difficult~e.5 :domain~e.4 (r / reach-01~e.7 :ARG1 (c / consensus~e.0 :topic~e.1 (c2 / country :wiki "India" :name (n / name :op1 "India"~e.2))) :time~e.8 (m / meet-03~e.11 :ARG0 (o / organization :wiki "Nubolt12_632_6421.19clear_Suppliers_Group" :name (n2 / name :op1 "NSG"~e.10)) :time~e.12 (d2 / date-entity :year 2007~e.14 :month~e.13 11~e.13))))""" amr = AMR.parse_string(amr_str) generated_concepts = IdentifiedConcepts() generated_concepts.create_from_amr('amr_id_3', amr) expected_concepts = IdentifiedConcepts() expected_concepts.amr_id = 'amr_id_3' # return None as not all concepts are aligned + unalignment tolerance is default (0) expected_concepts.ordered_concepts = None assert_identified_concepts(expected_concepts, generated_concepts)
def test_generate_amr_node_for_vector_of_parents(): identified_concepts: IdentifiedConcepts = IdentifiedConcepts() identified_concepts.ordered_concepts = [Concept('', 'ROOT'), # 0 Concept('i', 'it'), # 1 Concept('r', 'recommend-01'), # 2 Concept('v', 'vigorous'), # 3 Concept('a', 'advocate-01') # 4 ] predicted_vector_of_parents = [[-1], [4], [0], [4], [2]] relations_dict = { ('recommend-01', 'advocate-01'): 'ARG1', ('advocate-01', 'it'): 'ARG1', ('advocate-01', 'vigorous'): 'manner' } amr: Node = generate_amr_node_for_vector_of_parents(identified_concepts, predicted_vector_of_parents, relations_dict) generated_amr_str = amr.amr_print_with_reentrancy() gold_amr_str = """(r / recommend-01~e.1 :ARG1 (a / advocate-01~e.4 :ARG1 (i / it~e.0) :manner~e.2 (v / vigorous~e.3)))""" smatch = calculate_smatch(generated_amr_str, gold_amr_str) assert smatch == 1