示例#1
0
    def test_Lexicon(self):
        m1 = statements.Lexicon()

        # base cases
        m1.add("John", "P")
        m1.add("Mary", "P")
        m1.add("duck", "N")
        m1.add("student", "N")
        m1.add("purple", "A")
        m1.add("old", "A")
        m1.add("fly", "I")
        m1.add("swim", "I")
        m1.add("like", "T")
        m1.add("hit", "T")

        self.assertEquals(m1.getAll("P"), ["John", "Mary"])
        self.assertEquals(m1.getAll("N"), ["duck", "student"])
        self.assertEquals(m1.getAll("A"), ["purple", "old"])
        self.assertEquals(m1.getAll("I"), ["fly", "swim"])
        self.assertEquals(m1.getAll("T"), ["like", "hit"])

        # additional testing
        m1.add("dog", "NN")
        m1.add("cat", "NN")
        m1.add("frog", "NN")
        m1.add("student", "NN")

        m1.add("walk", "VB")
        m1.add("cook", "VB")
        m1.add("smile", "VB")
        m1.add("study", "VB")

        self.assertEquals(m1.getAll("NN"), ["dog", "cat", "frog", "student"])
        self.assertEquals(m1.getAll("VB"), ["walk", "cook", "smile", "study"])
        self.assertEquals(m1.getAll("VBZ"), "")
 def test_no_duplicates(self):
     lx = s.Lexicon()
     lx.add("John", "P")
     lx.add("Mary", "P")
     lx.add("John", "P")
     lx.add("Mary", "P")
     lx.add("like", "T")
     self.assertEqual(lx.getAll("P"), ["John", "Mary"])
示例#3
0
def test_tag_words(self):
lx = s.Lexicon()
lx.add("John", "P")
lx.add("orange", "A")
lx.add("orange", "N")
lx.add("fish", "N")
lx.add("fish", "I")
lx.add("fish", "T")
self.assertEqual(["P"], p.tag_word(lx, "John"))
self.assertEqual(["A", "Ns"], p.tag_word(lx, "orange"))
self.assertEqual(["Ns", "Np", "Ip", "Tp"], p.tag_word(lx, "fish"))
self.assertEqual(["AR"], p.tag_word(lx, "a"))
self.assertEqual([], p.tag_word(lx, "zxghqw"))


class TestAgreement(unittest.TestCase):
def test_can_parse(self):
lx = s.Lexicon()
lx.add('John', 'P')
lx.add('like', 'T')
lx.add("fly", "I")
lx.add("Mary", "P")
lx.add("duck", "N")
lx.add("swim", "I")
lx.add("like", "T")
lx.add("frog", "N")
lx.add("orange", "A")
lx.add("orange", "N")
lx.add("purple", "A")
lx.add("fish", "N")
lx.add("fish", "I")
lx.add("fish", "T")
lx.add("student", "N")
lx.add("old", "A")
self.assertGreaterEqual(
len(a.all_valid_parses(lx, "Who likes John ?".split(" "))), 1)
self.assertGreaterEqual(
len(a.all_valid_parses(lx, "Who is a duck ?".split(" "))), 1)
self.assertGreaterEqual(len(a.all_valid_parses(
lx, "Which orange duck likes a frog ?".split(" "))), 1)
self.assertGreaterEqual(len(a.all_valid_parses(
lx, "Who does John like ?".split(" "))), 1)
self.assertGreaterEqual(len(a.all_valid_parses(
lx, "Who is an orange duck ?".split(" "))), 1)
self.assertGreaterEqual(len(a.all_valid_parses(
lx, "Which ducks are orange ?".split(" "))), 1)
self.assertGreaterEqual(len(a.all_valid_parses(
lx, "Which ducks like a frog ?".split(" "))), 1)
self.assertGreaterEqual(len(a.all_valid_parses(
lx, "Which ducks like frogs ?".split(" "))), 1)
self.assertGreaterEqual(len(a.all_valid_parses(
lx, "Who likes a duck who flies ?".split(" "))), 1)
self.assertGreaterEqual(len(a.all_valid_parses(
lx, "Which purple ducks fly ?".split(" "))), 1)


if __name__ == '__main__':
unittest.main()
 def test_tag_words(self):
     lx = s.Lexicon()
     lx.add("John", "P")
     lx.add("orange", "A")
     lx.add("orange", "N")
     lx.add("fish", "N")
     lx.add("fish", "I")
     lx.add("fish", "T")
     self.assertEqual(["P"], p.tag_word(lx, "John"))
     self.assertEqual(["A", "Ns"], p.tag_word(lx, "orange"))
     self.assertEqual(["Ns", "Np", "Ip", "Tp"], p.tag_word(lx, "fish"))
     self.assertEqual(["AR"], p.tag_word(lx, "a"))
     self.assertEqual([], p.tag_word(lx, "zxghqw"))
示例#5
0
def test_can_parse(self):
lx = s.Lexicon()
lx.add('John', 'P')
lx.add('like', 'T')
lx.add("fly", "I")
lx.add("Mary", "P")
lx.add("duck", "N")
lx.add("swim", "I")
lx.add("like", "T")
lx.add("frog", "N")
lx.add("orange", "A")
lx.add("orange", "N")
lx.add("purple", "A")
lx.add("fish", "N")
lx.add("fish", "I")
lx.add("fish", "T")
lx.add("student", "N")
lx.add("old", "A")
self.assertGreaterEqual(
len(a.all_valid_parses(lx, "Who likes John ?".split(" "))), 1)
self.assertGreaterEqual(
len(a.all_valid_parses(lx, "Who is a duck ?".split(" "))), 1)
self.assertGreaterEqual(len(a.all_valid_parses(
lx, "Which orange duck likes a frog ?".split(" "))), 1)
self.assertGreaterEqual(len(a.all_valid_parses(
lx, "Who does John like ?".split(" "))), 1)
self.assertGreaterEqual(len(a.all_valid_parses(
lx, "Who is an orange duck ?".split(" "))), 1)
self.assertGreaterEqual(len(a.all_valid_parses(
lx, "Which ducks are orange ?".split(" "))), 1)
self.assertGreaterEqual(len(a.all_valid_parses(
lx, "Which ducks like a frog ?".split(" "))), 1)
self.assertGreaterEqual(len(a.all_valid_parses(
lx, "Which ducks like frogs ?".split(" "))), 1)
self.assertGreaterEqual(len(a.all_valid_parses(
lx, "Who likes a duck who flies ?".split(" "))), 1)
self.assertGreaterEqual(len(a.all_valid_parses(
lx, "Which purple ducks fly ?".split(" "))), 1)


if __name__ == '__main__':
unittest.main()
 def test_john_likes_mary(self):
     lx = s.Lexicon()
     lx.add("John", "P")
     lx.add("Mary", "P")
     lx.add("like", "T")
     self.assertEqual(lx.getAll("P"), ["John", "Mary"])
 def test_access_before_assign(self):
     lx = s.Lexicon()
     self.assertEqual(lx.getAll("N"), [])
示例#8
0
def test_no_duplicates(self):
    lx = s.Lexicon()
    lx.add("John", "P")