Revision: 19779
          http://sourceforge.net/p/gate/code/19779
Author:   markagreenwood
Date:     2016-11-24 10:18:32 +0000 (Thu, 24 Nov 2016)
Log Message:
-----------
bit of tidying up

Modified Paths:
--------------
    
gate/branches/sawdust2/plugins/Format_Twitter/src/main/java/gate/corpora/JSONTweetFormat.java
    
gate/branches/sawdust2/plugins/Format_Twitter/src/main/java/gate/corpora/twitter/Population.java
    
gate/branches/sawdust2/plugins/Format_Twitter/src/main/java/gate/corpora/twitter/Tweet.java

Modified: 
gate/branches/sawdust2/plugins/Format_Twitter/src/main/java/gate/corpora/JSONTweetFormat.java
===================================================================
--- 
gate/branches/sawdust2/plugins/Format_Twitter/src/main/java/gate/corpora/JSONTweetFormat.java
       2016-11-24 09:51:59 UTC (rev 19778)
+++ 
gate/branches/sawdust2/plugins/Format_Twitter/src/main/java/gate/corpora/JSONTweetFormat.java
       2016-11-24 10:18:32 UTC (rev 19779)
@@ -110,9 +110,9 @@
       doc.edit(0L, doc.getContent().size(), newContent);
 
       // Create Original markups annotations for each tweet
-      for (Tweet tweet : tweetStarts.keySet()) {
-        for (PreAnnotation preAnn : tweet.getAnnotations()) {
-          preAnn.toAnnotation(doc, tweetStarts.get(tweet));
+      for (Map.Entry<Tweet, Long> entry: tweetStarts.entrySet()) {
+        for (PreAnnotation preAnn : entry.getKey().getAnnotations()) {
+          preAnn.toAnnotation(doc, entry.getValue());
         }
       }
     }

Modified: 
gate/branches/sawdust2/plugins/Format_Twitter/src/main/java/gate/corpora/twitter/Population.java
===================================================================
--- 
gate/branches/sawdust2/plugins/Format_Twitter/src/main/java/gate/corpora/twitter/Population.java
    2016-11-24 09:51:59 UTC (rev 19778)
+++ 
gate/branches/sawdust2/plugins/Format_Twitter/src/main/java/gate/corpora/twitter/Population.java
    2016-11-24 10:18:32 UTC (rev 19779)
@@ -21,6 +21,7 @@
 import gate.creole.metadata.CreoleResource;
 import gate.gui.NameBearerHandle;
 import gate.gui.ResourceHelper;
+import gate.persist.PersistenceException;
 import gate.util.GateRuntimeException;
 import gate.util.InvalidOffsetException;
 import java.awt.event.ActionEvent;
@@ -126,7 +127,7 @@
       }
       
     }
-    catch (Exception e) {
+    catch (IOException | InvalidOffsetException | PersistenceException | 
SecurityException e) {
       throw new ResourceInstantiationException(e);
     }
     finally {
@@ -163,13 +164,13 @@
     else {    
       DocumentContent contentImpl = new 
DocumentContentImpl(content.toString());
       document.setContent(contentImpl);
-      for (PreAnnotation preAnn : annotandaOffsets.keySet()) {
+      for (Map.Entry<PreAnnotation,Integer> entry : 
annotandaOffsets.entrySet()) {
         try {
-          preAnn.toAnnotation(document, annotandaOffsets.get(preAnn));
+          entry.getKey().toAnnotation(document, entry.getValue());
         } catch (InvalidOffsetException ex) {
           // show the content in the error message, so it becomes more easy to 
find the 
           // cause of an InvalidOffsetException in a large file that has many 
json entries.
-          throw new GateRuntimeException("Attempt to add annotation "+preAnn+" 
for text="+contentImpl,ex);
+          throw new GateRuntimeException("Attempt to add annotation 
"+entry.getKey()+" for text="+contentImpl,ex);
         }
       }
       corpus.add(document);
@@ -188,7 +189,20 @@
 
     if(!(handle.getTarget() instanceof Corpus)) return actions;
 
-    actions.add(new AbstractAction("Populate from Twitter JSON files") {
+    actions.add(new PopulateAction((Corpus)handle.getTarget()));
+
+    return actions;
+  }
+  
+  private static class PopulateAction extends AbstractAction {
+         
+         private Corpus corpus;
+         
+         public PopulateAction(Corpus corpus) {
+                 super("Populate from Twitter JSON files");
+                 this.corpus = corpus;
+         }
+         
       private static final long serialVersionUID = -8511779592856786327L;
 
       @Override
@@ -209,7 +223,7 @@
                 public void run() {
                   for (URL fileUrl : fileUrls) {
                     try {
-                      populateCorpus((Corpus) handle.getTarget(), fileUrl, 
dialog.getConfig());
+                      populateCorpus(corpus, fileUrl, dialog.getConfig());
                     } catch(ResourceInstantiationException e) {
                       logger.warn("Error in Twitter Population, url="+fileUrl, 
e);
                     }
@@ -223,9 +237,6 @@
           logger.warn("Error in Twitter Population", e0);
         }
       }
-    });
+    }
 
-    return actions;
-  }
-
 }

Modified: 
gate/branches/sawdust2/plugins/Format_Twitter/src/main/java/gate/corpora/twitter/Tweet.java
===================================================================
--- 
gate/branches/sawdust2/plugins/Format_Twitter/src/main/java/gate/corpora/twitter/Tweet.java
 2016-11-24 09:51:59 UTC (rev 19778)
+++ 
gate/branches/sawdust2/plugins/Format_Twitter/src/main/java/gate/corpora/twitter/Tweet.java
 2016-11-24 10:18:32 UTC (rev 19779)
@@ -88,7 +88,7 @@
       } else if(key.equals("entities") && handleEntities) {
         // do nothing - don't add entities as a feature
       } else {
-        features.put(key.toString(), TweetUtils.process(json.get(key)));
+        features.put(key, TweetUtils.process(json.get(key)));
       }
     }
     

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


------------------------------------------------------------------------------
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs

Reply via email to