-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathtest_DocSim.py
More file actions
24 lines (19 loc) · 826 Bytes
/
Copy pathtest_DocSim.py
File metadata and controls
24 lines (19 loc) · 826 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from gensim.models.keyedvectors import KeyedVectors
import numpy as np
from DocSim import DocSim
import unittest
class DocSimTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
test_model_path = './data/test_data.txt'
cls.w2v_model = KeyedVectors.load_word2vec_format(test_model_path, binary=False)
cls.stopwords = ['to', 'an', 'a']
cls.doc_sim = DocSim(cls.w2v_model, cls.stopwords)
def test_vectorize_with_valid_words(self):
source_doc = 'how to delete an invoice'
# same values dummy data will output same mean value
expected = np.array([0.5, 0.5, 0.6, 0.3, 0.2, 0.1, 0.4, 0.6, 0.5, 0.5])
actual = self.doc_sim.vectorize(source_doc)
self.assertEqual(expected.all(), actual.all())
if __name__ == "__main__":
unittest.main()