ctakes-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dlig...@apache.org
Subject svn commit: r1524179 - /ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/data/analysis/SignSymptomDurations.java
Date Tue, 17 Sep 2013 18:59:55 GMT
Author: dligach
Date: Tue Sep 17 18:59:54 2013
New Revision: 1524179

URL: http://svn.apache.org/r1524179
Log:
more readable implementation of the same logic

Modified:
    ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/data/analysis/SignSymptomDurations.java

Modified: ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/data/analysis/SignSymptomDurations.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/data/analysis/SignSymptomDurations.java?rev=1524179&r1=1524178&r2=1524179&view=diff
==============================================================================
--- ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/data/analysis/SignSymptomDurations.java
(original)
+++ ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/data/analysis/SignSymptomDurations.java
Tue Sep 17 18:59:54 2013
@@ -90,23 +90,11 @@ public class SignSymptomDurations {
       for(SignSymptomMention signSymptomMention : JCasUtil.select(jCas, SignSymptomMention.class))
{
 
         if(signSymptomMention.getCoveredText().equals(signSymptomText)) {
-          // distances to time expressions from this sign/symptom
-          Map<TimeMention, Integer> distances = new HashMap<TimeMention, Integer>();
+          TimeMention nearestTimeMention = getNearestTimeMention(jCas, signSymptomMention);
 
-          for(TimeMention timeMention : JCasUtil.selectFollowing(jCas, TimeMention.class,
signSymptomMention, 1)) {
-            int distance = JCasUtil.selectBetween(jCas, BaseToken.class, signSymptomMention,
timeMention).size();
-            distances.put(timeMention, distance);
-          }
-
-          // find closest time to this sign/symptom
-          List<TimeMention> sortedTimeMentions = new ArrayList<TimeMention>(distances.keySet());
-          Function<TimeMention, Integer> getValue = Functions.forMap(distances);
-          Collections.sort(sortedTimeMentions, Ordering.natural().onResultOf(getValue));
+          if(nearestTimeMention != null) {
+            Matcher matcher = pattern.matcher(nearestTimeMention.getCoveredText());
 
-          if(sortedTimeMentions.size() > 0 && distances.get(sortedTimeMentions.get(0))
<= maxDistance) {
-
-            String timex = sortedTimeMentions.get(0).getCoveredText();
-            Matcher matcher = pattern.matcher(timex);
             while(matcher.find()) {
               durationDistribution.add(matcher.group());
             }
@@ -115,9 +103,42 @@ public class SignSymptomDurations {
       }
 
       if(durationDistribution.size() > 0) { 
-        String durationDistributionAsString = convertToString(durationDistribution);
-        System.out.println(signSymptomText + "," + durationDistributionAsString);
+        System.out.println(signSymptomText + "," + convertToString(durationDistribution));
+        // System.out.println(signSymptomText + ": " + durationDistribution);
+      }
+    }
+    
+    /**
+     * Find nearest time mention. Return null if none found.
+     */
+    private static TimeMention getNearestTimeMention(JCas jCas, SignSymptomMention signSymptomMention)
{
+      
+      // max distance between a time and an evenet
+      final int MAXDISTANCE = 2;
+      
+      // distances to time expressions from this sign/symptom
+      Map<TimeMention, Integer> distances = new HashMap<TimeMention, Integer>();
+
+      for(TimeMention timeMention : JCasUtil.selectFollowing(jCas, TimeMention.class, signSymptomMention,
1)) {
+        int distance = JCasUtil.selectBetween(jCas, BaseToken.class, signSymptomMention,
timeMention).size();
+        distances.put(timeMention, distance);
+      }
+
+      if(distances.size() < 1) {
+        return null;
       }
+      
+      // sort time mentions by distance to sign/symptom
+      List<TimeMention> sortedTimeMentions = new ArrayList<TimeMention>(distances.keySet());
+      Function<TimeMention, Integer> getValue = Functions.forMap(distances);
+      Collections.sort(sortedTimeMentions, Ordering.natural().onResultOf(getValue));
+
+      // if the closest one too far away, return null
+      if(distances.get(sortedTimeMentions.get(0)) > MAXDISTANCE) {
+        return null;
+      }
+      
+      return sortedTimeMentions.get(0);
     }
     
     private static String convertToString(Multiset<String> durationDistribution) {



Mime
View raw message