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


Python GraphUtils.write_raw_triples方法代码示例

本文整理汇总了Python中dipper.utils.GraphUtils.GraphUtils.write_raw_triples方法的典型用法代码示例。如果您正苦于以下问题:Python GraphUtils.write_raw_triples方法的具体用法?Python GraphUtils.write_raw_triples怎么用?Python GraphUtils.write_raw_triples使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在dipper.utils.GraphUtils.GraphUtils的用法示例。


在下文中一共展示了GraphUtils.write_raw_triples方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: write

# 需要导入模块: from dipper.utils.GraphUtils import GraphUtils [as 别名]
# 或者: from dipper.utils.GraphUtils.GraphUtils import write_raw_triples [as 别名]
    def write(self, format='rdfxml', stream=None):
        """
        This convenience method will write out all of the graphs
        associated with the source.
        Right now these are hardcoded to be a single "graph" and a "dataset".
        If you do not supply stream='stdout'
        it will default write these to files.

        In addition, if the version number isn't yet set in the dataset,
        it will be set to the date on file.
        :return: None

        """
        format_to_xtn = {
            'rdfxml': 'xml', 'turtle': 'ttl'
        }

        # make the regular graph output file
        file = None
        if self.name is not None:
            file = '/'.join((self.outdir, self.name))
            if format in format_to_xtn:
                file = '.'.join((file, format_to_xtn.get(format)))
            else:
                file = '.'.join((file, format))
            # make the datasetfile name
            datasetfile = '/'.join((self.outdir, self.name+'_dataset'))
            if format in format_to_xtn:
                datasetfile = '.'.join((datasetfile,
                                        format_to_xtn.get(format)))
            else:
                datasetfile = '.'.join((datasetfile, format))

            logger.info(
                "No version set for this datasource; setting to date issued.")

            if self.dataset is not None and self.dataset.version is None:
                self.dataset.set_version_by_date()
        else:
            logger.warning("No output file set. Using stdout")
            stream = 'stdout'

        # start off with only the dataset descriptions
        graphs = [
            {'g': self.dataset.getGraph(), 'file': datasetfile},
        ]

        # add the other graphs to the set to write, if not in the test mode
        if self.testMode:
            graphs += [{'g': self.testgraph, 'file': self.testfile}]
        else:
            graphs += [{'g': self.graph, 'file': file}]

        gu = GraphUtils(None)
        # loop through each of the graphs and print them out

        for g in graphs:
            f = None
            if stream is None:
                f = g['file']
            elif stream.lower().strip() == 'stdout':
                f = None
            else:
                logger.error("I don't understand your stream.")
                return
            if format == 'raw':
                gu.write_raw_triples(g['g'], file=f)
            else:
                gu.write(g['g'], format, file=f)

        return
开发者ID:JervenBolleman,项目名称:dipper,代码行数:73,代码来源:Source.py


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