Пример #1
0
class TestKnowledgebase(unittest.TestCase):

    def setUp(self):
        self.fe = Acquirer()     # A dumb frontend
        self.kb = KnowledgeBase(frontend=self.fe)

    def test_get(self):
        self.assertEquals(self.fe.resources()['get'], self.kb.get)

    def test_get_attributes(self):
        f = self.fe.resources()['get-attributes']
        self.assertIn("BIRTH-DATE", f("wikipedia-president", "Bill Clinton"))

    def test_attributes_format(self):
        attrs = self.fe.resources()['get-attributes']("wikipedia-president",
                                                      "Bill Clinton")

        for a in CLINTON_ATTRS:
            self.assertIn(a, attrs)

    def test_classes(self):
        self.assertIn("wikipedia-president",
                      str(self.fe.resources()['get-classes']("Bill Clinton")))
        # The list gets iterated and memoization fails.
        self.assertIn("wikipedia-president",
                      str(self.fe.resources()['get-classes']("Bill Clinton")),
                      "Second time failed. Memoization problem")

    def test_types(self):
        types = self.fe.resources()['get-types']("Bill Clinton")
        self.assertIn('officeholder', types)
        self.assertIn('president', types)

    def test_categories(self):
        self.assertIn("Presidents of the United States",
                      self.fe.resources()['get-categories']("Bill Clinton"))

    def test_sort_symbols(self):
        ench = self.fe.resources()['sort-symbols']("Mary Shakespeare", "Batman")
        self.assertIs(type(ench), LispList)
        self.assertEqual(ench.val, ["Batman", "Mary Shakespeare"])

    def test_synonyms(self):
        self.assertIn("batman", self.kb.synonyms("bat man"))

    def tearDown(self):
        pass
Пример #2
0
 def setUp(self):
     self.fe = Acquirer()     # A dumb frontend
     self.kb = KnowledgeBase(frontend=self.fe)