ctakes-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dlig...@apache.org
Subject svn commit: r1550243 - /ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/
Date Wed, 11 Dec 2013 20:02:51 GMT
Author: dligach
Date: Wed Dec 11 20:02:51 2013
New Revision: 1550243

URL: http://svn.apache.org/r1550243
Log:
refactoring + new duration features for event-time relations

Added:
    ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/DurationEventEventFeatureExtractor.java
      - copied, changed from r1549631, ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/EventDurationFeatureExtractor.java
    ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/DurationEventTimeFeatureExtractor.java
  (with props)
    ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/DurationExpectationFeatureExtractor.java
      - copied, changed from r1549631, ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/ExpectedDurationFeatureExtractor.java
Removed:
    ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/EventDurationFeatureExtractor.java
    ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/ExpectedDurationFeatureExtractor.java
Modified:
    ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/DurationDistributionFeatureExtractor.java

Modified: ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/DurationDistributionFeatureExtractor.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/DurationDistributionFeatureExtractor.java?rev=1550243&r1=1550242&r2=1550243&view=diff
==============================================================================
--- ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/DurationDistributionFeatureExtractor.java
(original)
+++ ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/DurationDistributionFeatureExtractor.java
Wed Dec 11 20:02:51 2013
@@ -65,7 +65,7 @@ public class DurationDistributionFeature
     return features;
   }
 
-  private static class Callback implements LineProcessor <Map<String, Map<String,
Float>>> {
+  public static class Callback implements LineProcessor <Map<String, Map<String,
Float>>> {
 
     // map event text to its duration distribution
     private Map<String, Map<String, Float>> textToDistribution;

Copied: ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/DurationEventEventFeatureExtractor.java
(from r1549631, ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/EventDurationFeatureExtractor.java)
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/DurationEventEventFeatureExtractor.java?p2=ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/DurationEventEventFeatureExtractor.java&p1=ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/EventDurationFeatureExtractor.java&r1=1549631&r2=1550243&rev=1550243&view=diff
==============================================================================
--- ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/EventDurationFeatureExtractor.java
(original)
+++ ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/DurationEventEventFeatureExtractor.java
Wed Dec 11 20:02:51 2013
@@ -21,22 +21,20 @@ package org.apache.ctakes.temporal.ae.fe
 import java.io.File;
 import java.io.IOException;
 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.temporal.ae.feature.DurationDistributionFeatureExtractor.Callback;
 import org.apache.ctakes.typesystem.type.textsem.IdentifiedAnnotation;
 import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
 import org.apache.uima.jcas.JCas;
 import org.cleartk.classifier.Feature;
 
 import com.google.common.base.Charsets;
-import com.google.common.collect.ImmutableMap;
 import com.google.common.io.Files;
-import com.google.common.io.LineProcessor;
 
-public class EventDurationFeatureExtractor implements RelationFeaturesExtractor {
+public class DurationEventEventFeatureExtractor implements RelationFeaturesExtractor {
 
   @Override
   public List<Feature> extract(JCas jCas, IdentifiedAnnotation arg1, IdentifiedAnnotation
arg2)
@@ -59,7 +57,7 @@ public class EventDurationFeatureExtract
     if(arg1Distribution == null) {
       features.add(new Feature("arg1_no_duration_info"));
     } else {
-      float expectation1 = ExpectedDurationFeatureExtractor.expectedDuration(arg1Distribution);
+      float expectation1 = DurationExpectationFeatureExtractor.expectedDuration(arg1Distribution);
       features.add(new Feature("arg1_expected_duration", expectation1));
     }
     
@@ -67,39 +65,10 @@ public class EventDurationFeatureExtract
     if(arg2Distribution == null) {
       features.add(new Feature("arg2_no_duration_info"));
     } else {
-      float expectation2 = ExpectedDurationFeatureExtractor.expectedDuration(arg2Distribution);
+      float expectation2 = DurationExpectationFeatureExtractor.expectedDuration(arg2Distribution);
       features.add(new Feature("arg2_expected_duration", expectation2));
     }
     
     return features;
   }
-  
-  private static class Callback implements LineProcessor <Map<String, Map<String,
Float>>> {
-
-    // map event text to its duration distribution
-    private Map<String, Map<String, Float>> textToDistribution;
-    
-    public Callback() {
-      textToDistribution = new HashMap<String, Map<String, Float>>();
-    }
-    
-    public boolean processLine(String line) throws IOException {
-
-      String[] elements = line.split(", "); // e.g. pain, second:0.000, minute:0.005, hour:0.099,
...
-      Map<String, Float> distribution = new HashMap<String, Float>();
-      
-      for(int durationBinNumber = 1; durationBinNumber < elements.length; durationBinNumber++)
{
-        String[] durationAndValue = elements[durationBinNumber].split(":"); // e.g. "day:0.475"
-        distribution.put(durationAndValue[0], Float.parseFloat(durationAndValue[1]));
-      }
-      
-      textToDistribution.put(elements[0], distribution);
-      return true;
-    }
-
-    public Map<String, Map<String, Float>> getResult() {
-
-      return textToDistribution;
-    }
-  }
 }
\ No newline at end of file

Added: ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/DurationEventTimeFeatureExtractor.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/DurationEventTimeFeatureExtractor.java?rev=1550243&view=auto
==============================================================================
--- ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/DurationEventTimeFeatureExtractor.java
(added)
+++ ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/DurationEventTimeFeatureExtractor.java
Wed Dec 11 20:02:51 2013
@@ -0,0 +1,69 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.ctakes.temporal.ae.feature;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.ctakes.relationextractor.ae.features.RelationFeaturesExtractor;
+import org.apache.ctakes.temporal.ae.feature.DurationDistributionFeatureExtractor.Callback;
+import org.apache.ctakes.typesystem.type.textsem.IdentifiedAnnotation;
+import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
+import org.apache.uima.jcas.JCas;
+import org.cleartk.classifier.Feature;
+
+import com.google.common.base.Charsets;
+import com.google.common.io.Files;
+
+public class DurationEventTimeFeatureExtractor implements RelationFeaturesExtractor {
+
+  @Override
+  public List<Feature> extract(JCas jCas, IdentifiedAnnotation arg1, IdentifiedAnnotation
arg2)
+      throws AnalysisEngineProcessException {
+
+    List<Feature> features = new ArrayList<Feature>();
+    File durationLookup = new File("/Users/dima/Boston/Thyme/Duration/Output/Duration/distribution.txt");
+    String eventText = arg1.getCoveredText().toLowerCase(); // event mention
+    String timeText = arg2.getCoveredText().toLowerCase();  // time mention
+    
+    Map<String, Map<String, Float>> textToDistribution = null;
+    try {
+      textToDistribution = Files.readLines(durationLookup, Charsets.UTF_8, new Callback());
+    } catch(IOException e) {
+      e.printStackTrace();
+      return features;
+    }
+    
+    Map<String, Float> eventDistribution = textToDistribution.get(eventText);
+    if(eventDistribution == null) {
+      features.add(new Feature("no_duration_info", true));
+    } else {
+      //float eventExpectedDuration = DurationExpectationFeatureExtractor.expectedDuration(eventDistribution);
+      //features.add(new Feature("expected_duration", eventExpectedDuration));
+      for(String timeUnit : eventDistribution.keySet()) {
+        features.add(new Feature("duration_" + timeUnit, eventDistribution.get(timeUnit)));
 
+      }
+    }
+    
+    return features; 
+  }
+}

Propchange: ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/DurationEventTimeFeatureExtractor.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Copied: ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/DurationExpectationFeatureExtractor.java
(from r1549631, ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/ExpectedDurationFeatureExtractor.java)
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/DurationExpectationFeatureExtractor.java?p2=ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/DurationExpectationFeatureExtractor.java&p1=ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/ExpectedDurationFeatureExtractor.java&r1=1549631&r2=1550243&rev=1550243&view=diff
==============================================================================
--- ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/ExpectedDurationFeatureExtractor.java
(original)
+++ ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/DurationExpectationFeatureExtractor.java
Wed Dec 11 20:02:51 2013
@@ -21,10 +21,10 @@ package org.apache.ctakes.temporal.ae.fe
 import java.io.File;
 import java.io.IOException;
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.ctakes.temporal.ae.feature.DurationDistributionFeatureExtractor.Callback;
 import org.apache.uima.jcas.JCas;
 import org.apache.uima.jcas.tcas.Annotation;
 import org.cleartk.classifier.Feature;
@@ -34,9 +34,8 @@ import org.cleartk.classifier.feature.ex
 import com.google.common.base.Charsets;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.io.Files;
-import com.google.common.io.LineProcessor;
 
-public class ExpectedDurationFeatureExtractor implements SimpleFeatureExtractor {
+public class DurationExpectationFeatureExtractor implements SimpleFeatureExtractor {
 
   @Override
   public List<Feature> extract(JCas view, Annotation annotation) throws CleartkExtractorException
{ 
@@ -87,33 +86,4 @@ public class ExpectedDurationFeatureExtr
   
     return expectation / converter.get("year");
   }
-  
-  private static class Callback implements LineProcessor <Map<String, Map<String,
Float>>> {
-
-    // map event text to its duration distribution
-    private Map<String, Map<String, Float>> textToDistribution;
-    
-    public Callback() {
-      textToDistribution = new HashMap<String, Map<String, Float>>();
-    }
-    
-    public boolean processLine(String line) throws IOException {
-
-      String[] elements = line.split(", "); // e.g. pain, second:0.000, minute:0.005, hour:0.099,
...
-      Map<String, Float> distribution = new HashMap<String, Float>();
-      
-      for(int durationBinNumber = 1; durationBinNumber < elements.length; durationBinNumber++)
{
-        String[] durationAndValue = elements[durationBinNumber].split(":"); // e.g. "day:0.475"
-        distribution.put(durationAndValue[0], Float.parseFloat(durationAndValue[1]));
-      }
-      
-      textToDistribution.put(elements[0], distribution);
-      return true;
-    }
-
-    public Map<String, Map<String, Float>> getResult() {
-
-      return textToDistribution;
-    }
-  }
 }
\ No newline at end of file



Mime
View raw message