예제 #1
0
    def get(self, e_i, f_i):
        e_word = Vocabulary.get_word(self.e_vocab, e_i)
        f_word = Vocabulary.get_word(self.f_vocab, f_i)
        #looking for value corresponding to dict of dict val
        ret_val = self.dict_of_dict[e_word][f_word]

        return ret_val
예제 #2
0
 def test_add_one_word(self):
     """Assert that adding a single word to a newly constructed Vocabulary works as expected"""
     v = Vocabulary()
     i = v.get_int("hello")
     self.assertEqual(i, 0)
     self.assertEqual(v.size(), 1)
     self.assertEqual(v.words(), ["hello"])
     self.assertEqual(v.get_int("hello"), i)
     self.assertEqual(v.get_word(0), "hello")
예제 #3
0
    def test_adding_words(self):
        """Assert that words are properly added to the vocabulary"""
        v = Vocabulary()
        tokens = "Four score and seven years ago".split()
        ints = list()
        for token in tokens:
            ints.append(v.get_int(token))

        self.assertEqual(v.words(), tokens)

        for token in tokens:
            i = v.get_int(token)
            self.assertNotEqual(i, None)
            t = v.get_word(i)
            self.assertEqual(t, token)

        for i in range(0, len(tokens)):
            self.assertNotEqual(i, None)
            t = v.get_word(i)
            self.assertEqual(t, tokens[i])
예제 #4
0
    def set(self, e_i, f_i, value):
        e_word = Vocabulary.get_word(self.e_vocab, e_i)
        f_word = Vocabulary.get_word(self.f_vocab, f_i)

        self.dict_of_dict[e_word][f_word] = value
예제 #5
0
파일: c.py 프로젝트: mtlynch3/ling402
 def set(self, e_i, f_i, value):
     word_e = Vocabulary.get_word(self.e_vocab, e_i)
     word_f = Vocabulary.get_word(self.f_vocab, f_i)
     self.double_dict[word_e][word_f] = value
예제 #6
0
파일: c.py 프로젝트: mtlynch3/ling402
 def get(self, e_i, f_i):
     word_e = Vocabulary.get_word(self.e_vocab, e_i)
     word_f = Vocabulary.get_word(self.f_vocab, f_i)
     return self.double_dict[word_e][word_f]
예제 #7
0
 def test_negative_indices(self):
     """Assert that a newly constructed vocabulary returns None for negative numbers"""
     v = Vocabulary()
     for i in range(-1000, -1):
         self.assertEqual(v.get_word(i), None)
예제 #8
0
 def test_empty_word_index(self):
     """Assert that a newly constructed vocabulary does not associate any string with index zero"""
     v = Vocabulary()
     self.assertEqual(v.get_word(0), None)