Exemplo n.º 1
0
 def __str__(self):
     ret_str = ""
     for word_e in Vocabulary.words(self.e_vocab):
         for word_f in Vocabulary.words(self.f_vocab):
             ret_str += self.name + "[" + word_e + " | " + word_f + "] = " + str(
                 self.double_dict[word_e][word_f]) + "\n"
     return ret_str
Exemplo n.º 2
0
    def __str__(self):
        ret_string = ""

        for e in Vocabulary.words(self.e_vocab):
            for f in Vocabulary.words(self.f_vocab):
                ret_string = ret_string + self.name + "[" + e + " | " + f + "]" + " = " + str(
                    self.dict_of_dict[e][f]) + '\n'
        return ret_string
Exemplo n.º 3
0
    def __init__(self, name, e_vocab, f_vocab, initial_value):
        self.name = name
        self.e_vocab = e_vocab
        self.f_vocab = f_vocab
        #cast as dict?? self.double_dict = dict(defaultdict(dict))?
        self.double_dict = defaultdict(dict)

        for word_e in Vocabulary.words(e_vocab):
            for word_f in Vocabulary.words(f_vocab):
                self.double_dict[word_e][word_f] = initial_value
Exemplo n.º 4
0
    def __init__(self, name, e_vocab, f_vocab, initial_value):
        self.name = name
        self.e_vocab = e_vocab
        self.f_vocab = f_vocab
        #self.initial_value = 0
        self.dict_of_dict = defaultdict(dict)

        #storing initial value for every pair of words in dictionary of dictionaries
        for e_word in Vocabulary.words(e_vocab):
            for f_word in Vocabulary.words(f_vocab):
                self.dict_of_dict[e_word][f_word] = initial_value
Exemplo n.º 5
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")
Exemplo n.º 6
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])
Exemplo n.º 7
0
 def test_empty_list(self):
     """Assert that a newly constructed vocabulary contains an empty list"""
     v = Vocabulary()
     self.assertEqual(v.words(), list())