You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ctakes.apache.org by st...@apache.org on 2012/10/23 22:12:59 UTC

svn commit: r1401430 - /incubator/ctakes/trunk/ctakes-relation-extractor/src/test/java/org/apache/ctakes/relationextractor/ae/RelationExtractorAnnotatorsTest.java

Author: stevenbethard
Date: Tue Oct 23 20:12:59 2012
New Revision: 1401430

URL: http://svn.apache.org/viewvc?rev=1401430&view=rev
Log:
Fix for CTAKES-88 Add test for trained relation extraction modules

Added:
    incubator/ctakes/trunk/ctakes-relation-extractor/src/test/java/org/apache/ctakes/relationextractor/ae/RelationExtractorAnnotatorsTest.java   (with props)

Added: incubator/ctakes/trunk/ctakes-relation-extractor/src/test/java/org/apache/ctakes/relationextractor/ae/RelationExtractorAnnotatorsTest.java
URL: http://svn.apache.org/viewvc/incubator/ctakes/trunk/ctakes-relation-extractor/src/test/java/org/apache/ctakes/relationextractor/ae/RelationExtractorAnnotatorsTest.java?rev=1401430&view=auto
==============================================================================
--- incubator/ctakes/trunk/ctakes-relation-extractor/src/test/java/org/apache/ctakes/relationextractor/ae/RelationExtractorAnnotatorsTest.java (added)
+++ incubator/ctakes/trunk/ctakes-relation-extractor/src/test/java/org/apache/ctakes/relationextractor/ae/RelationExtractorAnnotatorsTest.java Tue Oct 23 20:12:59 2012
@@ -0,0 +1,93 @@
+package org.apache.ctakes.relationextractor.ae;
+
+import static org.junit.Assert.*;
+
+import java.io.File;
+import java.util.Collection;
+import java.util.Iterator;
+
+import org.apache.ctakes.typesystem.type.constants.CONST;
+import org.apache.ctakes.typesystem.type.relation.BinaryTextRelation;
+import org.apache.ctakes.typesystem.type.syntax.BaseToken;
+import org.apache.ctakes.typesystem.type.textsem.EntityMention;
+import org.apache.ctakes.typesystem.type.textsem.Modifier;
+import org.apache.ctakes.typesystem.type.textspan.Sentence;
+import org.apache.uima.UIMAFramework;
+import org.apache.uima.analysis_engine.AnalysisEngine;
+import org.apache.uima.analysis_engine.AnalysisEngineDescription;
+import org.apache.uima.jcas.JCas;
+import org.apache.uima.util.XMLInputSource;
+import org.apache.uima.util.XMLParser;
+import org.junit.Test;
+import org.uimafit.component.JCasAnnotator_ImplBase;
+import org.uimafit.factory.AggregateBuilder;
+import org.uimafit.testing.factory.TokenBuilder;
+import org.uimafit.util.JCasUtil;
+
+public class RelationExtractorAnnotatorsTest {
+
+  @Test
+  public void test() throws Exception {
+    // create the pipeline
+    AggregateBuilder builder = new AggregateBuilder();
+    builder.add(this.findDescription(ModifierExtractorAnnotator.class));
+    builder.add(this.findDescription(DegreeOfRelationExtractorAnnotator.class));
+    builder.add(this.findDescription(EntityMentionPairRelationExtractorAnnotator.class));
+    AnalysisEngine engine = builder.createAggregate();
+    JCas jCas = engine.newJCas();
+
+    // populate the CAS with an example sentence
+    // TODO: add annotations to support phrase chunk and dependency features
+    TokenBuilder<BaseToken, Sentence> tokenBuilder = new TokenBuilder<BaseToken, Sentence>(
+        BaseToken.class,
+        Sentence.class,
+        "partOfSpeech",
+        null);
+    tokenBuilder.buildTokens(
+        jCas,
+        "He had a slight fracture in the proximal right fibula.",
+        "He had a slight fracture in the proximal right fibula .",
+        "PRP VBD DT JJ NN IN DT JJ JJ NN .");
+    EntityMention fracture = new EntityMention(jCas, 16, 24);
+    fracture.setTypeID(CONST.NE_TYPE_ID_DISORDER);
+    fracture.addToIndexes();
+    assertEquals("fracture", fracture.getCoveredText());
+    EntityMention fibula = new EntityMention(jCas, 32, 53);
+    fibula.setTypeID(CONST.NE_TYPE_ID_ANATOMICAL_SITE);
+    fibula.addToIndexes();
+    assertEquals("proximal right fibula", fibula.getCoveredText());
+
+    // run the analysis engine
+    engine.process(jCas);
+
+    // test the modifier annotator
+    Collection<Modifier> modifiers = JCasUtil.select(jCas, Modifier.class);
+    assertEquals(1, modifiers.size());
+    Modifier slight = modifiers.iterator().next();
+    assertEquals("slight", slight.getCoveredText());
+
+    // test the relation annotators
+    Collection<BinaryTextRelation> relations = JCasUtil.select(jCas, BinaryTextRelation.class);
+    assertEquals(2, relations.size());
+    Iterator<BinaryTextRelation> iterator = relations.iterator();
+    BinaryTextRelation slightFracture = iterator.next();
+    assertEquals("degree_of", slightFracture.getCategory());
+    assertEquals(fracture, slightFracture.getArg1().getArgument());
+    assertEquals(slight, slightFracture.getArg2().getArgument());
+    BinaryTextRelation fractureFibula = iterator.next();
+    assertEquals("location_of", fractureFibula.getCategory());
+    // TODO: this seems backwards, but maybe that's how it's supposed to be?
+    assertEquals(fibula, fractureFibula.getArg1().getArgument());
+    assertEquals(fracture, fractureFibula.getArg2().getArgument());
+  }
+
+  private AnalysisEngineDescription findDescription(Class<? extends JCasAnnotator_ImplBase> cls)
+      throws Exception {
+    File directory = new File("desc/analysis_engine");
+    File file = new File(directory, cls.getSimpleName() + ".xml");
+    XMLParser parser = UIMAFramework.getXMLParser();
+    XMLInputSource source = new XMLInputSource(file);
+    return parser.parseAnalysisEngineDescription(source);
+  }
+
+}

Propchange: incubator/ctakes/trunk/ctakes-relation-extractor/src/test/java/org/apache/ctakes/relationextractor/ae/RelationExtractorAnnotatorsTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/ctakes/trunk/ctakes-relation-extractor/src/test/java/org/apache/ctakes/relationextractor/ae/RelationExtractorAnnotatorsTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain