本文整理汇总了Python中Orange.data.Table.from_file方法的典型用法代码示例。如果您正苦于以下问题:Python Table.from_file方法的具体用法?Python Table.from_file怎么用?Python Table.from_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Orange.data.Table
的用法示例。
在下文中一共展示了Table.from_file方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _construct_table
# 需要导入模块: from Orange.data import Table [as 别名]
# 或者: from Orange.data.Table import from_file [as 别名]
def _construct_table(self, with_header_row):
"""
Write the `selected_lines` into a temporary file and read it.
If `with_header_row` is `True`, the first line in every block is
skipped, except for the first block.
If `with_header_row` is `False`, a header row is added.
"""
assert self.selected_lines
tempf = NamedTemporaryFile("w", suffix=".csv", delete=False)
if with_header_row:
data = self.selected_lines[0] + "\n" + \
"\n".join(
"\n".join(self.selected_lines[i + 1:i + self.block_length])
for i in range(0, len(self.selected_lines),
self.block_length))
else:
n_cols = len(self.selected_lines[0].split())
data = (
" ".join("var{:03}".format(i + 1) for i in range(n_cols))
+ "\n"
+ "\n".join(self.selected_lines))
tempf.write(re.sub(" +", " ", data))
tempf.close()
try:
return Table.from_file(tempf.name)
except Exception as err:
self.Error.unreadable(str(err).replace(" " + tempf.name, ""))
finally:
os.remove(tempf.name)
示例2: from_file
# 需要导入模块: from Orange.data import Table [as 别名]
# 或者: from Orange.data.Table import from_file [as 别名]
def from_file(cls, filename):
if not os.path.exists(filename): # check the default corpora location
abs_path = os.path.join(get_sample_corpora_dir(), filename)
if not abs_path.endswith('.tab'):
abs_path += '.tab'
if not os.path.exists(abs_path):
raise FileNotFoundError('File "{}" was not found.'.format(filename))
else:
filename = abs_path
table = Table.from_file(filename)
include_ids = []
first_id = None
for i, attr in enumerate(table.domain.metas):
if isinstance(attr, StringVariable):
if first_id is None:
first_id = i
if attr.attributes.get('include', 'False') == 'True':
include_ids.append(i)
if len(include_ids) == 0:
include_ids.append(first_id)
documents = []
for line in range(table.metas.shape[0]):
documents.append(' '.join(table.metas[line, include_ids]))
corp = cls(documents, table.X, table.Y, table.metas, table.domain)
corp.used_features = [f for i, f in enumerate(table.domain.metas) if i in include_ids]
return corp
示例3: test_from_table
# 需要导入模块: from Orange.data import Table [as 别名]
# 或者: from Orange.data.Table import from_file [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: from_file
# 需要导入模块: from Orange.data import Table [as 别名]
# 或者: from Orange.data.Table import from_file [as 别名]
def from_file(cls, filename, wrapper=None):
if not os.path.exists(filename): # check the default location
abs_path = os.path.join(get_sample_corpora_dir(), filename)
if not abs_path.endswith('.tab'):
abs_path += '.tab'
if not os.path.exists(abs_path):
raise FileNotFoundError('File "{}" not found.'.format(filename))
else:
filename = abs_path
table = Table.from_file(filename, wrapper)
return cls(table.X, table.Y, table.metas, table.domain, None)
示例5: from_file
# 需要导入模块: from Orange.data import Table [as 别名]
# 或者: from Orange.data.Table import from_file [as 别名]
def from_file(cls, filename):
table = Table.from_file(filename)
include_ids = []
first_id = None
for i, attr in enumerate(table.domain.metas):
if isinstance(attr, StringVariable):
if first_id is None:
first_id = i
if attr.attributes.get("include", "False") == "True":
include_ids.append(i)
if len(include_ids) == 0:
include_ids.append(first_id)
documents = []
for line in range(table.metas.shape[0]):
documents.append(" ".join(table.metas[line, include_ids]))
corp = cls(documents, table.X, table.Y, table.metas, table.domain)
corp.used_features = [f for i, f in enumerate(table.domain.metas) if i in include_ids]
return corp
示例6: test_documents_from_sparse_features
# 需要导入模块: from Orange.data import Table [as 别名]
# 或者: from Orange.data.Table import from_file [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)
示例7: test_named_sheet_table
# 需要导入模块: from Orange.data import Table [as 别名]
# 或者: from Orange.data.Table import from_file [as 别名]
def test_named_sheet_table(self):
table = Table.from_file(get_dataset("header_0_sheet.xlsx"),
sheet="my_sheet")
self.assertEqual(len(table.domain.attributes), 4)
self.assertEqual(table.name, 'header_0_sheet-my_sheet')
示例8: setUp
# 需要导入模块: from Orange.data import Table [as 别名]
# 或者: from Orange.data.Table import from_file [as 别名]
def setUp(self):
self.widget = self.create_widget(OWDuplicates)
self.data = Table.from_file('iris')
self.distances = Euclidean(self.data)