def test_categorization_of_atom(self):
     expression = ['foo']
     context = AssociativeSet("*")
     categorized = categorize(expression, context)
     self.assertEqual(
         AssociativeSet("__relation__0").name, categorized.name)
     # We expect a category related to the context we've created and our expression, 'foo'
     self.assertTrue("*" in categorized.contents)
     self.assertTrue("foo" in categorized.contents)
Exemple #2
0
    def test_generate_simple_dump(self):

        filename = "/nml/nextwheel/tests/test.dot"

        root = AssociativeSet('*')

        # parse_text = "foo bar (baz berz)"
        parse_text = "foo bar"

        parse(parse_text, root)

        # Expected: foo, bar, (baz berz), baz, berz, outer expression, inner expression (parenthetical)
        CategoryInspector(root).dump_to_file(filename)

        dumpfile = open(filename, "r")

        self.assertNotEqual(dumpfile, None, "Can't find the file?")

        content = dumpfile.readlines()

        self.assertTrue(len(content) > 0, "No lines read from dot file?")

        # We don't want duplicate relations. Let's only allow them once.
        # In this case our context is named '*' and our test category is 'bar'.
        lines_with_bar_and_star = [
            line for line in content if "bar" in line and "*" in line
        ]

        self.assertTrue(
            len(lines_with_bar_and_star) == 1,
            "'bar' and '*' should appear only ONCE")
    def test_parse_nested_expression(self):

        root = AssociativeSet('*')

        parse_text = "foo bar (baz berz)"

        parse(parse_text, root)

        # Expected: foo, bar, (baz berz), baz, berz, outer expression, inner expression (parenthetical)
        # Plus outer ordinals: 0, 1, 2 (which should be shared w/ inner ordinals) and 5 relations to
        # support them, and the 'position' category.
        # self.assertEqual( len(root.contents), 15)

        self.assertTrue("foo" in root.contents)
        self.assertTrue("bar" in root.contents)

        relations = root.comprehend("baz", "berz")

        self.assertTrue(
            len(relations) > 0,
            "Should get a relation back for the inner expression")

        inner_expression = relations[0]

        self.assertNotEqual(inner_expression.name, '*',
                            "Shouldn't get root back as our match")

        self.assertTrue("baz" in inner_expression,
                        "Can't see first item in nested expression.")
        self.assertTrue("berz" in inner_expression,
                        "Can't see second item in nested expression.")
    def test_parse_atom(self):

        root = AssociativeSet('.')
        expression = "foo"
        parsed = parse(expression, root)

        self.assertTrue(isinstance(parsed, AssociativeSet))
        self.assertTrue(expression in parsed.contents,
                        "Not seeing 'foo' in the contents.")
    def test_parse_ordering_of_expression(self):

        root = AssociativeSet('*')
        expression_result = parse("foo bar", root)

        self.assertEqual(len(root.comprehend("foo", "0")),
                         1)  # Should get ONE hit.

        position_relation = root.comprehend("foo", "0")[0]

        self.assertTrue("position" in position_relation.contents)

        position_tags = [
            x for x in position_relation.contents.values()
            if "position" in x.contents
        ]
        self.assertTrue(
            position_tags,
            "Should be able to see the position relation marked as such.")
    def test_parse_simple_expression(self):

        root = AssociativeSet('.')

        expression = "foo bar"

        # Note that this is the result of the expression being
        # *parsed*, not *parsed AND evaluated*. If it was being
        # evaluated there would be another category that represented
        # the result of the interaction.
        expression_result = parse(expression, root)

        # Expected in root: foo, bar, the relation between them, and the literal <<relation>> category.
        # Also the ordinal values (positions) for each element of the expression, and a relation for each.
        # And the 'position' category.
        # self.assertEqual( len(root.contents), 9)
        self.assertTrue("foo" in root.contents)
        self.assertTrue("bar" in root.contents)
        self.assertTrue("__relation__0" in root.contents)
 def test_creating_categorized_expression(self):
     context = AssociativeSet("")
     categories = [Category("foo", context)]
     foo = categorized_expression(categories, context)
     self.assertEqual(foo.name, "__relation__0")