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)
def test_enumerate_paths(self): r = RandomPoolIEMLObjectGenerator(level=Text) t = r.text() e = list(enumerate_paths(t, level=Term)) self.assertSetEqual({t[1] for t in e}, set(e for e in t.tree_iter() if isinstance(e, Term)))
def test_equal(self): t = RandomPoolIEMLObjectGenerator(level=Text).text() t2 = Text(children=t.children) self.assertNotEqual(id(t), id(t2)) self.assertEqual(t, t2) self.assertEqual(t, str(t)) self.assertEqual(str(t), t)
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_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])
def test_random(self): r = RandomPoolIEMLObjectGenerator(level=Fact) s = r.fact() p = path("s+a+m + (s+a+m):(r+f)") elems = resolve(s, p) self.assertSetEqual(elems, s.words.union(s.semes)) 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, p) self.assertSetEqual(usl.facts.union(usl.words).union(usl.semes).union(usl.theories), elems)
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)
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.')]))
def random_usl(dictionary, rank_type=None): global _ieml_object_generator if _ieml_object_generator is None: _ieml_object_generator = RandomPoolIEMLObjectGenerator(dictionary, level=Text, pool_size=100) if rank_type and not isinstance(rank_type, IEMLSyntaxType): raise ValueError( 'The wanted type for the generated usl object must be a IEMLType, here : ' '%s' % rank_type.__class__.__name__) if not rank_type: i = random.randint(0, 10) if i < 4: rank_type = _ieml_objects_types[i] else: rank_type = Text return usl(_ieml_object_generator.from_type(rank_type))
def setUp(self): self.rand_gen = RandomPoolIEMLObjectGenerator(level=SuperSentence)
def __init__(self, **kwargs): self.generator = RandomPoolIEMLObjectGenerator(**kwargs)
def setUp(self): self.rand = RandomPoolIEMLObjectGenerator(level=Text) self.parser = IEMLParser()
def test_hashing(self): s = RandomPoolIEMLObjectGenerator(level=Text).text() h = {s: 1, 2: 3} self.assertIn(s, h)
def setUp(self): self.gen = RandomPoolIEMLObjectGenerator(Text)
def setUp(self): self.rnd_gen = RandomPoolIEMLObjectGenerator(Fact)
def setUp(self): self.rnd_gen = RandomPoolIEMLObjectGenerator(Sentence)
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)
def test_enumerate_paths(self): r = RandomPoolIEMLObjectGenerator(level=Text) t = r.text() e = list(enumerate_paths(t, level=Word)) self.assertSetEqual({t[1] for t in e}, t.words)
def setUp(self): self.rand_gen = RandomPoolIEMLObjectGenerator(level=Theory)
def test_hashing(self): s = RandomPoolIEMLObjectGenerator(level=SuperSentence).super_sentence() h = {s: 1, 2:3} self.assertIn(s, h)
def test_equality(self): ieml = RandomPoolIEMLObjectGenerator(level=Text).text() self.assertEqual(Usl(ieml_object=ieml), Usl(ieml_object=ieml))
def setUp(self): self.d = Dictionary.load() self.rand_gen = RandomPoolIEMLObjectGenerator(self.d, level=Theory)