Ejemplo n.º 1
0
from pydmrs.pydelphin_interface import parse
from pydmrs.matching.query import dmrs_query


if __name__ == '__main__':

    # basic functionality
    dmrs_list = [parse('A mouse ate the whole cheese.')[0],
                 parse('Lions eat around 15 zebras per year.')[0],
                 parse('Their children eat so many sweets.')[0],
                 parse('Potatoes are mostly eaten by humans.')[0]]
    search_dmrs = '_?1_?_?_rel i <-1- _eat_v_1_rel e? -2-> _?2_?_?_rel i'

    # not dict, not per dmrs
    results = list(dmrs_query(dmrs_list, search_dmrs, results_as_dict=False, results_per_dmrs=False))
    assert len(results) == 4
    assert ('mouse', 'cheese') in results
    assert ('lion', 'zebra') in results
    assert ('child', 'sweet') in results
    assert ('human', 'potato') in results
    # dict, not per dmrs
    results = list(dmrs_query(dmrs_list, search_dmrs, results_as_dict=True, results_per_dmrs=False))
    assert len(results) == 4
    assert {'1': 'mouse', '2': 'cheese'} in results
    assert {'1': 'lion', '2': 'zebra'} in results
    assert {'1': 'child', '2': 'sweet'} in results
    assert {'1': 'human', '2': 'potato'} in results
    # not dict, per dmrs
    results = list(dmrs_query(dmrs_list, search_dmrs, results_as_dict=False, results_per_dmrs=True))
    assert len(results) == 4 and all(isinstance(result, list) for result in results)
    assert ('mouse', 'cheese') in results[0]
Ejemplo n.º 2
0
                 replace_dmrs,
                 copy_dmrs=False,
                 iterative=True,
                 all_matches=False)
    assert 'A dog chases the cat.' in generate(dmrs)
    # iterative, all
    dmrs = examples.the_dog_chases_the_cat()
    dmrs_mapping(dmrs,
                 search_dmrs,
                 replace_dmrs,
                 copy_dmrs=False,
                 iterative=True,
                 all_matches=True)
    assert 'A dog chases a cat.' in generate(dmrs)

    dmrs = parse('Kim eats and Kim sleeps.')[0]
    search_dmrs = parse_graphlang(
        '[4]:node=1 <-1- [2]:node <-l- [1]:_and_c e? -r-> [3]:node -1-> node=1 <-- proper_q; :2 <-lh- :1 -rh-> :3'
    )
    replace_dmrs = parse_graphlang(
        '[4]:node <-1- [2]:node <-l- [1]:_and_c e? -r-> [3]:node -1-> :4; :2 <=lh= :1 =rh=> :3'
    )
    dmrs_mapping(dmrs, search_dmrs, replace_dmrs, copy_dmrs=False)
    assert 'Kim eats and sleeps.' in generate(dmrs)

    # some examples inspired by examples from the AMR specification

    dmrs = parse('He described the mission as a failure.')[0]
    search_dmrs = parse_graphlang(
        '[2]:node <-2- *[1]:_describe_v_as e? -3-> [3]:node')
    replace_dmrs = parse_graphlang(
Ejemplo n.º 3
0
from pydmrs.pydelphin_interface import parse
from pydmrs.matching.query import dmrs_query

if __name__ == '__main__':

    # basic functionality
    dmrs_list = [
        parse('A mouse ate the whole cheese.')[0],
        parse('Lions eat around 15 zebras per year.')[0],
        parse('Their children eat so many sweets.')[0],
        parse('Potatoes are mostly eaten by humans.')[0]
    ]
    search_dmrs = '_?1_?_?_rel i <-1- _eat_v_1_rel e? -2-> _?2_?_?_rel i'

    # not dict, not per dmrs
    results = list(
        dmrs_query(dmrs_list,
                   search_dmrs,
                   results_as_dict=False,
                   results_per_dmrs=False))
    assert len(results) == 4
    assert ('mouse', 'cheese') in results
    assert ('lion', 'zebra') in results
    assert ('child', 'sweet') in results
    assert ('human', 'potato') in results
    # dict, not per dmrs
    results = list(
        dmrs_query(dmrs_list,
                   search_dmrs,
                   results_as_dict=True,
                   results_per_dmrs=False))
Ejemplo n.º 4
0
    # not iterative, not all
    assert 'A dog chases the cat.' in generate(dmrs_mapping(dmrs, search_dmrs, replace_dmrs, copy_dmrs=True, iterative=False, all_matches=False))
    # original dmrs did not change so far
    assert 'The dog chases the cat.' in generate(dmrs)
    # iterative, not all
    dmrs = examples.the_dog_chases_the_cat()
    dmrs_mapping(dmrs, search_dmrs, replace_dmrs, copy_dmrs=False, iterative=True, all_matches=False)
    assert 'A dog chases the cat.' in generate(dmrs)
    # iterative, all
    dmrs = examples.the_dog_chases_the_cat()
    dmrs_mapping(dmrs, search_dmrs, replace_dmrs, copy_dmrs=False, iterative=True, all_matches=True)
    assert 'A dog chases a cat.' in generate(dmrs)



    dmrs = parse('Kim eats and Kim sleeps.')[0]
    search_dmrs = parse_graphlang('[4]:node=1 <-1- [2]:node <-l- [1]:_and_c e? -r-> [3]:node -1-> node=1 <-- proper_q; :2 <-lh- :1 -rh-> :3')
    replace_dmrs = parse_graphlang('[4]:node <-1- [2]:node <-l- [1]:_and_c e? -r-> [3]:node -1-> :4; :2 <=lh= :1 =rh=> :3')
    dmrs_mapping(dmrs, search_dmrs, replace_dmrs, copy_dmrs=False)
    assert 'Kim eats and sleeps.' in generate(dmrs)


    # some examples inspired by examples from the AMR specification

    dmrs = parse('He described the mission as a failure.')[0]
    search_dmrs = parse_graphlang('[2]:node <-2- *[1]:_describe_v_as e? -3-> [3]:node')
    replace_dmrs = parse_graphlang('pronoun_q --> pron x[3sn_s] <-2- [1]:_describe_v_to e? <-2h- *_as_x_subord e[pui--] -1h-> _be_v_id e[ppi--] -1-> [2]:node; :_be_v_id -2-> [3]:node')
    dmrs_mapping(dmrs, search_dmrs, replace_dmrs, copy_dmrs=False)
    assert 'As he described it, the mission is a failure.' in generate(dmrs)
    dmrs_mapping(dmrs, replace_dmrs, search_dmrs, copy_dmrs=False)
    assert 'He described the mission as a failure.' in generate(dmrs)