Revision: 18589
          http://sourceforge.net/p/gate/code/18589
Author:   markagreenwood
Date:     2015-02-26 14:15:49 +0000 (Thu, 26 Feb 2015)
Log Message:
-----------
relations now ssaved when documents added to datastores

Modified Paths:
--------------
    gate/trunk/src/main/gate/annotation/AnnotationSetImpl.java
    gate/trunk/src/main/gate/relations/RelationSet.java

Modified: gate/trunk/src/main/gate/annotation/AnnotationSetImpl.java
===================================================================
--- gate/trunk/src/main/gate/annotation/AnnotationSetImpl.java  2015-02-25 
02:19:47 UTC (rev 18588)
+++ gate/trunk/src/main/gate/annotation/AnnotationSetImpl.java  2015-02-26 
14:15:49 UTC (rev 18589)
@@ -44,6 +44,7 @@
 import gate.event.AnnotationSetListener;
 import gate.event.GateEvent;
 import gate.event.GateListener;
+import gate.relations.Relation;
 import gate.relations.RelationSet;
 import gate.util.InvalidOffsetException;
 import gate.util.RBTreeMap;
@@ -1308,7 +1309,10 @@
     annotations = new Annotation[this.annotsById.size()];
     annotations = this.annotsById.values().toArray(annotations);
     // out.writeObject(annotations);
-    pf.put("annotations", this.annotations);
+    pf.put("annotations", this.annotations);    
+    pf.put("relations", this.relations);
+    
+    
     out.writeFields();
     annotations = null;
     boolean isIndexedByType = (this.annotsByType != null);
@@ -1326,6 +1330,7 @@
     boolean isIndexedByType = false;
     boolean isIndexedByStartNode = false;
     this.annotations = (Annotation[])gf.get("annotations", null);
+    
     if(this.annotations == null) {
       // old style serialised version
       @SuppressWarnings("unchecked")
@@ -1360,6 +1365,9 @@
     for(int i = 0; i < annotations.length; i++) {
       add(annotations[i]);
     }
+    
+    this.relations = (RelationSet)gf.get("relations", null);
+    
     annotations = null;
   }
   

Modified: gate/trunk/src/main/gate/relations/RelationSet.java
===================================================================
--- gate/trunk/src/main/gate/relations/RelationSet.java 2015-02-25 02:19:47 UTC 
(rev 18588)
+++ gate/trunk/src/main/gate/relations/RelationSet.java 2015-02-26 14:15:49 UTC 
(rev 18589)
@@ -23,6 +23,9 @@
 import gate.event.RelationSetEvent;
 import gate.event.RelationSetListener;
 
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
 import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.BitSet;
@@ -93,6 +96,11 @@
    * of the index access operations
    */
   private int maxID = 0;
+  
+  /**
+   * Use only for serialization
+   */
+  private Relation[] relations;
 
   /**
    * The {@link AnnotationSet} which this instance belongs to.
@@ -628,4 +636,34 @@
   public <T> T[] toArray(T[] store) {
     return indexById.values().toArray(store);
   }
+  
+  private void writeObject(java.io.ObjectOutputStream out) throws IOException {
+    ObjectOutputStream.PutField pf = out.putFields();
+    
+    pf.put("annSet", annSet);
+    pf.put("relations", toArray(new Relation[size()]));
+    out.writeFields();
+  }
+  
+  private void readObject(java.io.ObjectInputStream in) throws IOException,
+          ClassNotFoundException {
+    ObjectInputStream.GetField gf = in.readFields();
+    
+    annSet = (AnnotationSet)gf.get("annSet", null);
+    relations = (Relation[])gf.get("relations", null);
+    
+    indexByType = new HashMap<String, BitSet>();
+    indexesByMember = new ArrayList<Map<Integer, BitSet>>();
+    indexById = new HashMap<Integer, Relation>();
+
+    annSet.addAnnotationSetListener(this);
+    
+    if (relations != null) {
+      for (Relation r : relations) {
+        add(r);
+      }      
+    }
+    
+    relations = null;
+  }
 }

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


------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the 
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs

Reply via email to