def test_words2indices(self): v = Vocab('unk') words = ['i', 'like', 'pie'] v.update(words) v = v.freeze() assert v.words2indices(words) == [1, 2, 3] assert v.words2indices(['i', 'said']) == [1, 0]
def test_eq(vocab): v = Vocab('unk') v.update('zero one two two three three three'.split()) assert v == vocab v.add('zero', count=10) assert v == vocab # equality doesn't depend on count v.add('four') assert v != vocab
def test_indices2words(self): v = Vocab(unk='unk') v.update(['i', 'like', 'pie']) words = v.indices2words([1, 2, 3, 0]) assert words == ['i', 'like', 'pie', 'unk']
def vocab(): v = Vocab('unk') v.update('zero one two two three three three'.split()) return v