示例#1
0
    def serialize(self, sink: Union[IO, str], cas: Cas):
        nsmap = cas.namespaces
        xmi_attrs = {'{http://www.omg.org/XMI}version': '2.0'}
        with etree.xmlfile(sink) as xf:
            with xf.element('xmi:XMI', nsmap=nsmap, **xmi_attrs):
                self._serialize_cas_null(xf, nsmap)

                for annotation in cas.select_all():
                    self._serialize_annotation(xf, nsmap, annotation)

                for sofa in cas.sofas:
                    self._serialize_sofa(xf, nsmap, sofa)

                for view in cas.views:
                    self._serialize_view(xf, nsmap, view)
示例#2
0
    def serialize(self, sink: Union[IO, str], cas: Cas, pretty_print=True):
        xmi_attrs = {"{http://www.omg.org/XMI}version": "2.0"}

        root = etree.Element(etree.QName(self._nsmap["xmi"], "XMI"), nsmap=self._nsmap, **xmi_attrs)

        self._serialize_cas_null(root)

        for annotation in sorted(cas.select_all(), key=lambda a: a.xmiID):
            self._serialize_annotation(root, annotation)

        for sofa in cas.sofas:
            self._serialize_sofa(root, sofa)

        for view in cas.views:
            self._serialize_view(root, view)

        doc = etree.ElementTree(root)
        etree.cleanup_namespaces(doc, top_nsmap=self._nsmap)

        doc.write(sink, xml_declaration=True, pretty_print=pretty_print)