MCPcopy Create free account
hub / github.com/GateNLP/gate-core / toXml

Method toXml

src/main/java/gate/corpora/DocumentXmlUtils.java:59–111  ·  view source on GitHub ↗

Returns a GateXml document that is a custom XML format for wich there is a reader inside GATE called gate.xml.GateFormatXmlHandler. What it does is to serialize a GATE document in an XML format. @param doc the document to serialize. @return a string representing a Gate Xml document.

(TextualDocument doc)

Source from the content-addressed store, hash-verified

57 * @return a string representing a Gate Xml document.
58 */
59 public static String toXml(TextualDocument doc) {
60 // Initialize the xmlContent several time the size of the current document.
61 // This is because of the tags size. This measure is made to increase the
62 // performance of StringBuffer.
63 StringBuffer xmlContent = new StringBuffer(
64 DOC_SIZE_MULTIPLICATION_FACTOR
65 * (doc.getContent().size().intValue()));
66 // Add xml header
67 xmlContent.append("<?xml version=\"1.0\" encoding=\"");
68 xmlContent.append(doc.getEncoding());
69 xmlContent.append("\" ?>");
70 xmlContent.append(Strings.getNl());
71 // Add the root element
72 xmlContent.append("<GateDocument>\n");
73 xmlContent.append("<!-- The document's features-->\n\n");
74 xmlContent.append("<GateDocumentFeatures>\n");
75 xmlContent.append(featuresToXml(doc.getFeatures(),null));
76 xmlContent.append("</GateDocumentFeatures>\n");
77 xmlContent.append("<!-- The document content area with serialized"
78 + " nodes -->\n\n");
79 // Add plain text element
80 xmlContent.append("<TextWithNodes>");
81 xmlContent.append(textWithNodes(doc, doc.getContent().toString()));
82 xmlContent.append("</TextWithNodes>\n");
83 // Serialize as XML all document's annotation sets
84 // Serialize the default AnnotationSet
85 StatusListener sListener = (StatusListener)gate.Gate
86 .getListeners().get("gate.event.StatusListener");
87 if(sListener != null)
88 sListener.statusChanged("Saving the default annotation set ");
89 xmlContent.append("<!-- The default annotation set -->\n\n");
90 annotationSetToXml(doc.getAnnotations(), xmlContent);
91 // Serialize all others AnnotationSets
92 // namedAnnotSets is a Map containing all other named Annotation Sets.
93 Map<String,AnnotationSet> namedAnnotSets = doc.getNamedAnnotationSets();
94 if(namedAnnotSets != null) {
95 Iterator<AnnotationSet> iter = namedAnnotSets.values().iterator();
96 while(iter.hasNext()) {
97 AnnotationSet annotSet = iter.next();
98 xmlContent.append("<!-- Named annotation set -->\n\n");
99 // Serialize it as XML
100 if(sListener != null)
101 sListener.statusChanged("Saving " + annotSet.getName()
102 + " annotation set ");
103 annotationSetToXml(annotSet, xmlContent);
104 }// End while
105 }// End if
106 // Add the end of GateDocument
107 xmlContent.append("</GateDocument>");
108 if(sListener != null) sListener.statusChanged("Done !");
109 // return the XmlGateDocument
110 return xmlContent.toString();
111 }
112
113
114 /**

Callers

nothing calls this directly

Calls 15

getNlMethod · 0.95
featuresToXmlMethod · 0.95
textWithNodesMethod · 0.95
statusChangedMethod · 0.95
annotationSetToXmlMethod · 0.95
getListenersMethod · 0.80
sizeMethod · 0.65
getContentMethod · 0.65
getEncodingMethod · 0.65
getFeaturesMethod · 0.65
toStringMethod · 0.65
getMethod · 0.65

Tested by

no test coverage detected