ctakes-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c...@apache.org
Subject svn commit: r1466028 - in /ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae: DocTimeRelAnnotator.java feature/NearbyVerbTenseXExtractor.java
Date Tue, 09 Apr 2013 13:43:15 GMT
Author: clin
Date: Tue Apr  9 13:43:15 2013
New Revision: 1466028

URL: http://svn.apache.org/r1466028
Log:
Add nearby Verb POS pattern feature extractor for docTimerel.

Added:
    ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/NearbyVerbTenseXExtractor.java
  (with props)
Modified:
    ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/DocTimeRelAnnotator.java

Modified: ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/DocTimeRelAnnotator.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/DocTimeRelAnnotator.java?rev=1466028&r1=1466027&r2=1466028&view=diff
==============================================================================
--- ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/DocTimeRelAnnotator.java
(original)
+++ ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/DocTimeRelAnnotator.java
Tue Apr  9 13:43:15 2013
@@ -21,6 +21,7 @@ package org.apache.ctakes.temporal.ae;
 import java.io.File;
 import java.util.List;
 
+import org.apache.ctakes.temporal.ae.feature.NearbyVerbTenseXExtractor;
 import org.apache.ctakes.typesystem.type.syntax.BaseToken;
 import org.apache.ctakes.typesystem.type.textsem.EventMention;
 import org.apache.uima.UimaContext;
@@ -71,6 +72,7 @@ public class DocTimeRelAnnotator extends
   }
 
   private CleartkExtractor contextExtractor;
+  private NearbyVerbTenseXExtractor verbTensePatternExtractor;
 
   @Override
   public void initialize(UimaContext context) throws ResourceInitializationException {
@@ -84,6 +86,7 @@ public class DocTimeRelAnnotator extends
         new Preceding(3),
         new Covered(),
         new Following(3));
+    this.verbTensePatternExtractor = new NearbyVerbTenseXExtractor();
   }
 
   @Override
@@ -91,6 +94,7 @@ public class DocTimeRelAnnotator extends
     for (EventMention eventMention : JCasUtil.select(jCas, EventMention.class)) {
       if (eventMention.getEvent() != null) {
         List<Feature> features = this.contextExtractor.extract(jCas, eventMention);
+        features.addAll(this.verbTensePatternExtractor.extract(jCas, eventMention));//add
nearby verb POS pattern feature
         if (this.isTraining()) {
           String outcome = eventMention.getEvent().getProperties().getDocTimeRel();
           this.dataWriter.write(new Instance<String>(outcome, features));

Added: ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/NearbyVerbTenseXExtractor.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/NearbyVerbTenseXExtractor.java?rev=1466028&view=auto
==============================================================================
--- ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/NearbyVerbTenseXExtractor.java
(added)
+++ ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/NearbyVerbTenseXExtractor.java
Tue Apr  9 13:43:15 2013
@@ -0,0 +1,80 @@
+/**
+ * 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.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.logging.Logger;
+
+import org.apache.ctakes.typesystem.type.syntax.WordToken;
+import org.apache.ctakes.typesystem.type.textsem.EventMention;
+import org.apache.ctakes.typesystem.type.textspan.Sentence;
+import org.apache.uima.jcas.JCas;
+import org.apache.uima.jcas.tcas.Annotation;
+import org.cleartk.classifier.Feature;
+import org.cleartk.classifier.feature.extractor.CleartkExtractorException;
+import org.cleartk.classifier.feature.extractor.simple.SimpleFeatureExtractor;
+import org.uimafit.util.JCasUtil;
+
+public class NearbyVerbTenseXExtractor implements SimpleFeatureExtractor {
+
+  private String name;
+
+  private Logger logger = Logger.getLogger(this.getClass().getName());
+
+  public NearbyVerbTenseXExtractor() {
+    super();
+    this.name = "VerbTenseFeature";
+    
+  }
+
+  @Override
+  public List<Feature> extract(JCas view, Annotation annotation) throws CleartkExtractorException
{
+	  List<Feature> features = new ArrayList<Feature>();
+	  
+	  //1 get covering sentence:
+	  Map<EventMention, Collection<Sentence>> coveringMap =
+			  JCasUtil.indexCovering(view, EventMention.class, Sentence.class);
+	  EventMention targetTokenAnnotation = (EventMention)annotation;
+	  Collection<Sentence> sentList = coveringMap.get(targetTokenAnnotation);
+	  
+	  //2 get Verb Tense
+	  if (sentList != null && !sentList.isEmpty()){
+		  for(Sentence sent : sentList) {
+			  String verbTP ="";
+			  for ( WordToken wt : JCasUtil.selectCovered(view, WordToken.class, sent)) {
+				  if (wt != null){
+					  String pos = wt.getPartOfSpeech();
+					  if (pos.startsWith("VB")){
+						  verbTP = verbTP + "_" + pos;
+					  }
+				  }
+			  }
+			  Feature feature = new Feature(this.name, verbTP);
+			  features.add(feature);
+			  logger.info("found nearby verb's pos tag: "+ verbTP);
+		  }
+		  
+	  }
+	  return features;
+  }
+
+}

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



Mime
View raw message