示例#1
0
def paraphrase(dmrs_iter, paraphrases):
    """
    """
    for dmrs in dmrs_iter:
        assert isinstance(dmrs, Dmrs), 'Object in dmrs_iter is not a Dmrs.'
        for (search_dmrs, replace_dmrs) in paraphrases:
            dmrs_mapping(dmrs, search_dmrs, replace_dmrs, equalities=!!!, copy_dmrs=False)
        yield dmrs
示例#2
0
def paraphrase(dmrs, paraphrases, hierarchy=None):
    """
    """
    assert isinstance(dmrs, Dmrs), 'Object in dmrs_iter is not a Dmrs.'
    for (search_dmrs, replace_dmrs) in paraphrases:
        paraphrased_dmrs = dmrs_mapping(dmrs,
                                        search_dmrs,
                                        replace_dmrs,
                                        hierarchy=hierarchy)
        if paraphrased_dmrs is None:
            break
        else:
            dmrs = paraphrased_dmrs
    return dmrs
示例#3
0
from pydmrs.mapping.mapping import dmrs_mapping
from pydmrs.graphlang.graphlang import parse_graphlang
import examples.examples_dmrs as examples

if __name__ == '__main__':

    # basic functionality
    dmrs = examples.the_dog_chases_the_cat()
    search_dmrs = parse_graphlang('[1]:_the_q')
    replace_dmrs = parse_graphlang('[1]:_a_q')

    # iterative, all
    assert 'A dog chases a cat.' in generate(
        dmrs_mapping(dmrs,
                     search_dmrs,
                     replace_dmrs,
                     copy_dmrs=True,
                     iterative=True,
                     all_matches=True))
    # not iterative, all
    assert all(sent in sents for sent, sents in zip(
        ['A dog chases the cat.', 'The dog chases a cat.'], [
            generate(dmrs) for dmrs in dmrs_mapping(dmrs,
                                                    search_dmrs,
                                                    replace_dmrs,
                                                    copy_dmrs=True,
                                                    iterative=False,
                                                    all_matches=True)
        ]))
    # iterative, not all
    assert 'A dog chases the cat.' in generate(
        dmrs_mapping(dmrs,
示例#4
0
from pydmrs.pydelphin_interface import parse, generate
from pydmrs.mapping.mapping import dmrs_mapping
from pydmrs.graphlang.graphlang import parse_graphlang
import examples.examples_dmrs as examples


if __name__ == '__main__':

    # basic functionality
    dmrs = examples.the_dog_chases_the_cat()
    search_dmrs = parse_graphlang('[1]:_the_q')
    replace_dmrs = parse_graphlang('[1]:_a_q')

    # iterative, all
    assert 'A dog chases a cat.' in generate(dmrs_mapping(dmrs, search_dmrs, replace_dmrs, copy_dmrs=True, iterative=True, all_matches=True))
    # not iterative, all
    assert all(sent in sents for sent, sents in zip(['A dog chases the cat.', 'The dog chases a cat.'], [generate(dmrs) for dmrs in dmrs_mapping(dmrs, search_dmrs, replace_dmrs, copy_dmrs=True, iterative=False, all_matches=True)]))
    # iterative, not all
    assert 'A dog chases the cat.' in generate(dmrs_mapping(dmrs, search_dmrs, replace_dmrs, copy_dmrs=True, iterative=True, all_matches=False))
    # 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)