本文整理汇总了Python中classifier.Classifier.get_vector方法的典型用法代码示例。如果您正苦于以下问题:Python Classifier.get_vector方法的具体用法?Python Classifier.get_vector怎么用?Python Classifier.get_vector使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类classifier.Classifier
的用法示例。
在下文中一共展示了Classifier.get_vector方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestManager
# 需要导入模块: from classifier import Classifier [as 别名]
# 或者: from classifier.Classifier import get_vector [as 别名]
class TestManager(unittest.TestCase):
""" Tests the Manager class.
"""
def setUp(self):
self.co = Collector()
self.c = Classifier(CleanTextUtil("french"))
self.m = Manager(self.co, self.c)
self.feeds_info = Manager.get_feeds_info()
def tearDown(self):
rm_data_dir()
def test_add_feeds(self):
""" Tests add_feeds.
Add feeds.
For each item with get_feeds_info:
1- Check if the feed has been added.
"""
self.m.add_feeds()
for name, _, _, _ in self.feeds_info:
self.assertTrue(self.co.has_feed(name)) # 1
def test_add_texts_vectors(self):
""" Tests add_texts_vectors.
Add feeds.
Add texts vectors:
1- Check if the dictionary is not empty.
2- Check if the number of text equals to feeds info.
"""
self.m.add_feeds()
self.m.add_texts_vectors()
self.assertNotEquals(len(self.c.dictionary_db), 0) # 1
size = len([_ for _, _, _, _ in self.feeds_info])
self.assertEquals(int(self.c.classifier_state_db.get("text_nb")), size) # 2
def test_add_general_feed(self):
#TODO
""" Test .
"""
pass
def test_remove_feed(self):
""" Tests remove_feed .
Add feeds.
Add texts vectors:
1- Check if a feed exists.
2- Check if a vector exists.
Remove a feed.
3- Check if the feed has been removed.
4- Check if the vector doesn't exist anymore.
"""
name = self.feeds_info[0][0]
self.m.add_feeds()
self.m.add_texts_vectors()
self.assertTrue(self.co.has_feed(name)) # 1
self.assertIsNotNone(self.c.get_vector(name)) # 2
self.m.remove_feed(name)
self.assertFalse(self.co.has_feed(name)) # 3
self.assertIsNone(self.c.get_vector(name)) # 4
def test_get_feeds_info(self):
#TODO
""" Test .
"""
pass
示例2: TestClassifier
# 需要导入模块: from classifier import Classifier [as 别名]
# 或者: from classifier.Classifier import get_vector [as 别名]
#.........这里部分代码省略.........
_, word_info = kc_util.gen_db(self.c.dictionary_db.cursor()).next()
self.assertEquals(word_info.idf, 0.0) # 1
self.c.add_vector(vector_1, text)
norm = self.c.vectors_norm_db.get(vector_1)
self.assertEquals(norm, '0.0') # 2
self.c.set_idf()
_, word_info = kc_util.gen_db(self.c.dictionary_db.cursor()).next()
self.assertNotEquals(word_info.idf, 0.0) # 3
self.c.set_tfidf_norm()
norm = self.c.vectors_norm_db.get(vector_1)
self.assertNotEquals(norm, '0.0') # 4
def test_add_vector(self):
""" Tests add_vector.
Add a text.
1- Check if there is not a vector.
Add a vector:
2- Check if there is a vector.
"""
text, vector_1 = "foo", "foo_1"
self.c.add_text(text)
vector = self.c.get_vector(vector_1)
self.assertIsNone(vector) # 1
self.c.add_vector(vector_1, text)
vector = self.c.get_vector(vector_1)
self.assertIsInstance(vector, Vector) # 2
def test_rm_vector(self):
""" Tests rm_vector.
Add a text.
Add a vector:
1- Check if the vector exists.
Remove the vector:
2- Check if the vector doesn't exist anymore.
"""
text, vector_1 = "foo", "foo_1"
self.c.add_text(text)
self.c.add_vector(vector_1, text)
vector = self.c.get_vector(vector_1)
self.assertIsNotNone(vector) # 1
self.c.rm_vector(vector_1)
vector = self.c.get_vector(vector_1)
self.assertIsNone(vector) # 2
def test_get_vector(self):
""" Tests get_vector.