def test_resolve(self):
        word = topic([ieml('wa.')])
        p = path('r0')
        elems = resolve(word, p)
        self.assertSetEqual(elems, {ieml('wa.')})

        worda = topic([ieml('wu.')])
        wordm = topic([ieml('we.')])

        s = fact([(word, worda, wordm)])
        p = path('sa:r')
        elems = resolve(s, p)
        self.assertSetEqual(elems, {ieml('wu.')})

        p = path('sa0+s0+sm0')
        elems = resolve(s, p)
        self.assertSetEqual(elems, {word, wordm, worda})


        t = text([s, word])
        p = path('t')
        elems = resolve(t, p)
        self.assertSetEqual(elems, {s, word})
        p = path('t1')
        elems = resolve(t, p)
        self.assertSetEqual(elems, {s})
 def setUp(self):
     self.morpheme_a = [
         term("E:A:T:."),
         term("E:.S:.wa.-"),
         term("E:.-S:.o.-t.-'")
     ]
     self.morpheme_b = [term("a.i.-"), term("i.i.-")]
     self.word_a = topic(self.morpheme_a, self.morpheme_b)
     self.word_b = topic(
         [term("E:A:T:."),
          term("E:.-S:.o.-t.-'"),
          term("E:.S:.wa.-")], [term("a.i.-"), term("i.i.-")])
 def test_topics_reordering(self):
     morpheme_a = [
         term("E:A:T:."),
         term("E:.-S:.o.-t.-'"),
         term("E:.S:.wa.-")
     ]
     morpheme_b = [
         term("E:A:T:."),
         term("E:.S:.wa.-"),
         term("E:.-S:.o.-t.-'")
     ]
     self.assertTrue(topic(morpheme_a) == topic(morpheme_b))
 def test_topics_hashing(self):
     """Verifies words can be used as keys in a hashmap"""
     new_word = topic(
         [term("E:A:T:."),
          term("E:.-S:.o.-t.-'"),
          term("E:.S:.wa.-")])
     word_hashmap = {new_word: 1, self.word_a: 2}
     self.assertTrue(self.word_b in word_hashmap)
    def test_deference(self):
        rand = RandomPoolIEMLObjectGenerator()
        w0 = rand.topic()

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

        w0 = topic([w0['r0']])

        self.assertEqual(w0['f'], w0.flexing)
    def test_rules(self):
        rules0 = [(path('r0'), ieml('wa.'))]
        obj = resolve_ieml_object(*zip(*rules0))
        self.assertEqual(obj, topic([ieml('wa.')]))

        rules1 = [(path('r1'), ieml('wa.')), (path('r'), ieml('I:')), (path('f0'), ieml('we.'))]
        obj = resolve_ieml_object(*zip(*rules1))
        word1 = topic([ieml('I:'), ieml('wa.')], [ieml('we.')])
        self.assertEqual(obj, word1)

        self.assertEqual(resolve_ieml_object(enumerate_paths(obj)), obj)

        r = RandomPoolIEMLObjectGenerator(level=Text)
        t = r.text()
        self.assertEqual(t, resolve_ieml_object(enumerate_paths(t)))

        rules = [(path('r1'), ieml('wa.')), (path('r'), ieml('I:')), (path('f0'), ieml('we.'))]
        obj = resolve_ieml_object(*zip(*rules))
        self.assertEqual(obj, topic([ieml('I:'), ieml('wa.')], [ieml('we.')]))
Example #7
0
def get_topics_list():
    #this list is already sorted
    terms_list = [
        term("E:A:T:."),
        term("E:.S:.wa.-"),
        term("E:.-S:.o.-t.-'"),
        term("a.i.-"),
        term("i.i.-"),
        term("u.M:M:.-")
    ]

    # a small yield to check the word before returning it :-°
    for t in terms_list:
        word_obj = topic([t])
        yield word_obj
 def test_topics_with_different_substance_comparison(self):
     word_a, word_b = topic(self.morpheme_a), topic(self.morpheme_b)
     # true because term("E:A:T:.") < term("a.i.-")
     self.assertTrue(word_a < word_b)
    def test_invalid_creation(self):
        def test(rules, expected=None):
            if expected:
                try:
                    usl(rules)
                except IEMLObjectResolutionError as e:
                    self.assertListEqual(e.errors, expected)
                else:
                    self.fail()
            else:
                with self.assertRaises(IEMLObjectResolutionError):
                    usl(rules)

        # missing node definition on sm0
        test([('s:r', ieml('[we.]')),('sa0:r', ieml('[wa.]'))],
             [('s0m0', "Missing node definition.")])

        # empty rules
        test([],
             [('', "Missing node definition.")])

        # multiple def for a node
        test([('r0', ieml('[wa.]')), ('r0', ieml('[we.]'))],
             [('r0', 'Multiple definition, multiple ieml object provided for the same node.')])

        # missing index on text
        test([('t:r', ieml('[we.]')),('t2:r', ieml('[wa.]'))],
             [('', "Index missing on text definition.")])

        # missing index on word
        test([('r2', ieml('[we.]')),('r', ieml('[wa.]'))],
             [('', "Index missing on topic definition.")])

        test([('s:r', ieml('[wa.]')), ('sm:r', ieml('[we.]')), ('sa1:r', ieml('[wu.]'))],
             [('s0a0', 'Missing node definition.')])

        # incompatible path
        test([('t:r', ieml('[wa.]')), ('s:f', ieml('[we.]'))],
             [('', 'No definition, no type inferred on rules list.')])


        # mulitple errors
        test([("t0:s:f0", ieml('[wa.]')), ("t0:sa:r", ieml('[a.]')), ('t2:r', ieml('[we.]')), ("t0:sm1", topic([ieml('[wu.]')]))],
             [('t0:s0', 'No root for the topic node.'),
             ('t0:s0m0', 'Missing node definition.'),
             ('t1', 'Missing node definition.')])