ctakes-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dlig...@apache.org
Subject svn commit: r1554897 - /ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/PreserveCertainEventTimeRelationsInGold.java
Date Thu, 02 Jan 2014 20:20:16 GMT
Author: dligach
Date: Thu Jan  2 20:20:16 2014
New Revision: 1554897

URL: http://svn.apache.org/r1554897
Log:
fixed a bug; now checking for type of arg1/2

Modified:
    ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/PreserveCertainEventTimeRelationsInGold.java

Modified: ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/PreserveCertainEventTimeRelationsInGold.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/PreserveCertainEventTimeRelationsInGold.java?rev=1554897&r1=1554896&r2=1554897&view=diff
==============================================================================
--- ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/PreserveCertainEventTimeRelationsInGold.java
(original)
+++ ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/PreserveCertainEventTimeRelationsInGold.java
Thu Jan  2 20:20:16 2014
@@ -1,5 +1,11 @@
 package org.apache.ctakes.temporal.ae;
 
+import java.io.File;
+import java.io.IOException;
+import java.util.Map;
+
+import org.apache.ctakes.temporal.ae.feature.duration.DurationDistributionFeatureExtractor.Callback;
+import org.apache.ctakes.temporal.ae.feature.duration.DurationTimeUnitFeatureExtractor;
 import org.apache.ctakes.typesystem.type.relation.BinaryTextRelation;
 import org.apache.ctakes.typesystem.type.relation.RelationArgument;
 import org.apache.ctakes.typesystem.type.textsem.EventMention;
@@ -7,11 +13,20 @@ import org.apache.ctakes.typesystem.type
 import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
 import org.apache.uima.cas.CASException;
 import org.apache.uima.jcas.JCas;
+import org.threeten.bp.temporal.TemporalUnit;
 import org.uimafit.component.JCasAnnotator_ImplBase;
 import org.uimafit.util.JCasUtil;
 
+import scala.collection.immutable.Set;
+
+import com.google.common.base.Charsets;
 import com.google.common.collect.Lists;
+import com.google.common.io.Files;
 
+/**
+ * Preserve only those event-time relations whose event argument has duration data
+ * and whose time argument can be normalized using Steve's timex normalizer.
+ */
 public class PreserveCertainEventTimeRelationsInGold extends JCasAnnotator_ImplBase {   
                                           
   
   public static final String GOLD_VIEW_NAME = "GoldView";
@@ -19,23 +34,48 @@ public class PreserveCertainEventTimeRel
   @Override                                                                             
                                    
   public void process(JCas jCas) throws AnalysisEngineProcessException {                
                                    
 
+    File durationLookup = new File("/Users/Dima/Boston/Thyme/Duration/Output/Duration/distribution.txt");
                     
+    Map<String, Map<String, Float>> textToDistribution = null;              
                                                  
+    try {                                                                               
                                      
+      textToDistribution = Files.readLines(durationLookup, Charsets.UTF_8, new Callback());
                                   
+    } catch(IOException e) {                                                            
                                      
+      e.printStackTrace();                                                              
                                      
+      return;                                                                           
                                      
+    }  
+    
     JCas goldView;                                                                      
                                    
     try {                                                                               
                                    
       goldView = jCas.getView(GOLD_VIEW_NAME);                                          
                                    
     } catch (CASException e) {                                                          
                                    
       throw new AnalysisEngineProcessException(e);                                      
                                    
     }                                                                                   
                                                                                         
                                                           
-                                                                                        
                                    
+    
     for (BinaryTextRelation relation : Lists.newArrayList(JCasUtil.select(goldView, BinaryTextRelation.class)))
{            
-      RelationArgument arg1 = relation.getArg1(); // arg1 is an event                   
                                                        
-      RelationArgument arg2 = relation.getArg2(); // arg2 is a time expression
+      RelationArgument arg1 = relation.getArg1();                                       
                                     
+      RelationArgument arg2 = relation.getArg2(); 
       
-      if(arg1.getArgument() instanceof EventMention && arg2.getArgument() instanceof
TimeMention){
-        arg1.removeFromIndexes();                                                       
                                    
-        arg2.removeFromIndexes();                                                       
                                    
-        relation.removeFromIndexes();
-        System.out.println("removing: " + relation.getCategory());
-      }                                                                                 
                                    
+      String eventText;
+      String timeText;
+      if(arg1.getArgument() instanceof TimeMention && arg2.getArgument() instanceof
EventMention) {
+        timeText = arg1.getArgument().getCoveredText().toLowerCase(); 
+        eventText = arg2.getArgument().getCoveredText().toLowerCase();  
+      } else if(arg1.getArgument() instanceof EventMention && arg2.getArgument()
instanceof TimeMention) {
+        eventText = arg1.getArgument().getCoveredText().toLowerCase(); 
+        timeText = arg2.getArgument().getCoveredText().toLowerCase();  
+      } else {
+        // this is not a event-time relation
+        continue;
+      }    
+
+      Set<TemporalUnit> units = DurationTimeUnitFeatureExtractor.normalize(timeText);
+      if(textToDistribution.containsKey(eventText) && units != null) {
+        // there is duration information and we are able to get time units, so keep this
+        continue;
+      }
+
+      arg1.removeFromIndexes();                                                         
                                  
+      arg2.removeFromIndexes();                                                         
                                  
+      relation.removeFromIndexes();
     }                                                                                   
                                    
   }                                                                                     
                                    
 }                                                                                       
                                    
\ No newline at end of file



Mime
View raw message