1 | import unittest2 as unittest |
---|
2 | import numpy as np |
---|
3 | |
---|
4 | from vsm.viewer.lsaviewer import LsaViewer |
---|
5 | |
---|
6 | |
---|
7 | class TestLsaViewer(unittest.TestCase): |
---|
8 | |
---|
9 | def setUp(self): |
---|
10 | |
---|
11 | from vsm.corpus.util.corpusbuilders import random_corpus |
---|
12 | from vsm.model.tf import TfSeq |
---|
13 | from vsm.model.tfidf import TfIdf |
---|
14 | from vsm.model.lsa import Lsa |
---|
15 | |
---|
16 | c = random_corpus(10000, 1000, 0, 30, context_type='document', metadata=True) |
---|
17 | |
---|
18 | tf = TfSeq(c, 'document') |
---|
19 | tf.train() |
---|
20 | |
---|
21 | tfidf = TfIdf.from_tf(tf) |
---|
22 | tfidf.train() |
---|
23 | |
---|
24 | m = Lsa.from_tfidf(tfidf) |
---|
25 | m.train() |
---|
26 | |
---|
27 | self.v = LsaViewer(c, m) |
---|
28 | |
---|
29 | |
---|
30 | def test_Lsaviewer(self): |
---|
31 | |
---|
32 | from vsm.viewer.labeleddata import LabeledColumn, IndexedSymmArray |
---|
33 | |
---|
34 | sww = self.v.dist_word_word('1') |
---|
35 | swwl = self.v.dist_word_word(['1', '0']) |
---|
36 | sdd = self.v.dist_doc_doc(1) |
---|
37 | sddl = self.v.dist_doc_doc([1, 0]) |
---|
38 | self.assertTrue(type(sww) == LabeledColumn) |
---|
39 | self.assertTrue(type(swwl) == LabeledColumn) |
---|
40 | self.assertTrue(type(sdd) == LabeledColumn) |
---|
41 | self.assertTrue(type(sddl) == LabeledColumn) |
---|
42 | |
---|
43 | sw = self.v.dismat_word(['2','4','5']) |
---|
44 | sd = self.v.dismat_doc([1, 0]) |
---|
45 | self.assertTrue(type(sw) == IndexedSymmArray) |
---|
46 | self.assertTrue(type(sd) == IndexedSymmArray) |
---|
47 | |
---|
48 | |
---|
49 | |
---|
50 | |
---|
51 | #Define and run test suite |
---|
52 | suite = unittest.TestLoader().loadTestsFromTestCase(TestLsaViewer) |
---|
53 | unittest.TextTestRunner(verbosity=2).run(suite) |
---|