예제 #1
0
    if not libhfst.HfstTransducer.is_implementation_type_available(type):
        continue

    transducers[type] = []
    compiler = libhfst.XreCompiler(type)
    # compiler.define('Var', 'v a r') TODO

    for regexp in regexps:
        # Print only results from tropical openfst implementation
        if type == libhfst.TROPICAL_OPENFST_TYPE:
            print("{0}".format(regexp))
        # Compile the regexp and append it to the list
        tr = compiler.compile(regexp)
        transducers[type].append(tr)
        # Print only results from tropical openfst implementation
        if type == libhfst.TROPICAL_OPENFST_TYPE:
            print(tr)


# Compare all the transducers with the transducers for tropical openfst type
for type_ind, type_val in enumerate(transducers):
    for tr_ind, tr_val in enumerate(transducers[type_val]):
        # Convert the transducer that we are comparing into tropical openfst format
        tr = libhfst.ptrvalue(transducers[type_val][tr_ind].convert(libhfst.TROPICAL_OPENFST_TYPE))
        # Get the transducer which we are comparing with
        tr_tropical = libhfst.ptrvalue(transducers[libhfst.TROPICAL_OPENFST_TYPE][tr_ind])
        # Compare
        assert(tr.compare(tr_tropical))

예제 #2
0
파일: test_lexc.py 프로젝트: unhammer/hfst3
    compiler = libhfst.LexcCompiler(type)
    compiler.parse("test_lexc.lexc")
    print("")
    parsed = compiler.compileLexical()
    assert(parsed != 0)
    tok = libhfst.HfstTokenizer()
    cat = libhfst.HfstTransducer("cat", tok, type)
    dog = libhfst.HfstTransducer("dog", tok, type)
    mouse = libhfst.HfstTransducer("mouse", tok, type)

    animals = libhfst.HfstTransducer(type)
    animals.disjunct(cat)
    animals.disjunct(dog)
    animals.disjunct(mouse)

    assert(animals.compare(libhfst.ptrvalue(parsed)))
    del(parsed)


    #try:
    #    print(" valid file, read_lexc... ")
    #    rlexc = libhfst.HfstTransducer.read_lexc("test_lexc.lexc", type)
    #    assert(animals.compare(rlexc))
    #except libhfst.FunctionNotImplementedException:
    #    assert(False)


    # (2) A file that does not follow lexc format
    compiler2 = libhfst.LexcCompiler(type)
    print(" invalid file, parse... ")
    compiler2.parse("test_lexc_fail.lexc")
예제 #3
0
    compiler = libhfst.LexcCompiler(type)
    compiler.parse("test_lexc.lexc")
    print("")
    parsed = compiler.compileLexical()
    assert (parsed != 0)
    tok = libhfst.HfstTokenizer()
    cat = libhfst.HfstTransducer("cat", tok, type)
    dog = libhfst.HfstTransducer("dog", tok, type)
    mouse = libhfst.HfstTransducer("mouse", tok, type)

    animals = libhfst.HfstTransducer(type)
    animals.disjunct(cat)
    animals.disjunct(dog)
    animals.disjunct(mouse)

    assert (animals.compare(libhfst.ptrvalue(parsed)))
    del (parsed)

    #try:
    #    print(" valid file, read_lexc... ")
    #    rlexc = libhfst.HfstTransducer.read_lexc("test_lexc.lexc", type)
    #    assert(animals.compare(rlexc))
    #except libhfst.FunctionNotImplementedException:
    #    assert(False)

    # (2) A file that does not follow lexc format
    compiler2 = libhfst.LexcCompiler(type)
    print(" invalid file, parse... ")
    compiler2.parse("test_lexc_fail.lexc")
    parsed = compiler2.compileLexical()
    assert (parsed == None)