public void WriteXml(XmlWriter writer) { using (Py.GIL()) { var pyObj = Interop.GetBytes(_pyLexeme.to_bytes()); writer.WriteElementString("PyObj", pyObj, Serialization.Namespace); } // Using the property is important form the members to be loaded writer.WriteElementString("Text", Text, Serialization.Namespace); writer.WriteElementString("Shape", Shape, Serialization.Namespace); writer.WriteElementString("Prefix", Prefix, Serialization.Namespace); writer.WriteElementString("Suffix", Suffix, Serialization.Namespace); writer.WriteElementString("Lang", Lang, Serialization.Namespace); writer.WriteElementString("Orth", Orth.ToString(), Serialization.Namespace); writer.WriteStartElement("IsAlpha", Serialization.Namespace); writer.WriteValue(IsAlpha); writer.WriteEndElement(); writer.WriteStartElement("IsDigit", Serialization.Namespace); writer.WriteValue(IsDigit); writer.WriteEndElement(); writer.WriteStartElement("IsTitle", Serialization.Namespace); writer.WriteValue(IsTitle); writer.WriteEndElement(); }
public void WriteXml(XmlWriter writer) { writer.WriteStartElement(Serialization.Prefix, "DocBin", Serialization.Namespace); var serializationMode = Serialization.Selected; if (serializationMode == Serialization.Mode.SpacyAndDotNet) { using (Py.GIL()) { var pyObj = Interop.GetBytes(_pyDocBin.to_bytes()); var pyObjB64 = Convert.ToBase64String(pyObj); writer.WriteElementString("PyObj", Serialization.Namespace, pyObjB64); } } Debug.Assert(serializationMode != Serialization.Mode.Spacy); writer.WriteStartElement("Docs", Serialization.Namespace); foreach (var doc in _docs) { doc.WriteXml(writer); } writer.WriteEndElement(); writer.WriteEndElement(); }
public void WriteXml(XmlWriter writer) { var serializationMode = Serialization.Selected; Debug.Assert(serializationMode != Serialization.Mode.Spacy); if (serializationMode == Serialization.Mode.SpacyAndDotNet) { using (Py.GIL()) { var pyObj = Interop.GetBytes(PyVocab.to_bytes()); var pyObjB64 = Convert.ToBase64String(pyObj); writer.WriteElementString("PyObj", Serialization.Namespace, pyObjB64); } } }
public byte[] ToBytes() { if (Serialization.Selected == Serialization.Mode.Spacy) { using (Py.GIL()) { return(Interop.GetBytes(PyDoc.to_bytes())); } } else { using var stream = new MemoryStream(); var settings = new XmlWriterSettings(); settings.Indent = true; using var writer = XmlWriter.Create(stream, settings); WriteXml(writer); writer.Flush(); return(stream.ToArray()); } }
public void WriteXml(XmlWriter writer) { writer.WriteStartElement(Serialization.Prefix, "Doc", Serialization.Namespace); var serializationMode = Serialization.Selected; if (serializationMode == Serialization.Mode.SpacyAndDotNet) { using (Py.GIL()) { var pyObj = Interop.GetBytes(PyDoc.to_bytes()); var pyObjB64 = Convert.ToBase64String(pyObj); writer.WriteElementString("PyObj", Serialization.Namespace, pyObjB64); } } Debug.Assert(serializationMode != Serialization.Mode.Spacy); // Using the property is important form the members to be loaded writer.WriteElementString("Text", Serialization.Namespace, Text); writer.WriteStartElement("Vocab", Serialization.Namespace); Vocab.WriteXml(writer); writer.WriteEndElement(); writer.WriteStartElement("Tokens", Serialization.Namespace); foreach (var token in Tokens) { writer.WriteStartElement("Token", Serialization.Namespace); token.WriteXml(writer); writer.WriteEndElement(); } writer.WriteEndElement(); writer.WriteStartElement("Sentences", Serialization.Namespace); foreach (var sent in Sents) { writer.WriteStartElement("Sent", Serialization.Namespace); sent.WriteXml(writer); writer.WriteEndElement(); } writer.WriteEndElement(); writer.WriteStartElement("NounChunks", Serialization.Namespace); foreach (var nounChunk in NounChunks) { writer.WriteStartElement("NounChunk", Serialization.Namespace); nounChunk.WriteXml(writer); writer.WriteEndElement(); } writer.WriteEndElement(); writer.WriteStartElement("Ents", Serialization.Namespace); foreach (var ent in Ents) { writer.WriteStartElement("Ent", Serialization.Namespace); ent.WriteXml(writer); writer.WriteEndElement(); } writer.WriteEndElement(); writer.WriteEndElement(); }