How to use smt - 10 common examples

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 c01db33f / concolica / state.py View on Github external
def read(self, address, size):
        if arbitrary(self, address):
            raise ArbitraryRead(self, address)

        as_ = concretise(self, address)
        try:
            if len(as_) > 1:
                e = None
                value = bv.Symbol(size, unique_name('read'))

                for a in as_:
                    v = None
                    for i in range(0, size // 8):
                        if v is None:
                            v = self.memory.read_byte(self, a.value + i)
                        else:
                            v = self.memory.read_byte(self, a.value + i).concatenate(v)

                    if e is None:
                        e = (address == a) & (value == v)
                    else:
                        e = e | ((address == a) & (value == v))

                self.solver.add(e)
            else:
github kenkov / smt / test / test_phrase.py View on Github external
def test_symmetrization(self):
        sentenses = [("僕 は 男 です", "I am a man"),
                     ("私 は 女 です", "I am a girl"),
                     ("私 は 先生 です", "I am a teacher"),
                     ("彼女 は 先生 です", "She is a teacher"),
                     ("彼 は 先生 です", "He is a teacher"),
                     ]
        corpus = mkcorpus(sentenses)
        es = "私 は 先生 です".split()
        fs = "I am a teacher".split()
        syn = symmetrization(es, fs, corpus)
        ans = set([(1, 1), (1, 2), (2, 3), (3, 4), (4, 3)])
        self.assertEqual(syn, ans)
github kenkov / smt / test / test_phrase.py View on Github external
(('that', 'he', 'will', 'stay', 'in', 'the', 'house'),
                    ('dass', 'er', 'im', 'haus', 'bleibt')),
                   (('will', 'stay'), ('bleibt',)),
                   (('will', 'stay', 'in', 'the', 'house'),
                    ('im', 'haus', 'bleibt'))])
        self.assertEqual(phrase_extract(es, fs, alignment), ans)

        # another test
        es, fs = ("私 は 先生 です".split(), "I am a teacher".split())
        sentenses = [("僕 は 男 です", "I am a man"),
                     ("私 は 女 です", "I am a girl"),
                     ("私 は 先生 です", "I am a teacher"),
                     ("彼女 は 先生 です", "She is a teacher"),
                     ("彼 は 先生 です", "He is a teacher"),
                     ]
        corpus = mkcorpus(sentenses)
        alignment = symmetrization(es, fs, corpus)
        ans = set([(('\xe3\x81\xaf',
                     '\xe5\x85\x88\xe7\x94\x9f',
                     '\xe3\x81\xa7\xe3\x81\x99'),
                    ('a', 'teacher')),
                   (('\xe5\x85\x88\xe7\x94\x9f',), ('teacher',)),
                   (('\xe7\xa7\x81',), ('I', 'am')),
                   (('\xe7\xa7\x81',
                     '\xe3\x81\xaf',
                     '\xe5\x85\x88\xe7\x94\x9f',
                     '\xe3\x81\xa7\xe3\x81\x99'),
                    ('I', 'am', 'a', 'teacher'))])
        self.assertEqual(phrase_extract(es, fs, alignment), ans)
github kenkov / smt / test / test_stackdecoder.py View on Github external
(5, 8): -3.6999999999999997,
               (5, 9): -3.6999999999999997,
               (6, 6): -1.0,
               (6, 7): -1.3,
               (6, 8): -2.3,
               (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
(5, 8): -3.6999999999999997,
               (5, 9): -3.6999999999999997,
               (6, 6): -1.0,
               (6, 7): -1.3,
               (6, 8): -2.3,
               (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
(5, 8): -4.6,
               (5, 9): -4.8,
               (6, 6): -1.0,
               (6, 7): -1.3,
               (6, 8): -2.3,
               (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
github kenkov / smt / test / test_phrase.py View on Github external
'er',
                     'im',
                     'haus',
                     'bleibt')),
                   (('that',), (',', 'dass')),
                   (('that',), ('dass',)),
                   (('that', 'he'), (',', 'dass', 'er')),
                   (('that', 'he'), ('dass', 'er')),
                   (('that', 'he', 'will', 'stay', 'in', 'the', 'house'),
                    (',', 'dass', 'er', 'im', 'haus', 'bleibt')),
                   (('that', 'he', 'will', 'stay', 'in', 'the', 'house'),
                    ('dass', 'er', 'im', 'haus', 'bleibt')),
                   (('will', 'stay'), ('bleibt',)),
                   (('will', 'stay', 'in', 'the', 'house'),
                    ('im', 'haus', 'bleibt'))])
        self.assertEqual(phrase_extract(es, fs, alignment), ans)

        # another test
        es, fs = ("私 は 先生 です".split(), "I am a teacher".split())
        sentenses = [("僕 は 男 です", "I am a man"),
                     ("私 は 女 です", "I am a girl"),
                     ("私 は 先生 です", "I am a teacher"),
                     ("彼女 は 先生 です", "She is a teacher"),
                     ("彼 は 先生 です", "He is a teacher"),
                     ]
        corpus = mkcorpus(sentenses)
        alignment = symmetrization(es, fs, corpus)
        ans = set([(('\xe3\x81\xaf',
                     '\xe5\x85\x88\xe7\x94\x9f',
                     '\xe3\x81\xa7\xe3\x81\x99'),
                    ('a', 'teacher')),
                   (('\xe5\x85\x88\xe7\x94\x9f',), ('teacher',)),
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)