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

Method toXML

src/main/java/gate/creole/annic/Parser.java:138–211  ·  view source on GitHub ↗

Given an array of instances of Hit, this method returns an xml representation of the Hit

(Hit[] hits)

Source from the content-addressed store, hash-verified

136 * representation of the Hit
137 */
138 public static String toXML(Hit[] hits) {
139 StringBuffer sb = new StringBuffer();
140
141 // first sentence
142 sb.append("<?xml version=\"1.0\"?>\n");
143
144 // root element
145 sb.append(wrap(HITS, true));
146
147 // iterating through each hit
148 for(int i = 0; i < hits.length; i++) {
149
150 // adding a hit element
151 sb.append(wrap(HIT, true));
152 sb.append(wrap(DOC_ID, hits[i].documentID));
153 sb.append(wrap(ANNOTATION_SET_NAME, hits[i].annotationSetName));
154 sb.append(wrap(START_OFFSET, hits[i].startOffset));
155 sb.append(wrap(END_OFFSET, hits[i].endOffset));
156 sb.append(wrap(QUERY, hits[i].queryString));
157
158
159 // it hit is an instance of Pattern, we need to add further
160 // information as well
161 if(hits[i] instanceof Pattern) {
162 Pattern pat = (Pattern)hits[i];
163 sb.append(wrap(LEFT_CONTEXT_START_OFFSET, pat
164 .getLeftContextStartOffset()));
165 sb
166 .append(wrap(RIGHT_CONTEXT_END_OFFSET, pat
167 .getRightContextEndOffset()));
168 sb.append(wrap(PATTERN_TEXT, pat.getPatternText()));
169
170 PatternAnnotation[] annots = pat.getPatternAnnotations();
171
172 // all annotations should be exported
173 sb.append(wrap(PATTERN_ANNOTATIONS, true));
174
175 // one annotation at a time
176 for(int j = 0; j < annots.length; j++) {
177 sb.append(wrap(PATTERN_ANNOTATION, true));
178 sb.append(wrap(START, annots[j].getStartOffset()));
179 sb.append(wrap(END, annots[j].getEndOffset()));
180 sb.append(wrap(TEXT, annots[j].getText()));
181 sb.append(wrap(TYPE, annots[j].getType()));
182 sb.append(wrap(POSITION, annots[j].getPosition()));
183 // exporting features as well
184 Map<String, String> features = annots[j].getFeatures();
185 sb.append(wrap(FEATURES, true));
186 // one feature at a time
187 //if(features != null) {
188 //Set<String> keySet = features.keySet();
189 //if(keySet != null) {
190 //Iterator<String> iter = keySet.iterator();
191 //while(iter.hasNext()) {
192 for (Map.Entry<String,String> entry : features.entrySet()) {
193 sb.append(wrap(FEATURE, true));
194 String key = entry.getKey();
195 sb.append(wrap(KEY, key));

Callers 3

testSearcherMethod · 0.95
toStringMethod · 0.80
writeParametersToDiskMethod · 0.80

Calls 15

wrapMethod · 0.95
getPatternTextMethod · 0.95
getPatternAnnotationsMethod · 0.95
getTextMethod · 0.80
getTypeMethod · 0.65
getFeaturesMethod · 0.65
getKeyMethod · 0.65
getValueMethod · 0.65
toStringMethod · 0.65
getStartOffsetMethod · 0.45

Tested by 1

testSearcherMethod · 0.76