本文整理汇总了Python中orangecontrib.text.corpus.Corpus.from_table方法的典型用法代码示例。如果您正苦于以下问题:Python Corpus.from_table方法的具体用法?Python Corpus.from_table怎么用?Python Corpus.from_table使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类orangecontrib.text.corpus.Corpus
的用法示例。
在下文中一共展示了Corpus.from_table方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: open_file
# 需要导入模块: from orangecontrib.text.corpus import Corpus [as 别名]
# 或者: from orangecontrib.text.corpus.Corpus import from_table [as 别名]
def open_file(self, path=None, data=None):
self.closeContext()
self.Error.clear()
self.unused_attrs_model[:] = []
self.used_attrs_model[:] = []
if data:
self.corpus = Corpus.from_table(data.domain, data)
elif path:
try:
self.corpus = Corpus.from_file(path)
self.corpus.name = os.path.splitext(os.path.basename(path))[0]
except BaseException as err:
self.Error.read_file(path, str(err))
else:
return
self.update_info()
self.used_attrs = list(self.corpus.text_features)
if not self.corpus.text_features:
self.Error.corpus_without_text_features()
self.Outputs.corpus.send(None)
return
self.openContext(self.corpus)
self.used_attrs_model.extend(self.used_attrs)
self.unused_attrs_model.extend(
[f for f in self.corpus.domain.metas
if f.is_string and f not in self.used_attrs_model])
示例2: set_data
# 需要导入模块: from orangecontrib.text.corpus import Corpus [as 别名]
# 或者: from orangecontrib.text.corpus.Corpus import from_table [as 别名]
def set_data(self, data=None):
self.reset_widget()
self.corpus = data
if data is not None:
if not isinstance(data, Corpus):
self.corpus = Corpus.from_table(data.domain, data)
self.load_features()
self.regenerate_docs()
self.commit()
示例3: test_from_table
# 需要导入模块: from orangecontrib.text.corpus import Corpus [as 别名]
# 或者: from orangecontrib.text.corpus.Corpus import from_table [as 别名]
def test_from_table(self):
t = Table.from_file('brown-selected')
self.assertIsInstance(t, Table)
c = Corpus.from_table(t.domain, t)
self.assertIsInstance(c, Corpus)
self.assertEqual(len(t), len(c))
np.testing.assert_equal(t.metas, c.metas)
self.assertEqual(c.text_features, [t.domain.metas[0]])
示例4: test_compute_values
# 需要导入模块: from orangecontrib.text.corpus import Corpus [as 别名]
# 或者: from orangecontrib.text.corpus.Corpus import from_table [as 别名]
def test_compute_values(self):
corpus = Corpus.from_file('deerwester')
vect = BowVectorizer()
bow = vect.transform(corpus)
computed = Corpus.from_table(bow.domain, corpus)
self.assertEqual(bow.domain, computed.domain)
self.assertEqual((bow.X != computed.X).nnz, 0)
示例5: on_data
# 需要导入模块: from orangecontrib.text.corpus import Corpus [as 别名]
# 或者: from orangecontrib.text.corpus.Corpus import from_table [as 别名]
def on_data(self, data):
if data and not isinstance(data, Corpus):
data = Corpus.from_table(data.domain, data)
self.data = data
self._repopulate_attr_combo(data)
if not data:
self.region_selected('')
QTimer.singleShot(0, lambda: self.webview.evalJS('DATA = {}; renderMap();'))
else:
QTimer.singleShot(0, self.on_attr_change)
示例6: set_data
# 需要导入模块: from orangecontrib.text.corpus import Corpus [as 别名]
# 或者: from orangecontrib.text.corpus.Corpus import from_table [as 别名]
def set_data(self, data=None):
self.reset_widget() # Clear any old data.
if data is not None:
self.corpus = data
if isinstance(data, Table):
self.corpus = Corpus.from_table(data.domain, data)
self.load_features()
self.regenerate_documents()
# Send the corpus to output.
self.send(Output.CORPUS, self.corpus)
示例7: test_documents_from_sparse_features
# 需要导入模块: from orangecontrib.text.corpus import Corpus [as 别名]
# 或者: from orangecontrib.text.corpus.Corpus import from_table [as 别名]
def test_documents_from_sparse_features(self):
t = Table.from_file('brown-selected')
c = Corpus.from_table(t.domain, t)
c.X = csr_matrix(c.X)
# docs from X, Y and metas
docs = c.documents_from_features([t.domain.attributes[0], t.domain.class_var, t.domain.metas[0]])
self.assertEqual(len(docs), len(t))
for first_attr, class_val, meta_attr, d in zip(t.X[:, 0], c.Y, c.metas[:, 0], docs):
first_attr = c.domain.attributes[0].str_val(first_attr)
class_val = c.domain.class_var.str_val(class_val)
meta_attr = c.domain.metas[0].str_val(meta_attr)
self.assertIn(class_val, d)
self.assertIn(first_attr, d)
self.assertIn(meta_attr, d)
# docs only from sparse X
docs = c.documents_from_features([t.domain.attributes[0]])
self.assertEqual(len(docs), len(t))
for first_attr, d in zip(t.X[:, 0], docs):
first_attr = c.domain.attributes[0].str_val(first_attr)
self.assertIn(first_attr, d)
示例8: commit
# 需要导入模块: from orangecontrib.text.corpus import Corpus [as 别名]
# 或者: from orangecontrib.text.corpus.Corpus import from_table [as 别名]
def commit(self):
if self.output_mask is not None:
output_corpus = Corpus.from_table(self.corpus.domain, self.corpus,
row_indices=self.output_mask)
self.send(Output.CORPUS, output_corpus)
示例9: test_compute_values
# 需要导入模块: from orangecontrib.text.corpus import Corpus [as 别名]
# 或者: from orangecontrib.text.corpus.Corpus import from_table [as 别名]
def test_compute_values(self):
sentiment = self.method.transform(self.corpus)
computed = Corpus.from_table(sentiment.domain, self.corpus)
self.assertEqual(sentiment.domain, computed.domain)
self.assertTrue((sentiment.X == computed.X).all())