ctakes-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chen...@apache.org
Subject svn commit: r1605432 - in /ctakes/trunk/ctakes-temporal/src/test/java/org/apach/ctakes/temporal/ae: BackwardsTimeAnnotatorTest.java ContextualModalityAnnotatorTest.java DocTimeRelAnnotatorTest.java EventAnnotatorTest.java
Date Wed, 25 Jun 2014 14:55:33 GMT
Author: chenpei
Date: Wed Jun 25 14:55:32 2014
New Revision: 1605432

URL: http://svn.apache.org/r1605432
Log:
CTAKES-82 - temporal unit tests.
The UMLS lookup is not actually required for runtime.
ContextModality property not quite ready for prime time yet.
Addded license headers for the new test classes.

Modified:
    ctakes/trunk/ctakes-temporal/src/test/java/org/apach/ctakes/temporal/ae/BackwardsTimeAnnotatorTest.java
    ctakes/trunk/ctakes-temporal/src/test/java/org/apach/ctakes/temporal/ae/ContextualModalityAnnotatorTest.java
    ctakes/trunk/ctakes-temporal/src/test/java/org/apach/ctakes/temporal/ae/DocTimeRelAnnotatorTest.java
    ctakes/trunk/ctakes-temporal/src/test/java/org/apach/ctakes/temporal/ae/EventAnnotatorTest.java

Modified: ctakes/trunk/ctakes-temporal/src/test/java/org/apach/ctakes/temporal/ae/BackwardsTimeAnnotatorTest.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-temporal/src/test/java/org/apach/ctakes/temporal/ae/BackwardsTimeAnnotatorTest.java?rev=1605432&r1=1605431&r2=1605432&view=diff
==============================================================================
--- ctakes/trunk/ctakes-temporal/src/test/java/org/apach/ctakes/temporal/ae/BackwardsTimeAnnotatorTest.java
(original)
+++ ctakes/trunk/ctakes-temporal/src/test/java/org/apach/ctakes/temporal/ae/BackwardsTimeAnnotatorTest.java
Wed Jun 25 14:55:32 2014
@@ -1,3 +1,21 @@
+/**
+ * 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.apach.ctakes.temporal.ae;
 
 import static org.junit.Assert.*;
@@ -48,7 +66,9 @@ public class BackwardsTimeAnnotatorTest 
 	    builder.add(ClinicalPipelineFactory.getTokenProcessingPipeline());
 	    builder.add(AnalysisEngineFactory.createPrimitiveDescription(CopyNPChunksToLookupWindowAnnotations.class));
 	    builder.add(AnalysisEngineFactory.createPrimitiveDescription(RemoveEnclosedLookupWindows.class));
-	    builder.add(UmlsDictionaryLookupAnnotator.createAnnotatorDescription());
+	    //Commented out the Dictionary lookup for the test
+	    //Uncomment and set -Dctakes.umlsuser and -Dctakes.umlspw env params if needed
+	    //builder.add(UmlsDictionaryLookupAnnotator.createAnnotatorDescription());
 	    builder.add(ClearNLPDependencyParserAE.createAnnotatorDescription());
 		
 		//Add BackwardsTimeAnnotator
@@ -64,9 +84,9 @@ public class BackwardsTimeAnnotatorTest 
 	    Collection<TimeMention> mentions = JCasUtil.select(jcas, TimeMention.class);
 
 	    ArrayList<String> temp = new ArrayList<>();
-	    for(IdentifiedAnnotation entity : mentions){
-	    	LOGGER.info("Entity: " + entity.getCoveredText());
-	    	temp.add(entity.getCoveredText());
+	    for(TimeMention mention : mentions){
+	    	LOGGER.info("Event: " + mention.getCoveredText());
+	    	temp.add(mention.getCoveredText());
 	    }
 	    assertEquals(2, temp.size());	    
 	    assertTrue(temp.contains("recently"));

Modified: ctakes/trunk/ctakes-temporal/src/test/java/org/apach/ctakes/temporal/ae/ContextualModalityAnnotatorTest.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-temporal/src/test/java/org/apach/ctakes/temporal/ae/ContextualModalityAnnotatorTest.java?rev=1605432&r1=1605431&r2=1605432&view=diff
==============================================================================
--- ctakes/trunk/ctakes-temporal/src/test/java/org/apach/ctakes/temporal/ae/ContextualModalityAnnotatorTest.java
(original)
+++ ctakes/trunk/ctakes-temporal/src/test/java/org/apach/ctakes/temporal/ae/ContextualModalityAnnotatorTest.java
Wed Jun 25 14:55:32 2014
@@ -1,14 +1,121 @@
+/**
+ * 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.apach.ctakes.temporal.ae;
 
 import static org.junit.Assert.*;
 
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.apache.ctakes.clinicalpipeline.ClinicalPipelineFactory;
+import org.apache.ctakes.clinicalpipeline.ClinicalPipelineFactory.CopyNPChunksToLookupWindowAnnotations;
+import org.apache.ctakes.clinicalpipeline.ClinicalPipelineFactory.RemoveEnclosedLookupWindows;
+import org.apache.ctakes.dependency.parser.ae.ClearNLPDependencyParserAE;
+import org.apache.ctakes.temporal.ae.BackwardsTimeAnnotator;
+import org.apache.ctakes.temporal.ae.EventAnnotator;
+import org.apache.ctakes.typesystem.type.textsem.EventMention;
+import org.apache.ctakes.typesystem.type.textsem.IdentifiedAnnotation;
+import org.apache.ctakes.typesystem.type.textsem.TimeMention;
+import org.apache.log4j.Logger;
+import org.apache.uima.UIMAException;
+import org.apache.uima.jcas.JCas;
+import org.cleartk.classifier.CleartkAnnotator;
+import org.cleartk.classifier.jar.GenericJarClassifierFactory;
 import org.junit.Test;
+import org.uimafit.factory.AggregateBuilder;
+import org.uimafit.factory.AnalysisEngineFactory;
+import org.uimafit.factory.JCasFactory;
+import org.uimafit.pipeline.SimplePipeline;
+import org.uimafit.util.JCasUtil;
 
 public class ContextualModalityAnnotatorTest {
 
+	// LOG4J logger based on class name
+	private Logger LOGGER = Logger.getLogger(getClass().getName());
+	
 	@Test
-	public void test() {
-		fail("Not yet implemented");
-	}
+	public void testPipeline() throws UIMAException, IOException {
+		
+		/** Not ready for prime time yet
+		 * Annotator Caused by: java.lang.IllegalArgumentException: Unrecognized BIO outcome: ACTUAL
+
+		String note = "The patient is a 55-year-old man referred by Dr. Good for recently diagnosed
colorectal cancer.  "
+				+ "The patient was well till 6 months ago, when he started having a little blood with
stool.";
+		JCas jcas = JCasFactory.createJCas();
+		jcas.setDocumentText(note);
+
+		// Get the default pipeline with umls dictionary lookup
+		AggregateBuilder builder = new AggregateBuilder();
+		builder.add(ClinicalPipelineFactory.getTokenProcessingPipeline());
+		builder.add(AnalysisEngineFactory
+				.createPrimitiveDescription(CopyNPChunksToLookupWindowAnnotations.class));
+		builder.add(AnalysisEngineFactory
+				.createPrimitiveDescription(RemoveEnclosedLookupWindows.class));
+		// Commented out the Dictionary lookup for the test
+		// Uncomment and set -Dctakes.umlsuser and -Dctakes.umlspw env params if
+		// needed
+		// builder.add(UmlsDictionaryLookupAnnotator.createAnnotatorDescription());
+		builder.add(ClearNLPDependencyParserAE.createAnnotatorDescription());
+
+		// Add BackwardsTimeAnnotator
+		builder.add(AnalysisEngineFactory.createPrimitiveDescription(
+				BackwardsTimeAnnotator.class,
+				CleartkAnnotator.PARAM_IS_TRAINING, false,
+				GenericJarClassifierFactory.PARAM_CLASSIFIER_JAR_PATH,
+				"/org/apache/ctakes/temporal/ae/timeannotator/model.jar"));
+		// Add EventAnnotator
+		builder.add(AnalysisEngineFactory.createPrimitiveDescription(
+				EventAnnotator.class, CleartkAnnotator.PARAM_IS_TRAINING,
+				false, GenericJarClassifierFactory.PARAM_CLASSIFIER_JAR_PATH,
+				"/org/apache/ctakes/temporal/ae/eventannotator/model.jar"));
+		// Add Document Time Relative Annotator
+		builder.add(AnalysisEngineFactory.createPrimitiveDescription(
+				BackwardsTimeAnnotator.class,
+				CleartkAnnotator.PARAM_IS_TRAINING, false,
+				GenericJarClassifierFactory.PARAM_CLASSIFIER_JAR_PATH,
+				"/org/apache/ctakes/temporal/ae/contextualmodality/model.jar"));
 
+		SimplePipeline.runPipeline(jcas, builder.createAggregateDescription());
+
+		Collection<EventMention> mentions = JCasUtil.select(jcas,
+				EventMention.class);
+
+		ArrayList<String> temp = new ArrayList<>();
+		for (EventMention entity : mentions) {
+			String property = null;
+			if (entity.getEvent() != null
+					&& entity.getEvent().getProperties() != null
+					&& entity.getEvent().getProperties().getContextualModality() != null) {
+
+				property = entity.getEvent().getProperties().getContextualModality();
+				temp.add(entity.getCoveredText());
+			}
+			LOGGER.info("Entity: " + entity.getCoveredText() + "ContextualModality:"
+					+ property);
+		}
+		// assertEquals(2, temp.size());
+		// assertTrue(temp.contains("recently"));
+		// assertTrue(temp.contains("6 months ago"));
+		 
+		 
+	*/
+	}
+		
 }

Modified: ctakes/trunk/ctakes-temporal/src/test/java/org/apach/ctakes/temporal/ae/DocTimeRelAnnotatorTest.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-temporal/src/test/java/org/apach/ctakes/temporal/ae/DocTimeRelAnnotatorTest.java?rev=1605432&r1=1605431&r2=1605432&view=diff
==============================================================================
--- ctakes/trunk/ctakes-temporal/src/test/java/org/apach/ctakes/temporal/ae/DocTimeRelAnnotatorTest.java
(original)
+++ ctakes/trunk/ctakes-temporal/src/test/java/org/apach/ctakes/temporal/ae/DocTimeRelAnnotatorTest.java
Wed Jun 25 14:55:32 2014
@@ -1,14 +1,115 @@
+/**
+ * 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.apach.ctakes.temporal.ae;
 
 import static org.junit.Assert.*;
 
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.apache.ctakes.clinicalpipeline.ClinicalPipelineFactory;
+import org.apache.ctakes.clinicalpipeline.ClinicalPipelineFactory.CopyNPChunksToLookupWindowAnnotations;
+import org.apache.ctakes.clinicalpipeline.ClinicalPipelineFactory.RemoveEnclosedLookupWindows;
+import org.apache.ctakes.dependency.parser.ae.ClearNLPDependencyParserAE;
+import org.apache.ctakes.temporal.ae.BackwardsTimeAnnotator;
+import org.apache.ctakes.temporal.ae.EventAnnotator;
+import org.apache.ctakes.typesystem.type.textsem.EventMention;
+import org.apache.ctakes.typesystem.type.textsem.IdentifiedAnnotation;
+import org.apache.ctakes.typesystem.type.textsem.TimeMention;
+import org.apache.log4j.Logger;
+import org.apache.uima.UIMAException;
+import org.apache.uima.jcas.JCas;
+import org.cleartk.classifier.CleartkAnnotator;
+import org.cleartk.classifier.jar.GenericJarClassifierFactory;
 import org.junit.Test;
+import org.uimafit.factory.AggregateBuilder;
+import org.uimafit.factory.AnalysisEngineFactory;
+import org.uimafit.factory.JCasFactory;
+import org.uimafit.pipeline.SimplePipeline;
+import org.uimafit.util.JCasUtil;
 
 public class DocTimeRelAnnotatorTest {
 
+	// LOG4J logger based on class name
+	private Logger LOGGER = Logger.getLogger(getClass().getName());
+
 	@Test
-	public void test() {
-		fail("Not yet implemented");
+	public void testPipeline() throws UIMAException, IOException {
+
+		String note = "The patient is a 55-year-old man referred by Dr. Good for recently diagnosed
colorectal cancer.  "
+				+ "The patient was well till 6 months ago, when he started having a little blood with
stool.";
+		JCas jcas = JCasFactory.createJCas();
+		jcas.setDocumentText(note);
+
+		// Get the default pipeline with umls dictionary lookup
+		AggregateBuilder builder = new AggregateBuilder();
+		builder.add(ClinicalPipelineFactory.getTokenProcessingPipeline());
+		builder.add(AnalysisEngineFactory
+				.createPrimitiveDescription(CopyNPChunksToLookupWindowAnnotations.class));
+		builder.add(AnalysisEngineFactory
+				.createPrimitiveDescription(RemoveEnclosedLookupWindows.class));
+		// Commented out the Dictionary lookup for the test
+		// Uncomment and set -Dctakes.umlsuser and -Dctakes.umlspw env params if
+		// needed
+		// builder.add(UmlsDictionaryLookupAnnotator.createAnnotatorDescription());
+		builder.add(ClearNLPDependencyParserAE.createAnnotatorDescription());
+
+		// Add BackwardsTimeAnnotator
+		builder.add(AnalysisEngineFactory.createPrimitiveDescription(
+				BackwardsTimeAnnotator.class,
+				CleartkAnnotator.PARAM_IS_TRAINING, false,
+				GenericJarClassifierFactory.PARAM_CLASSIFIER_JAR_PATH,
+				"/org/apache/ctakes/temporal/ae/timeannotator/model.jar"));
+		// Add EventAnnotator
+		builder.add(AnalysisEngineFactory.createPrimitiveDescription(
+				EventAnnotator.class, CleartkAnnotator.PARAM_IS_TRAINING,
+				false, GenericJarClassifierFactory.PARAM_CLASSIFIER_JAR_PATH,
+				"/org/apache/ctakes/temporal/ae/eventannotator/model.jar"));
+		// Add Document Time Relative Annotator
+		builder.add(AnalysisEngineFactory.createPrimitiveDescription(
+				BackwardsTimeAnnotator.class,
+				CleartkAnnotator.PARAM_IS_TRAINING, false,
+				GenericJarClassifierFactory.PARAM_CLASSIFIER_JAR_PATH,
+				"/org/apache/ctakes/temporal/ae/doctimerel/model.jar"));
+
+		SimplePipeline.runPipeline(jcas, builder.createAggregateDescription());
+
+		Collection<EventMention> mentions = JCasUtil.select(jcas,
+				EventMention.class);
+
+		ArrayList<String> temp = new ArrayList<>();
+		for (EventMention mention : mentions) {
+			String property = null;
+			if (mention.getEvent() != null
+					&& mention.getEvent().getProperties() != null
+					&& mention.getEvent().getProperties().getDocTimeRel() != null) {
+
+				property = mention.getEvent().getProperties().getDocTimeRel();
+				temp.add(mention.getCoveredText());
+			}
+			LOGGER.info("Event: " + mention.getCoveredText() + " DocTimeRel:"
+					+ property);
+		}
+		// assertEquals(2, temp.size());
+		// assertTrue(temp.contains("recently"));
+		// assertTrue(temp.contains("6 months ago"));
 	}
 
 }

Modified: ctakes/trunk/ctakes-temporal/src/test/java/org/apach/ctakes/temporal/ae/EventAnnotatorTest.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-temporal/src/test/java/org/apach/ctakes/temporal/ae/EventAnnotatorTest.java?rev=1605432&r1=1605431&r2=1605432&view=diff
==============================================================================
--- ctakes/trunk/ctakes-temporal/src/test/java/org/apach/ctakes/temporal/ae/EventAnnotatorTest.java
(original)
+++ ctakes/trunk/ctakes-temporal/src/test/java/org/apach/ctakes/temporal/ae/EventAnnotatorTest.java
Wed Jun 25 14:55:32 2014
@@ -1,3 +1,21 @@
+/**
+ * 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.apach.ctakes.temporal.ae;
 
 import static org.junit.Assert.*;
@@ -41,12 +59,14 @@ public class EventAnnotatorTest {
 		JCas jcas = JCasFactory.createJCas();
 		jcas.setDocumentText(note);
   
-		//Get the default pipeline with umls dictionary lookup
+		//Get the default pipeline
 	    AggregateBuilder builder = new AggregateBuilder();
 	    builder.add(ClinicalPipelineFactory.getTokenProcessingPipeline());
 	    builder.add(AnalysisEngineFactory.createPrimitiveDescription(CopyNPChunksToLookupWindowAnnotations.class));
 	    builder.add(AnalysisEngineFactory.createPrimitiveDescription(RemoveEnclosedLookupWindows.class));
-	    builder.add(UmlsDictionaryLookupAnnotator.createAnnotatorDescription());
+	    //Commented out the Dictionary lookup for the test
+	    //Uncomment and set -Dctakes.umlsuser and -Dctakes.umlspw env params if needed
+	    //builder.add(UmlsDictionaryLookupAnnotator.createAnnotatorDescription());
 	    builder.add(ClearNLPDependencyParserAE.createAnnotatorDescription());
 		
 		//Add EventAnnotator
@@ -62,11 +82,11 @@ public class EventAnnotatorTest {
 	    Collection<EventMention> mentions = JCasUtil.select(jcas, EventMention.class);
 
 	    ArrayList<String> temp = new ArrayList<>();
-	    for(IdentifiedAnnotation entity : mentions){
-	    	LOGGER.info("Entity: " + entity.getCoveredText());
-	    	temp.add(entity.getCoveredText());
+	    for(EventMention mention : mentions){
+	    	LOGGER.info("Event: " + mention.getCoveredText() + " Confidence:" + mention.getConfidence());
+	    	temp.add(mention.getCoveredText());
 	    }
-	   	assertEquals(7, temp.size());	    
+	   	assertEquals(6, temp.size());	    
 	    assertTrue(temp.contains("old"));
 	    assertTrue(temp.contains("referred"));	    
 	    assertTrue(temp.contains("cancer"));



Mime
View raw message