How to use the smt.decoder.stackdecoder.Phrase function in smt

To help you get started, we’ve selected a few smt examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kenkov / smt / test / test_stackdecoder.py View on Github external
(6, 9): -2.3,
               (7, 7): -1.0,
               (7, 8): -2.2,
               (7, 9): -2.3,
               (8, 8): -1.9,
               (8, 9): -2.4,
               (9, 9): -1.6,
               }

        with DBSetup(db) as dbobj:
            dbobj.session.add_all(TransPhraseProb(lang2p=item[0],
                                                  lang1p=item[1],
                                                  p1_2=item[2],
                                                  p2_1=item[3])
                                  for item in dataset)
            dbobj.session.add_all(Phrase(lang1p=item[0],
                                         lang2p=item[1])
                                  for item in dataset)
            dbobj.session.commit()

            ans = future_cost_estimate(sentences,
                                       transfrom=transfrom,
                                       transto=transto,
                                       init_val=init_val,
                                       db=db)
        # assert
        self.assertEqual(ans, val)
github kenkov / smt / test / test_stackdecoder.py View on Github external
(6, 9): -2.3,
               (7, 7): -1.0,
               (7, 8): -2.2,
               (7, 9): -2.3,
               (8, 8): -1.9,
               (8, 9): -2.4,
               (9, 9): -1.6,
               }

        with DBSetup(db) as dbobj:
            dbobj.session.add_all(TransPhraseProb(lang1p=item[0],
                                                  lang2p=item[1],
                                                  p2_1=item[2],
                                                  p1_2=item[3])
                                  for item in dataset)
            dbobj.session.add_all(Phrase(lang1p=item[0],
                                         lang2p=item[1])
                                  for item in dataset)
            dbobj.session.commit()

            ans = future_cost_estimate(sentences,
                                       transfrom=transfrom,
                                       transto=transto,
                                       init_val=init_val,
                                       db=db)
        # assert
        self.assertEqual(ans, val)
github kenkov / smt / test / test_stackdecoder.py View on Github external
(6, 9): -2.3,
               (7, 7): -1.0,
               (7, 8): -2.2,
               (7, 9): -2.3,
               (8, 8): -1.9,
               (8, 9): -2.4,
               (9, 9): -1.6,
               }

        with DBSetup(db) as dbobj:
            dbobj.session.add_all(TransPhraseProb(lang1p=item[0],
                                                  lang2p=item[1],
                                                  p2_1=item[2],
                                                  p1_2=item[3])
                                  for item in dataset)
            dbobj.session.add_all(Phrase(lang1p=item[0],
                                         lang2p=item[1])
                                  for item in dataset)
            dbobj.session.commit()

            ans = future_cost_estimate(sentences,
                                       transfrom=transfrom,
                                       transto=transto,
                                       init_val=init_val,
                                       db=db)

        # assert
        self.assertEqual(ans, val)
github kenkov / smt / test / test_stackdecoder.py View on Github external
def __init__(self, db="sqlite:///:memory:"):
        self.db = db
        self.tables = [TransPhraseProb, Phrase]
github kenkov / smt / smt / decoder / stackdecoder.py View on Github external
((2, u'is'), (3, u'a')),
         ((3, u'a'),),
         ((4, u'teacher.'),)])
    """
    engine = create_engine(db)
    # create session
    Session = sessionmaker(bind=engine)
    session = Session()
    available = set()
    for i, f in enumerate(inputs):
        f_rest = ()
        for fr in inputs[i:]:
            f_rest += (fr,)
            rest_phrase = u" ".join(f_rest)
            if transfrom == 2 and transto == 1:
                query = session.query(Phrase).filter_by(lang2p=rest_phrase)
            elif transfrom == 1 and transto == 2:
                query = session.query(Phrase).filter_by(lang1p=rest_phrase)
            lst = list(query)
            if lst:
                available.add(tuple(enumerate(f_rest, i+1)))
    return available