예제 #1
0
class TestTexts(unittest.TestCase):

    #  TODO : more tests on texts
    def setUp(self):
        self.rand_gen = RandomPoolIEMLObjectGenerator(level=SuperSentence)

    def test_text_ordering_simple(self):
        """Just checks that elements created in a text are ordered the right way"""
        word = self.rand_gen.word()
        sentence, supersentence = self.rand_gen.sentence(
        ), self.rand_gen.super_sentence()
        text = Text([supersentence, sentence, word])

        self.assertIsInstance(text.children[0], Word)
        self.assertIsInstance(text.children[1], Sentence)
        self.assertIsInstance(text.children[2], SuperSentence)
예제 #2
0
    def test_random(self):
        r = RandomPoolIEMLObjectGenerator(level=Sentence)
        s = r.sentence()
        p = path("s+a+m + (s+a+m):(r+f)")
        elems = resolve(s, p)
        self.assertSetEqual(
            elems,
            {p
             for p in s.tree_iter() if isinstance(p, (Word, Morpheme))})

        p = path("t + t:(s+a+m+r+f+(s+a+m):(s+a+m+r+f+(s+a+m):(r+f)))")
        usl = random_usl(rank_type=Text)
        elems = resolve(usl.ieml_object, p)
        self.assertSetEqual(
            set(e for e in usl.ieml_object.tree_iter()
                if not isinstance(e, (Text, SuperClause, Clause, SyntaxTerm))),
            elems)
예제 #3
0
class TestSuperSentence(unittest.TestCase):

    def setUp(self):
        self.rnd_gen = RandomPoolIEMLObjectGenerator(Sentence)

    def test_supersentence_creation(self):
        a, b, c, d, e, f = tuple(self.rnd_gen.sentence() for i in range(6))
        try:
            super_sentence = SuperSentence([SuperClause(a,b,f), SuperClause(a,c,f), SuperClause(b,e,f), SuperClause(b,d,f)])
        except InvalidIEMLObjectArgument as e:
            self.fail()

    def test_hashing(self):
        s = RandomPoolIEMLObjectGenerator(level=SuperSentence).super_sentence()
        h = {s: 1,
             2:3}
        self.assertIn(s, h)
예제 #4
0
class TestText(unittest.TestCase):
    def setUp(self):
        self.gen = RandomPoolIEMLObjectGenerator(Text)

    def test_equality(self):
        text0 = self.gen.text()
        self.assertEqual(text0, Text(text0))

        s0 = self.gen.sentence()
        t1 = Text([text0, s0])
        self.assertIn(s0, t1)
        self.assertIn(text0, t1)

    def test_hashing(self):
        s = RandomPoolIEMLObjectGenerator(level=Text).text()
        h = {s: 1,
             2:3}
        self.assertIn(s, h)
예제 #5
0
class TestPropositionParser(unittest.TestCase):
    def setUp(self):
        self.rand = RandomPoolIEMLObjectGenerator(level=Text)
        self.parser = IEMLParser()

    def test_parse_term(self):

        for i in range(10):
            o = self.rand.term()
            self.assertEqual(self.parser.parse(str(o)), o)

    def test_parse_word(self):
        for i in range(10):
            o = self.rand.word()
            self.assertEqual(self.parser.parse(str(o)), o)

    def test_parse_term_plus(self):
        t = term("f.-O:M:.+M:O:.-s.y.-'")
        to_check = ieml("[f.-O:M:.+M:O:.-s.y.-']")
        self.assertEqual(to_check, SyntaxTerm(t))

    def test_parse_sentence(self):
        for i in range(10):
            o = self.rand.sentence()
            self.assertEqual(self.parser.parse(str(o)), o)

    def test_parse_super_sentence(self):
        for i in range(10):
            o = self.rand.word()
            self.assertEqual(self.parser.parse(str(o)), o)

    def test_parse_text(self):
        for i in range(10):
            o = self.rand.text()
            self.assertEqual(self.parser.parse(str(o)), o)

    def test_literals(self):
        w1 = str(self.rand.word()) + "<la\la\>lal\>fd>"
        w2 = str(self.rand.word()) + "<@!#$#@%{}\>fd>"
        self.assertEqual(str(self.parser.parse(w1)), w1)
        self.assertEqual(str(self.parser.parse(w2)), w2)
        s1 = '[(' + '*'.join(
            (w1, w2, str(self.rand.word()))) + ')]' + "<!@#$%^&*()_+\<>"
        self.assertEqual(str(self.parser.parse(s1)), s1)
        ss1 = '[(' + '*'.join((s1, str(
            self.rand.sentence()), str(self.rand.sentence()))) + ')]<opopop>'
        self.assertEqual(str(self.parser.parse(ss1)), ss1)

    def test_invalid_term(self):
        with self.assertRaises(CannotParse):
            self.parser.parse("[([A:A:A:.-'])]")

        with self.assertRaises(TermNotFoundInDictionary):
            term("A:A:A:.")

    def test_multiple_ieml_parser(self):
        p0 = IEMLParser()
        p1 = IEMLParser()
        self.assertEqual(p0, p1)

        p2 = IEMLParser(Dictionary('dictionary_2017-06-07_00:00:00'))
        self.assertNotEqual(p0, p2)

        p3 = IEMLParser(from_version='dictionary_2017-06-07_00:00:00')
        self.assertNotEqual(p2, p3)

    def test_parse_script(self):
        self.assertEqual(str(self.parser.parse("A:")), '[A:]')

    def test_threading(self):
        pool = ThreadPool(4)
        results = pool.map(self.parser.parse, Dictionary().version.terms)
        self.assertSetEqual(
            {str(t)
             for t in results},
            {'[{0}]'.format(str(t))
             for t in Dictionary().version.terms})

        results = pool.map(script, Dictionary().version.terms)
        self.assertSetEqual({str(t)
                             for t in results},
                            set(Dictionary().version.terms))
예제 #6
0
 def test_rank(self):
     r = RandomPoolIEMLObjectGenerator(level=Text)
     self.assertEqual(r.word().__class__.syntax_rank(), 2)
     self.assertEqual(r.sentence().__class__.syntax_rank(), 4)
     self.assertEqual(r.super_sentence().__class__.syntax_rank(), 6)
     self.assertEqual(r.text().__class__.syntax_rank(), 7)