コード例 #1
0
 def test_rank(self):
     r = RandomPoolIEMLObjectGenerator(level=Text)
     self.assertEqual(r.word().__class__.syntax_rank(), 1)
     self.assertEqual(r.topic().__class__.syntax_rank(), 2)
     self.assertEqual(r.fact().__class__.syntax_rank(), 3)
     self.assertEqual(r.theory().__class__.syntax_rank(), 4)
     self.assertEqual(r.text().__class__.syntax_rank(), 5)
コード例 #2
0
    def test_deference(self):
        rand = RandomPoolIEMLObjectGenerator()
        w0 = rand.word()

        self.assertEqual(w0['r0'], w0[0][0])
        self.assertEqual(w0['r'], w0[0])

        w0 = Word.from_term(w0['r0'])

        with self.assertRaises(InvalidPathException):
            self.assertEqual(w0['f'], w0[1])
コード例 #3
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)
コード例 #4
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))
コード例 #5
0
ファイル: test_parser.py プロジェクト: IEMLdev/ieml-api
class TestPropositionParser(unittest.TestCase):

    def setUp(self):
        self.rand = RandomPoolIEMLObjectGenerator(level=Theory)
        self.parser = IEMLParser()

    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_topic(self):
        for i in range(10):
            o = self.rand.topic()
            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, Word(t))

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

    def test_parse_super_sentence(self):
        for i in range(10):
            o = self.rand.theory()
            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.topic()) + "<la\la\>lal\>fd>"
        w2 = str(self.rand.topic()) + "<@!#$#@%{}\>fd>"
        self.assertEqual(str(self.parser.parse(w1)), w1)
        self.assertEqual(str(self.parser.parse(w2)), w2)
        s1 = '[('+ '*'.join((w1, w2, str(self.rand.topic()))) +')]' + "<!@#$%^&*()_+\<>"
        self.assertEqual(str(self.parser.parse(s1)), s1)
        ss1 = '[('+ '*'.join((s1, str(self.rand.fact()), str(self.rand.fact()))) + ')]<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)