Revision: 18432
          http://sourceforge.net/p/gate/code/18432
Author:   ian_roberts
Date:     2014-11-06 14:22:47 +0000 (Thu, 06 Nov 2014)
Log Message:
-----------
When serializing entities as JSON, make sure to use a consistent order - 
entities of a given type are now always written in document order.

Modified Paths:
--------------
    gate/trunk/plugins/Twitter/src/gate/corpora/export/GATEJsonExporter.java

Modified: 
gate/trunk/plugins/Twitter/src/gate/corpora/export/GATEJsonExporter.java
===================================================================
--- gate/trunk/plugins/Twitter/src/gate/corpora/export/GATEJsonExporter.java    
2014-11-06 02:20:17 UTC (rev 18431)
+++ gate/trunk/plugins/Twitter/src/gate/corpora/export/GATEJsonExporter.java    
2014-11-06 14:22:47 UTC (rev 18432)
@@ -37,6 +37,7 @@
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
+import java.util.LinkedHashMap;
 import java.util.Map;
 import java.util.Set;
 
@@ -191,7 +192,7 @@
       boolean includeText = (options.containsKey("includeText")
               ? ((Boolean)options.get("includeText")).booleanValue() : true);
 
-      Map<String,Collection<Annotation>> annotationsMap = new HashMap<>();
+      Map<String,Collection<Annotation>> annotationsMap = new 
LinkedHashMap<>();
       
       for (String type : types) {
         String[] setAndType = type.split(":", 2);
@@ -210,14 +211,18 @@
       }
       if(docAnnots == null || docAnnots.isEmpty()) {
         // no document annotations, write everything
-        DocumentJsonUtils.writeDocument(doc, 0L, Utils.end(doc), 
annotationsMap, null, null, includeText, generator);
+        Map<String, Collection<Annotation>> sortedAnnots = new 
LinkedHashMap<>();
+        for(Map.Entry<String, Collection<Annotation>> entry : 
annotationsMap.entrySet()) {
+          sortedAnnots.put(entry.getKey(), 
Utils.inDocumentOrder((AnnotationSet)entry.getValue()));
+        }
+        DocumentJsonUtils.writeDocument(doc, 0L, Utils.end(doc), sortedAnnots, 
null, null, includeText, generator);
       } else {
         for(Annotation docAnnot : Utils.inDocumentOrder(docAnnots)) {
           Map<String, Collection<Annotation>> coveredAnnotations = new 
HashMap<>();
           for(Map.Entry<String, Collection<Annotation>> entry : 
annotationsMap.entrySet()) {
             coveredAnnotations.put(entry.getKey(),
-                    ((AnnotationSet)entry.getValue()).getContained(
-                            Utils.start(docAnnot), Utils.end(docAnnot)));
+                    
Utils.inDocumentOrder(((AnnotationSet)entry.getValue()).getContained(
+                            Utils.start(docAnnot), Utils.end(docAnnot))));
           }
           DocumentJsonUtils.writeDocument(doc, Utils.start(docAnnot), 
Utils.end(docAnnot),
                   coveredAnnotations, docAnnot.getFeatures(), null, 
includeText, generator);

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
_______________________________________________
GATE-cvs mailing list
GATE-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gate-cvs

Reply via email to