convert.py 文件源码

python
阅读 31 收藏 0 点赞 0 评论 0

项目:nn4nlp-code 作者: neubig 项目源码 文件源码
def passage2file(passage, filename, indent=True, binary=False):
    """Writes a UCCA passage as a standard XML file or a binary pickle
    :param passage: passage object to write
    :param filename: file name to write to
    :param indent: whether to indent each line
    :param binary: whether to write pickle format (or XML)
    """
    if binary:
        with open(filename, "wb") as h:
            pickle.dump(passage, h)
    else:  # xml
        root = to_standard(passage)
        xml = ET.tostring(root).decode()
        output = textutil.indent_xml(xml) if indent else xml
        with open(filename, "w", encoding="utf-8") as h:
            h.write(output)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号