当前位置: 首页>>代码示例>>Python>>正文


Python Table.from_file方法代码示例

本文整理汇总了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)
开发者ID:pavlin-policar,项目名称:orange3-prototypes,代码行数:33,代码来源:owgrep.py

示例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
开发者ID:pombredanne,项目名称:orange3-text,代码行数:31,代码来源:corpus.py

示例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]])
开发者ID:s-alexey,项目名称:orange3-text,代码行数:11,代码来源:test_corpus.py

示例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)
开发者ID:ales-erjavec,项目名称:orange3-text,代码行数:14,代码来源:corpus.py

示例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
开发者ID:kernc,项目名称:orange3-text,代码行数:22,代码来源:corpus.py

示例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)
开发者ID:s-alexey,项目名称:orange3-text,代码行数:24,代码来源:test_corpus.py

示例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')
开发者ID:PrimozGodec,项目名称:orange3,代码行数:7,代码来源:test_xlsx_reader.py

示例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)
开发者ID:s-alexey,项目名称:orange3-text,代码行数:6,代码来源:test_owduplicates.py


注:本文中的Orange.data.Table.from_file方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。