ctakes-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tm...@apache.org
Subject svn commit: r1501804 - in /ctakes/trunk/ctakes-assertion/src/main/java/org/apache/ctakes/assertion/medfacts/cleartk: AssertionCleartkAnalysisEngine.java PolarityCleartkAnalysisEngine.java
Date Wed, 10 Jul 2013 15:41:45 GMT
Author: tmill
Date: Wed Jul 10 15:41:44 2013
New Revision: 1501804

URL: http://svn.apache.org/r1501804
Log:
Added lastLabel variable. Changed polarity engine to use constants.

Modified:
    ctakes/trunk/ctakes-assertion/src/main/java/org/apache/ctakes/assertion/medfacts/cleartk/AssertionCleartkAnalysisEngine.java
    ctakes/trunk/ctakes-assertion/src/main/java/org/apache/ctakes/assertion/medfacts/cleartk/PolarityCleartkAnalysisEngine.java

Modified: ctakes/trunk/ctakes-assertion/src/main/java/org/apache/ctakes/assertion/medfacts/cleartk/AssertionCleartkAnalysisEngine.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-assertion/src/main/java/org/apache/ctakes/assertion/medfacts/cleartk/AssertionCleartkAnalysisEngine.java?rev=1501804&r1=1501803&r2=1501804&view=diff
==============================================================================
--- ctakes/trunk/ctakes-assertion/src/main/java/org/apache/ctakes/assertion/medfacts/cleartk/AssertionCleartkAnalysisEngine.java
(original)
+++ ctakes/trunk/ctakes-assertion/src/main/java/org/apache/ctakes/assertion/medfacts/cleartk/AssertionCleartkAnalysisEngine.java
Wed Jul 10 15:41:44 2013
@@ -89,6 +89,7 @@ public abstract class AssertionCleartkAn
   
   protected Random coin = new Random(0);
 
+  protected String lastLabel;
   
 /* DEPRECATED: STW 2013/03/28.  Use DependencyUtility:getNominalHeadNode(jCas,annotation)
instead */
 //  public ConllDependencyNode findAnnotationHead(JCas jcas, Annotation annotation) {
@@ -217,6 +218,9 @@ public abstract class AssertionCleartkAn
     {
       logger.warn("processing next doc (doc id is null)");
     }
+    
+    this.lastLabel = "<BEGIN>";
+    
 //    // get gold standard relation instances during testing for error analysis
 //    if (! this.isTraining() && printErrors) {
 //      JCas goldView;
@@ -317,7 +321,7 @@ public abstract class AssertionCleartkAn
           }
 //          instance.addAll(cuePhraseInWindowExtractor.extractBetween(jCas, cue, entityOrEventMention));
         }
-        if(closestCue != null){
+        if(closestCue != null && closest < 21){
           instance.add(new Feature("ClosestCue_Word", closestCue.getCoveredText()));
 //          instance.add(new Feature("ClosestCue_Phrase", closestCue.getCuePhrase()));
           instance.add(new Feature("ClosestCue_PhraseFamily", closestCue.getCuePhraseAssertionFamily()));
@@ -330,7 +334,7 @@ public abstract class AssertionCleartkAn
 //      }
 
 
-      instance.add(new Feature("ENTITY_TYPE", entityOrEventMention.getTypeID()));
+      instance.add(new Feature("ENTITY_TYPE_" + entityOrEventMention.getTypeID()));
       
       for (SimpleFeatureExtractor extractor : this.entityFeatureExtractors) {
         instance.addAll(extractor.extract(jCas, entityOrEventMention));
@@ -344,17 +348,14 @@ public abstract class AssertionCleartkAn
       }
       
       List<Feature> feats = instance.getFeatures();
-//      List<Feature> lcFeats = new ArrayList<Feature>();
       
       for(Feature feat : feats){
     	  if(feat.getName() != null && (feat.getName().startsWith("TreeFrag") || feat.getName().startsWith("WORD")
|| feat.getName().startsWith("NEG"))) continue;
     	  if(feat.getValue() instanceof String){
     		  feat.setValue(((String)feat.getValue()).toLowerCase());
-//    		  lcFeats.add(new Feature("LC_" + feat.getName(), ((String)feat.getValue()).toLowerCase()));
     	  }
       }
-//      instance.addAll(lcFeats);
-
+      
       setClassLabel(entityOrEventMention, instance);
       
     }

Modified: ctakes/trunk/ctakes-assertion/src/main/java/org/apache/ctakes/assertion/medfacts/cleartk/PolarityCleartkAnalysisEngine.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-assertion/src/main/java/org/apache/ctakes/assertion/medfacts/cleartk/PolarityCleartkAnalysisEngine.java?rev=1501804&r1=1501803&r2=1501804&view=diff
==============================================================================
--- ctakes/trunk/ctakes-assertion/src/main/java/org/apache/ctakes/assertion/medfacts/cleartk/PolarityCleartkAnalysisEngine.java
(original)
+++ ctakes/trunk/ctakes-assertion/src/main/java/org/apache/ctakes/assertion/medfacts/cleartk/PolarityCleartkAnalysisEngine.java
Wed Jul 10 15:41:44 2013
@@ -24,6 +24,7 @@ import org.apache.ctakes.assertion.medfa
 import org.apache.ctakes.assertion.medfacts.cleartk.extractors.AboveRightFragmentExtractor;
 import org.apache.ctakes.assertion.medfacts.cleartk.extractors.ContextWordWindowExtractor;
 import org.apache.ctakes.assertion.medfacts.cleartk.extractors.NegationDependencyFeatureExtractor;
+import org.apache.ctakes.typesystem.type.constants.CONST;
 import org.apache.ctakes.typesystem.type.textsem.IdentifiedAnnotation;
 import org.apache.uima.UimaContext;
 import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
@@ -34,6 +35,9 @@ import org.cleartk.classifier.feature.ex
 
 public class PolarityCleartkAnalysisEngine extends AssertionCleartkAnalysisEngine {
 
+  public static final String NEGATED = "NEGATED";
+  public static final String NOT_NEGATED = "NOT_NEGATED";
+  
 	@Override
 	public void initialize(UimaContext context) throws ResourceInitializationException {
 		super.initialize(context);
@@ -52,13 +56,14 @@ public class PolarityCleartkAnalysisEngi
 	public void setClassLabel(IdentifiedAnnotation entityOrEventMention, Instance<String>
instance) throws AnalysisEngineProcessException {
 	      if (this.isTraining())
 	      {
-	        String polarity = (entityOrEventMention.getPolarity() == -1) ? "negated" : "present";
+	        String polarity = (entityOrEventMention.getPolarity() == CONST.NE_POLARITY_NEGATION_PRESENT)
? NEGATED : NOT_NEGATED; // "negated" : "present";
+	        this.lastLabel = polarity;
 	        // downsampling. initialize probabilityOfKeepingADefaultExample to 1.0 for no downsampling
-	        if ("negated".equals(polarity))
+	        if (NEGATED.equals(polarity))
 	        {
 	          logger.debug("TRAINING: " + polarity);
 	        }
-	        if ("present".equals(polarity) 
+	        if (NOT_NEGATED.equals(polarity) 
 	        		&& coin.nextDouble() >= this.probabilityOfKeepingADefaultExample) {
 	        	return;
 	        }
@@ -67,19 +72,17 @@ public class PolarityCleartkAnalysisEngi
 	      } else
 	      {
 	        String label = this.classifier.classify(instance.getFeatures());
-	        int polarity = 1;
-	        if (label!= null && label.equals("present"))
+	        this.lastLabel = label;
+	        int polarity = CONST.NE_POLARITY_NEGATION_ABSENT;
+	        if (NOT_NEGATED.equals(label))
 	        {
-	          polarity = 1;
-	        } else if (label != null && label.equals("negated"))
+	          polarity = CONST.NE_POLARITY_NEGATION_ABSENT;
+	        } else if (NEGATED.equals(label))
 	        {
-	          polarity = -1;
+	          polarity = CONST.NE_POLARITY_NEGATION_PRESENT;
+            logger.debug(String.format("DECODING/EVAL: %s//%s [%d-%d] (%s)", label, polarity,
entityOrEventMention.getBegin(), entityOrEventMention.getEnd(), entityOrEventMention.getClass().getName()));
 	        }
 	        entityOrEventMention.setPolarity(polarity);
-	        if ("negated".equals(label))
-	        {
-	          logger.debug(String.format("DECODING/EVAL: %s//%s [%d-%d] (%s)", label, polarity,
entityOrEventMention.getBegin(), entityOrEventMention.getEnd(), entityOrEventMention.getClass().getName()));
-	        }
 	      }
 	}
 }



Mime
View raw message