ctakes-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dlig...@apache.org
Subject svn commit: r1552731 - /ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/DurationTimeUnitFeatureExtractor.java
Date Fri, 20 Dec 2013 16:46:40 GMT
Author: dligach
Date: Fri Dec 20 16:46:40 2013
New Revision: 1552731

URL: http://svn.apache.org/r1552731
Log:
using duration in seconds rather than the name of the time unit

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

Modified: ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/DurationTimeUnitFeatureExtractor.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/DurationTimeUnitFeatureExtractor.java?rev=1552731&r1=1552730&r2=1552731&view=diff
==============================================================================
--- ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/DurationTimeUnitFeatureExtractor.java
(original)
+++ ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/DurationTimeUnitFeatureExtractor.java
Fri Dec 20 16:46:40 2013
@@ -27,7 +27,9 @@ import info.bethard.timenorm.TimeSpanSet
 
 import java.net.URL;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import org.apache.ctakes.relationextractor.ae.features.RelationFeaturesExtractor;
 import org.apache.ctakes.typesystem.type.textsem.IdentifiedAnnotation;
@@ -56,9 +58,11 @@ public class DurationTimeUnitFeatureExtr
       scala.collection.Iterator<TemporalUnit> iterator = units.iterator();
       while(iterator.hasNext()) {
         TemporalUnit unit = iterator.next();
-        features.add(new Feature("time_unit", unit.getName()));
+        Map<String, Float> distribution = convertToDistribution(unit.getName());
+        float expectedDuration = DurationExpectationFeatureExtractor.expectedDuration(distribution);
+        features.add(new Feature("expected_duration", expectedDuration));
       }
-    }
+    } 
 
     return features; 
   }
@@ -88,4 +92,26 @@ public class DurationTimeUnitFeatureExtr
     
     return units;
   }
+  
+  /**
+   * Take a time unit and return a probability distribution
+   * in which p(this time unit) = 1 and all others are zero.
+   */
+  public static Map<String, Float> convertToDistribution(String timeUnit) {
+    
+    String[] bins = {"second", "minute", "hour", "day", "week", "month", "year"};
+    Map<String, Float> distribution = new HashMap<String, Float>();
+    
+    for(String bin: bins) {
+      // convert things like "Hours" to "hour"
+      String normalized = timeUnit.substring(0, timeUnit.length() - 1).toLowerCase(); 
+      if(bin.equals(normalized)) {
+        distribution.put(bin, 1.0f);
+      } else {
+        distribution.put(bin, 0.0f);
+      }
+    }
+    
+    return distribution;
+  }
 }



Mime
View raw message