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)
评论列表
文章目录