ctakes-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From stevenbeth...@apache.org
Subject svn commit: r1503541 - in /ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal: ae/ eval/
Date Tue, 16 Jul 2013 01:31:07 GMT
Author: stevenbethard
Date: Tue Jul 16 01:31:07 2013
New Revision: 1503541

URL: http://svn.apache.org/r1503541
Log:
Adds reader for Anafora XML and updates ctakes-temporal evaluation scripts to add an option
for that

Added:
    ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/THYMEAnaforaXMLReader.java
Modified:
    ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfAnnotationSpans_ImplBase.java
    ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfClearTKEventSpans.java
    ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfClearTKTimeSpans.java
    ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfEventEventRelations.java
    ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfEventProperties.java
    ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfEventSpans.java
    ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfEventTimeRelations.java
    ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfNEPredicateEventSpans.java
    ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfTemporalRelations_ImplBase.java
    ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfTimeSpans.java
    ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/Evaluation_ImplBase.java

Added: ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/THYMEAnaforaXMLReader.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/THYMEAnaforaXMLReader.java?rev=1503541&view=auto
==============================================================================
--- ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/THYMEAnaforaXMLReader.java
(added)
+++ ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/THYMEAnaforaXMLReader.java
Tue Jul 16 01:31:07 2013
@@ -0,0 +1,338 @@
+package org.apache.ctakes.temporal.ae;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.ctakes.typesystem.type.constants.CONST;
+import org.apache.ctakes.typesystem.type.refsem.Event;
+import org.apache.ctakes.typesystem.type.refsem.EventProperties;
+import org.apache.ctakes.typesystem.type.relation.AspectualTextRelation;
+import org.apache.ctakes.typesystem.type.relation.BinaryTextRelation;
+import org.apache.ctakes.typesystem.type.relation.RelationArgument;
+import org.apache.ctakes.typesystem.type.relation.TemporalTextRelation;
+import org.apache.ctakes.typesystem.type.textsem.EventMention;
+import org.apache.ctakes.typesystem.type.textsem.TimeMention;
+import org.apache.log4j.Logger;
+import org.apache.uima.analysis_engine.AnalysisEngine;
+import org.apache.uima.analysis_engine.AnalysisEngineDescription;
+import org.apache.uima.analysis_engine.AnalysisEngineProcessException;
+import org.apache.uima.collection.CollectionReader;
+import org.apache.uima.jcas.JCas;
+import org.apache.uima.jcas.cas.FSArray;
+import org.apache.uima.jcas.tcas.Annotation;
+import org.apache.uima.resource.ResourceInitializationException;
+import org.cleartk.util.ViewURIUtil;
+import org.cleartk.util.cr.UriCollectionReader;
+import org.jdom2.Element;
+import org.jdom2.JDOMException;
+import org.jdom2.input.SAXBuilder;
+import org.uimafit.component.JCasAnnotator_ImplBase;
+import org.uimafit.descriptor.ConfigurationParameter;
+import org.uimafit.factory.AnalysisEngineFactory;
+import org.uimafit.pipeline.SimplePipeline;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+
+public class THYMEAnaforaXMLReader extends JCasAnnotator_ImplBase {
+  private static Logger LOGGER = Logger.getLogger(THYMEAnaforaXMLReader.class);
+
+  public static final String PARAM_ANAFORA_DIRECTORY = "anaforaDirectory";
+
+  @ConfigurationParameter(
+      name = PARAM_ANAFORA_DIRECTORY,
+      description = "root directory of the Anafora-annotated files, with one subdirectory
for "
+          + "each annotated file")
+  private File anaforaDirectory;
+
+  public static final String PARAM_ANAFORA_XML_SUFFIXES = "anaforaSuffixes";
+
+  @ConfigurationParameter(
+      name = PARAM_ANAFORA_XML_SUFFIXES,
+      description = "list of suffixes that might be added to a file name to identify the
Anafora "
+          + "XML annotations file; only the first suffix corresponding to a file will be
used")
+  private String[] anaforaXMLSuffixes = new String[] {
+      ".temporal.Temporal-Adjudication.gold.completed.xml",
+      ".temporal.Temporal-Entities.gold.completed.xml", };
+
+  public static AnalysisEngineDescription getDescription() throws ResourceInitializationException
{
+    return AnalysisEngineFactory.createPrimitiveDescription(THYMEAnaforaXMLReader.class);
+  }
+
+  public static AnalysisEngineDescription getDescription(File anaforaDirectory)
+      throws ResourceInitializationException {
+    return AnalysisEngineFactory.createPrimitiveDescription(
+        THYMEAnaforaXMLReader.class,
+        THYMEAnaforaXMLReader.PARAM_ANAFORA_DIRECTORY,
+        anaforaDirectory);
+  }
+
+  @Override
+  public void process(JCas jCas) throws AnalysisEngineProcessException {
+    // determine source text file
+    File textFile = new File(ViewURIUtil.getURI(jCas));
+    LOGGER.info("processing " + textFile);
+
+    // determine possible Anafora XML file names
+    List<File> possibleXMLFiles = Lists.newArrayList();
+    for (String anaforaXMLSuffix : this.anaforaXMLSuffixes) {
+      if (this.anaforaDirectory == null) {
+        possibleXMLFiles.add(new File(textFile + anaforaXMLSuffix));
+      } else {
+        File subDir = new File(this.anaforaDirectory, textFile.getName());
+        possibleXMLFiles.add(new File(subDir, textFile.getName() + anaforaXMLSuffix));
+      }
+    }
+
+    // find an Anafora XML file that actually exists
+    File xmlFile = null;
+    for (File possibleXMLFile : possibleXMLFiles) {
+      if (possibleXMLFile.exists()) {
+        xmlFile = possibleXMLFile;
+        break;
+      }
+    }
+    if (xmlFile == null) {
+      throw new IllegalArgumentException("no Anafora XML file found from " + possibleXMLFiles);
+    }
+
+    // load the XML
+    Element dataElem;
+    try {
+      dataElem = new SAXBuilder().build(xmlFile.toURI().toURL()).getRootElement();
+    } catch (MalformedURLException e) {
+      throw new AnalysisEngineProcessException(e);
+    } catch (JDOMException e) {
+      throw new AnalysisEngineProcessException(e);
+    } catch (IOException e) {
+      throw new AnalysisEngineProcessException(e);
+    }
+
+    for (Element annotationsElem : dataElem.getChildren("annotations")) {
+
+      Map<String, Annotation> idToAnnotation = Maps.newHashMap();
+      for (Element entityElem : annotationsElem.getChildren("entity")) {
+        String id = removeSingleChildText(entityElem, "id", null);
+        Element spanElem = removeSingleChild(entityElem, "span", id);
+        String type = removeSingleChildText(entityElem, "type", id);
+        Element propertiesElem = removeSingleChild(entityElem, "properties", id);
+
+        // UIMA doesn't support disjoint spans, so take the span enclosing
+        // everything
+        int begin = Integer.MAX_VALUE;
+        int end = Integer.MIN_VALUE;
+        for (String spanString : spanElem.getText().split(";")) {
+          String[] beginEndStrings = spanString.split(",");
+          if (beginEndStrings.length != 2) {
+            error("span not of the format 'number,number'", id);
+          }
+          int spanBegin = Integer.parseInt(beginEndStrings[0]);
+          int spanEnd = Integer.parseInt(beginEndStrings[1]);
+          if (spanBegin < begin) {
+            begin = spanBegin;
+          }
+          if (spanEnd > end) {
+            end = spanEnd;
+          }
+        }
+
+        Annotation annotation;
+        if (type.equals("EVENT")) {
+          String docTimeRel = removeSingleChildText(propertiesElem, "DocTimeRel", id);
+          if (docTimeRel == null) {
+            error("no docTimeRel, assuming OVERLAP", id);
+            docTimeRel = "OVERLAP";
+          }
+          String eventType = removeSingleChildText(propertiesElem, "Type", id);
+          String degree = removeSingleChildText(propertiesElem, "Degree", id);
+          String polarity = removeSingleChildText(propertiesElem, "Polarity", id);
+          String contextualModality = removeSingleChildText(propertiesElem, "ContextualModality",
id);
+          String contextualAspect = removeSingleChildText(propertiesElem, "ContextualAspect",
id);
+          String permanence = removeSingleChildText(propertiesElem, "Permanence", id);
+          EventMention eventMention = new EventMention(jCas, begin, end);
+          Event event = new Event(jCas);
+          EventProperties eventProperties = new EventProperties(jCas);
+          eventProperties.setDocTimeRel(docTimeRel);
+          eventProperties.setCategory(eventType);
+          eventProperties.setDegree(degree);
+          if (polarity.equals("POS")) {
+            eventProperties.setPolarity(CONST.NE_POLARITY_NEGATION_ABSENT);
+          } else if (polarity.equals("NEG")) {
+            eventProperties.setPolarity(CONST.NE_POLARITY_NEGATION_PRESENT);
+          } else {
+            error("polarity that was not POS or NEG", id);
+          }
+          eventProperties.setContextualModality(contextualModality);
+          eventProperties.setContextualAspect(contextualAspect);
+          eventProperties.setPermanence(permanence);
+          eventProperties.addToIndexes();
+          event.setConfidence(1.0f);
+          event.setDiscoveryTechnique(CONST.NE_DISCOVERY_TECH_GOLD_ANNOTATION);
+          event.setProperties(eventProperties);
+          event.setMentions(new FSArray(jCas, 1));
+          event.setMentions(0, eventMention);
+          event.addToIndexes();
+          eventMention.setConfidence(1.0f);
+          eventMention.setDiscoveryTechnique(CONST.NE_DISCOVERY_TECH_GOLD_ANNOTATION);
+          eventMention.setEvent(event);
+          eventMention.addToIndexes();
+          annotation = eventMention;
+
+        } else if (type.equals("TIMEX3")) {
+          String timeClass = removeSingleChildText(propertiesElem, "Class", id);
+          TimeMention timeMention = new TimeMention(jCas, begin, end);
+          timeMention.setTimeClass(timeClass);
+          timeMention.addToIndexes();
+          annotation = timeMention;
+
+        } else if (type.equals("DOCTIME")) {
+          TimeMention timeMention = new TimeMention(jCas, begin, end);
+          timeMention.setTimeClass(type);
+          timeMention.addToIndexes();
+          annotation = timeMention;
+
+        } else if (type.equals("SECTIONTIME")) {
+          TimeMention timeMention = new TimeMention(jCas, begin, end);
+          timeMention.setTimeClass(type);
+          timeMention.addToIndexes();
+          annotation = timeMention;
+
+        } else {
+          throw new UnsupportedOperationException("unsupported entity type: " + type);
+        }
+
+        // match the annotation to it's ID for later use
+        idToAnnotation.put(id, annotation);
+
+        // make sure all XML has been consumed
+        removeSingleChild(entityElem, "parentsType", id);
+        if (!propertiesElem.getChildren().isEmpty() || !entityElem.getChildren().isEmpty())
{
+          List<String> children = Lists.newArrayList();
+          for (Element child : propertiesElem.getChildren()) {
+            children.add(child.getName());
+          }
+          for (Element child : entityElem.getChildren()) {
+            children.add(child.getName());
+          }
+          error("unprocessed children " + children, id);
+        }
+      }
+
+      for (Element relationElem : annotationsElem.getChildren("relation")) {
+        String id = removeSingleChildText(relationElem, "id", null);
+        String type = removeSingleChildText(relationElem, "type", id);
+        Element propertiesElem = removeSingleChild(relationElem, "properties", id);
+
+        if (type.equals("TLINK")) {
+          String sourceID = removeSingleChildText(propertiesElem, "Source", id);
+          String targetID = removeSingleChildText(propertiesElem, "Target", id);
+          String tlinkType = removeSingleChildText(propertiesElem, "Type", id);
+          TemporalTextRelation relation = new TemporalTextRelation(jCas);
+          addRelation(jCas, relation, sourceID, targetID, tlinkType, idToAnnotation, id);
+
+        } else if (type.equals("ALINK")) {
+          String sourceID = removeSingleChildText(propertiesElem, "Source", id);
+          String targetID = removeSingleChildText(propertiesElem, "Target", id);
+          String alinkType = removeSingleChildText(propertiesElem, "Type", id);
+          AspectualTextRelation relation = new AspectualTextRelation(jCas);
+          addRelation(jCas, relation, sourceID, targetID, alinkType, idToAnnotation, id);
+
+        } else {
+          throw new UnsupportedOperationException("unsupported relation type: " + type);
+        }
+
+        // make sure all XML has been consumed
+        removeSingleChild(relationElem, "parentsType", id);
+        if (!propertiesElem.getChildren().isEmpty() || !relationElem.getChildren().isEmpty())
{
+          List<String> children = Lists.newArrayList();
+          for (Element child : propertiesElem.getChildren()) {
+            children.add(child.getName());
+          }
+          for (Element child : relationElem.getChildren()) {
+            children.add(child.getName());
+          }
+          error("unprocessed children " + children, id);
+        }
+      }
+    }
+  }
+
+  private static Element getSingleChild(Element elem, String elemName, String causeID) {
+    List<Element> children = elem.getChildren(elemName);
+    if (children.size() != 1) {
+      error(String.format("not exactly one '%s' child", elemName), causeID);
+    }
+    return children.size() > 0 ? children.get(0) : null;
+  }
+
+  private static Element removeSingleChild(Element elem, String elemName, String causeID)
{
+    Element child = getSingleChild(elem, elemName, causeID);
+    elem.removeChildren(elemName);
+    return child;
+  }
+
+  private static String removeSingleChildText(Element elem, String elemName, String causeID)
{
+    Element child = getSingleChild(elem, elemName, causeID);
+    String text = child.getText();
+    if (text.isEmpty()) {
+      error(String.format("an empty '%s' child", elemName), causeID);
+      text = null;
+    }
+    elem.removeChildren(elemName);
+    return text;
+  }
+
+  private static void addRelation(
+      JCas jCas,
+      BinaryTextRelation relation,
+      String sourceID,
+      String targetID,
+      String category,
+      Map<String, Annotation> idToAnnotation,
+      String causeID) {
+    if (sourceID != null && targetID != null) {
+      Annotation source = getArgument(sourceID, idToAnnotation, causeID);
+      Annotation target = getArgument(targetID, idToAnnotation, causeID);
+      if (source != null && target != null) {
+        RelationArgument sourceArg = new RelationArgument(jCas);
+        sourceArg.setArgument(source);
+        sourceArg.addToIndexes();
+        RelationArgument targetArg = new RelationArgument(jCas);
+        targetArg.setArgument(target);
+        targetArg.addToIndexes();
+        relation.setCategory(category);
+        relation.setArg1(sourceArg);
+        relation.setArg2(targetArg);
+        relation.addToIndexes();
+      }
+    }
+  }
+
+  private static Annotation getArgument(
+      String id,
+      Map<String, Annotation> idToAnnotation,
+      String causeID) {
+    Annotation annotation = idToAnnotation.get(id);
+    if (annotation == null) {
+      error("no annotation with id " + id, causeID);
+    }
+    return annotation;
+  }
+
+  private static void error(String found, String id) {
+    LOGGER.error(String.format("found %s in annotation with ID %s", found, id));
+  }
+
+  public static void main(String[] args) throws Exception {
+    List<File> files = Lists.newArrayList();
+    for (String path : args) {
+      files.add(new File(path));
+    }
+    CollectionReader reader = UriCollectionReader.getCollectionReaderFromFiles(files);
+    AnalysisEngine engine = AnalysisEngineFactory.createPrimitive(THYMEAnaforaXMLReader.class);
+    SimplePipeline.runPipeline(reader, engine);
+  }
+}

Modified: ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfAnnotationSpans_ImplBase.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfAnnotationSpans_ImplBase.java?rev=1503541&r1=1503540&r2=1503541&view=diff
==============================================================================
--- ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfAnnotationSpans_ImplBase.java
(original)
+++ ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfAnnotationSpans_ImplBase.java
Tue Jul 16 01:31:07 2013
@@ -73,21 +73,23 @@ public abstract class EvaluationOfAnnota
   public EvaluationOfAnnotationSpans_ImplBase(
       File baseDirectory,
       File rawTextDirectory,
-      File knowtatorXMLDirectory,
+      File xmlDirectory,
+      XMLFormat xmlFormat,
       File xmiDirectory,
       File treebankDirectory,
       Class<? extends Annotation> annotationClass) {
-    super(baseDirectory, rawTextDirectory, knowtatorXMLDirectory, xmiDirectory, treebankDirectory);
+    super(baseDirectory, rawTextDirectory, xmlDirectory, xmlFormat, xmiDirectory, treebankDirectory);
     this.annotationClass = annotationClass;
   }
   
   public EvaluationOfAnnotationSpans_ImplBase(
 		File baseDirectory,
 		File rawTextDirectory, 
-		File knowtatorXMLDirectory, 
+		File xmlDirectory,
+		XMLFormat xmlFormat,
 		File xmiDirectory,
 		Class<? extends Annotation> annotationClass) {
-	  this(baseDirectory,rawTextDirectory, knowtatorXMLDirectory, xmiDirectory, null, annotationClass);
+	  this(baseDirectory,rawTextDirectory, xmlDirectory, xmlFormat, xmiDirectory, null, annotationClass);
   }
 
 protected abstract AnalysisEngineDescription getDataWriterDescription(File directory)

Modified: ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfClearTKEventSpans.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfClearTKEventSpans.java?rev=1503541&r1=1503540&r2=1503541&view=diff
==============================================================================
--- ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfClearTKEventSpans.java
(original)
+++ ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfClearTKEventSpans.java
Tue Jul 16 01:31:07 2013
@@ -54,7 +54,8 @@ public class EvaluationOfClearTKEventSpa
     EvaluationOfClearTKEventSpans evaluation = new EvaluationOfClearTKEventSpans(
         new File("target/eval/cleartk-event-spans"),
         options.getRawTextDirectory(),
-        options.getKnowtatorXMLDirectory(),
+        options.getXMLDirectory(),
+        options.getXMLFormat(),
         options.getXMIDirectory());
     evaluation.prepareXMIsFor(patientSets);
     evaluation.setLogging(Level.FINE, new File("target/eval/cleartk-event-errors.log"));
@@ -65,9 +66,10 @@ public class EvaluationOfClearTKEventSpa
   public EvaluationOfClearTKEventSpans(
       File baseDirectory,
       File rawTextDirectory,
-      File knowtatorXMLDirectory,
+      File xmlDirectory,
+      XMLFormat xmlFormat,
       File xmiDirectory) {
-    super(baseDirectory, rawTextDirectory, knowtatorXMLDirectory, xmiDirectory, EventMention.class);
+    super(baseDirectory, rawTextDirectory, xmlDirectory, xmlFormat, xmiDirectory, EventMention.class);
   }
 
   @Override

Modified: ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfClearTKTimeSpans.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfClearTKTimeSpans.java?rev=1503541&r1=1503540&r2=1503541&view=diff
==============================================================================
--- ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfClearTKTimeSpans.java
(original)
+++ ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfClearTKTimeSpans.java
Tue Jul 16 01:31:07 2013
@@ -23,6 +23,7 @@ import java.util.Collection;
 import java.util.List;
 import java.util.logging.Level;
 
+import org.apache.ctakes.typesystem.type.textsem.EventMention;
 import org.apache.ctakes.typesystem.type.textsem.TimeMention;
 import org.apache.ctakes.typesystem.type.textspan.Segment;
 import org.apache.uima.analysis_engine.AnalysisEngineDescription;
@@ -53,7 +54,8 @@ public class EvaluationOfClearTKTimeSpan
     EvaluationOfClearTKTimeSpans evaluation = new EvaluationOfClearTKTimeSpans(
         new File("target/eval/cleartk-time-spans"),
         options.getRawTextDirectory(),
-        options.getKnowtatorXMLDirectory(),
+        options.getXMLDirectory(),
+        options.getXMLFormat(),
         options.getXMIDirectory());
     evaluation.prepareXMIsFor(patientSets);
     evaluation.setLogging(Level.FINE, new File("target/eval/cleartk-time-errors.log"));
@@ -64,9 +66,10 @@ public class EvaluationOfClearTKTimeSpan
   public EvaluationOfClearTKTimeSpans(
       File baseDirectory,
       File rawTextDirectory,
-      File knowtatorXMLDirectory,
+      File xmlDirectory,
+      XMLFormat xmlFormat,
       File xmiDirectory) {
-    super(baseDirectory, rawTextDirectory, knowtatorXMLDirectory, xmiDirectory, TimeMention.class);
+    super(baseDirectory, rawTextDirectory, xmlDirectory, xmlFormat, xmiDirectory, EventMention.class);
   }
 
   @Override

Modified: ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfEventEventRelations.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfEventEventRelations.java?rev=1503541&r1=1503540&r2=1503541&view=diff
==============================================================================
--- ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfEventEventRelations.java
(original)
+++ ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfEventEventRelations.java
Tue Jul 16 01:31:07 2013
@@ -44,14 +44,15 @@ EvaluationOfTemporalRelations_ImplBase {
   public EvaluationOfEventEventRelations(      
       File baseDirectory,
       File rawTextDirectory,
-      File knowtatorXMLDirectory,
+      File xmlDirectory,
+      XMLFormat xmlFormat,
       File xmiDirectory,
       File treebankDirectory,
       boolean printErrors,
       boolean printRelations,
       boolean baseline,
       ParameterSettings params){
-    super(baseDirectory, rawTextDirectory, knowtatorXMLDirectory, xmiDirectory,
+    super(baseDirectory, rawTextDirectory, xmlDirectory, xmlFormat, xmiDirectory,
         treebankDirectory, printErrors, printRelations, params);
     this.baseline = baseline;
   }
@@ -188,7 +189,8 @@ EvaluationOfTemporalRelations_ImplBase {
     EvaluationOfEventEventRelations evaluation = new EvaluationOfEventEventRelations(
         workingDir,
         options.getRawTextDirectory(),
-        options.getKnowtatorXMLDirectory(),
+        options.getXMLDirectory(),
+        options.getXMLFormat(),
         options.getXMIDirectory(),
         options.getTreebankDirectory(),
         options.getPrintErrors(),

Modified: ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfEventProperties.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfEventProperties.java?rev=1503541&r1=1503540&r2=1503541&view=diff
==============================================================================
--- ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfEventProperties.java
(original)
+++ ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfEventProperties.java
Tue Jul 16 01:31:07 2013
@@ -70,7 +70,8 @@ public class EvaluationOfEventProperties
     EvaluationOfEventProperties evaluation = new EvaluationOfEventProperties(
         new File("target/eval/event-properties"),
         options.getRawTextDirectory(),
-        options.getKnowtatorXMLDirectory(),
+        options.getXMLDirectory(),
+        options.getXMLFormat(),
         options.getXMIDirectory());
     evaluation.prepareXMIsFor(patientSets);
     evaluation.logClassificationErrors(new File("target/eval"), "ctakes-event-property-errors");
@@ -88,9 +89,10 @@ public class EvaluationOfEventProperties
   public EvaluationOfEventProperties(
       File baseDirectory,
       File rawTextDirectory,
-      File knowtatorXMLDirectory,
+      File xmlDirectory,
+      XMLFormat xmlFormat,
       File xmiDirectory) {
-    super(baseDirectory, rawTextDirectory, knowtatorXMLDirectory, xmiDirectory, null);
+    super(baseDirectory, rawTextDirectory, xmlDirectory, xmlFormat, xmiDirectory, null);
     for (String name : PROPERTY_NAMES) {
       this.loggers.put(name, Logger.getLogger(String.format("%s.%s", this.getClass().getName(),
name)));
     }

Modified: ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfEventSpans.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfEventSpans.java?rev=1503541&r1=1503540&r2=1503541&view=diff
==============================================================================
--- ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfEventSpans.java
(original)
+++ ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfEventSpans.java
Tue Jul 16 01:31:07 2013
@@ -63,7 +63,8 @@ public class EvaluationOfEventSpans exte
     EvaluationOfEventSpans evaluation = new EvaluationOfEventSpans(
         new File("target/eval/event-spans"),
         options.getRawTextDirectory(),
-        options.getKnowtatorXMLDirectory(),
+        options.getXMLDirectory(),
+        options.getXMLFormat(),
         options.getXMIDirectory(),
         options.getProbabilityOfKeepingANegativeExample(),
         options.getFeatureSelectionThreshold(),
@@ -83,12 +84,13 @@ public class EvaluationOfEventSpans exte
   public EvaluationOfEventSpans(
       File baseDirectory,
       File rawTextDirectory,
-      File knowtatorXMLDirectory,
+      File xmlDirectory,
+      XMLFormat xmlFormat,
       File xmiDirectory,
       float probabilityOfKeepingANegativeExample,
       float featureSelectionThreshold,
       float numOfSmoteNeighbors) {
-    super(baseDirectory, rawTextDirectory, knowtatorXMLDirectory, xmiDirectory, EventMention.class);
+    super(baseDirectory, rawTextDirectory, xmlDirectory, xmlFormat, xmiDirectory, EventMention.class);
     this.probabilityOfKeepingANegativeExample = probabilityOfKeepingANegativeExample;
     this.featureSelectionThreshold = featureSelectionThreshold;
     this.smoteNeighborNumber = numOfSmoteNeighbors;

Modified: ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfEventTimeRelations.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfEventTimeRelations.java?rev=1503541&r1=1503540&r2=1503541&view=diff
==============================================================================
--- ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfEventTimeRelations.java
(original)
+++ ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfEventTimeRelations.java
Tue Jul 16 01:31:07 2013
@@ -33,7 +33,6 @@ import java.util.Set;
 import org.apache.ctakes.relationextractor.eval.RelationExtractorEvaluation.HashableArguments;
 import org.apache.ctakes.temporal.ae.EventTimeRelationAnnotator;
 import org.apache.ctakes.temporal.ae.baselines.RecallBaselineEventTimeRelationAnnotator;
-import org.apache.ctakes.temporal.eval.Evaluation_ImplBase.CopyFromGold;
 import org.apache.ctakes.typesystem.type.relation.BinaryTextRelation;
 import org.apache.ctakes.typesystem.type.relation.RelationArgument;
 import org.apache.ctakes.typesystem.type.textsem.EventMention;
@@ -129,7 +128,8 @@ public class EvaluationOfEventTimeRelati
       EvaluationOfEventTimeRelations evaluation = new EvaluationOfEventTimeRelations(
           tempModelDir,
           options.getRawTextDirectory(),
-          options.getKnowtatorXMLDirectory(),
+          options.getXMLDirectory(),
+          options.getXMLFormat(),
           options.getXMIDirectory(),
           options.getTreebankDirectory(),
           options.getClosure(),
@@ -165,7 +165,8 @@ public class EvaluationOfEventTimeRelati
   public EvaluationOfEventTimeRelations(
       File baseDirectory,
       File rawTextDirectory,
-      File knowtatorXMLDirectory,
+      File xmlDirectory,
+      XMLFormat xmlFormat,
       File xmiDirectory,
       File treebankDirectory,
       boolean useClosure,
@@ -177,7 +178,8 @@ public class EvaluationOfEventTimeRelati
     super(
         baseDirectory,
         rawTextDirectory,
-        knowtatorXMLDirectory,
+        xmlDirectory,
+        xmlFormat,
         xmiDirectory,
         treebankDirectory,
         printErrors,

Modified: ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfNEPredicateEventSpans.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfNEPredicateEventSpans.java?rev=1503541&r1=1503540&r2=1503541&view=diff
==============================================================================
--- ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfNEPredicateEventSpans.java
(original)
+++ ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfNEPredicateEventSpans.java
Tue Jul 16 01:31:07 2013
@@ -22,18 +22,18 @@ public class EvaluationOfNEPredicateEven
 		EvaluationOfAnnotationSpans_ImplBase {
 
 	public EvaluationOfNEPredicateEventSpans(File baseDirectory,
-			File rawTextDirectory, File knowtatorXMLDirectory,
+			File rawTextDirectory, File xmlDirectory, XMLFormat xmlFormat,
 			File xmiDirectory, File treebankDirectory,
 			Class<? extends Annotation> annotationClass) {
-		super(baseDirectory, rawTextDirectory, knowtatorXMLDirectory,
+		super(baseDirectory, rawTextDirectory, xmlDirectory, xmlFormat,
 				xmiDirectory, treebankDirectory, annotationClass);
 		// TODO Auto-generated constructor stub
 	}
 
 	public EvaluationOfNEPredicateEventSpans(File baseDirectory,
-			File rawTextDirectory, File knowtatorXMLDirectory,
+			File rawTextDirectory, File xmlDirectory, XMLFormat xmlFormat,
 			File xmiDirectory) {
-		super(baseDirectory, rawTextDirectory, knowtatorXMLDirectory,
+		super(baseDirectory, rawTextDirectory, xmlDirectory, xmlFormat,
 				xmiDirectory, EventMention.class);
 		// TODO Auto-generated constructor stub
 	}
@@ -80,7 +80,8 @@ public class EvaluationOfNEPredicateEven
 	    EvaluationOfNEPredicateEventSpans evaluation = new EvaluationOfNEPredicateEventSpans(
 	        new File("target/eval/event-spans"),
 	        options.getRawTextDirectory(),
-	        options.getKnowtatorXMLDirectory(),
+	        options.getXMLDirectory(),
+	        options.getXMLFormat(),
 	        options.getXMIDirectory());
 	    evaluation.prepareXMIsFor(patientSets);
 	    evaluation.setLogging(Level.FINE, new File("target/eval/ctakes-event-errors.log"));

Modified: ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfTemporalRelations_ImplBase.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfTemporalRelations_ImplBase.java?rev=1503541&r1=1503540&r2=1503541&view=diff
==============================================================================
--- ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfTemporalRelations_ImplBase.java
(original)
+++ ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfTemporalRelations_ImplBase.java
Tue Jul 16 01:31:07 2013
@@ -53,9 +53,9 @@ public abstract class EvaluationOfTempor
 	  protected boolean printRelations = false;
 
 	public EvaluationOfTemporalRelations_ImplBase(File baseDirectory,
-			File rawTextDirectory, File knowtatorXMLDirectory,
+			File rawTextDirectory, File xmlDirectory, XMLFormat xmlFormat,
 			File xmiDirectory, File treebankDirectory, boolean printErrors, boolean printRelations,
ParameterSettings params) {
-		super(baseDirectory, rawTextDirectory, knowtatorXMLDirectory, xmiDirectory,
+		super(baseDirectory, rawTextDirectory, xmlDirectory, xmlFormat, xmiDirectory,
 				treebankDirectory);
 		this.params = params;
 		this.printRelations = printRelations;

Modified: ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfTimeSpans.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfTimeSpans.java?rev=1503541&r1=1503540&r2=1503541&view=diff
==============================================================================
--- ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfTimeSpans.java
(original)
+++ ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfTimeSpans.java
Tue Jul 16 01:31:07 2013
@@ -82,7 +82,8 @@ public class EvaluationOfTimeSpans exten
       EvaluationOfTimeSpans evaluation = new EvaluationOfTimeSpans(
           new File("target/eval/time-spans"),
           options.getRawTextDirectory(),
-          options.getKnowtatorXMLDirectory(),
+          options.getXMLDirectory(),
+          options.getXMLFormat(),
           options.getXMIDirectory(),
           options.getTreebankDirectory(),
           annotatorClass,
@@ -119,13 +120,14 @@ public class EvaluationOfTimeSpans exten
   public EvaluationOfTimeSpans(
       File baseDirectory,
       File rawTextDirectory,
-      File knowtatorXMLDirectory,
+      File xmlDirectory,
+      XMLFormat xmlFormat,
       File xmiDirectory,
       File treebankDirectory,
       Class<? extends JCasAnnotator_ImplBase> annotatorClass,
       boolean printOverlapping,
       String[] trainingArguments) {
-    super(baseDirectory, rawTextDirectory, knowtatorXMLDirectory, xmiDirectory, treebankDirectory,
TimeMention.class);
+    super(baseDirectory, rawTextDirectory, xmlDirectory, xmlFormat, xmiDirectory, treebankDirectory,
TimeMention.class);
     this.annotatorClass = annotatorClass;
     this.trainingArguments = trainingArguments;
     this.printOverlapping = printOverlapping;

Modified: ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/Evaluation_ImplBase.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/Evaluation_ImplBase.java?rev=1503541&r1=1503540&r2=1503541&view=diff
==============================================================================
--- ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/Evaluation_ImplBase.java
(original)
+++ ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/Evaluation_ImplBase.java
Tue Jul 16 01:31:07 2013
@@ -47,6 +47,7 @@ import org.apache.ctakes.dictionary.look
 import org.apache.ctakes.lvg.ae.LvgAnnotator;
 import org.apache.ctakes.lvg.resource.LvgCmdApiResourceImpl;
 import org.apache.ctakes.postagger.POSTagger;
+import org.apache.ctakes.temporal.ae.THYMEAnaforaXMLReader;
 import org.apache.ctakes.temporal.ae.THYMEKnowtatorXMLReader;
 import org.apache.ctakes.temporal.ae.THYMETreebankReader;
 import org.apache.ctakes.typesystem.type.syntax.BaseToken;
@@ -99,6 +100,8 @@ public abstract class Evaluation_ImplBas
     org.cleartk.eval.Evaluation_ImplBase<Integer, STATISTICS_TYPE> {
 
   public static final String GOLD_VIEW_NAME = "GoldView";
+  
+  enum XMLFormat { Knowtator, Anafora }
 
   static interface Options {
 
@@ -106,7 +109,10 @@ public abstract class Evaluation_ImplBas
     public File getRawTextDirectory();
 
     @Option(longName = "xml")
-    public File getKnowtatorXMLDirectory();
+    public File getXMLDirectory();
+
+    @Option(longName = "format")
+    public XMLFormat getXMLFormat();
 
     @Option(longName = "xmi")
     public File getXMIDirectory();
@@ -132,7 +138,9 @@ public abstract class Evaluation_ImplBas
 
   protected File rawTextDirectory;
 
-  protected File knowtatorXMLDirectory;
+  protected File xmlDirectory;
+  
+  protected XMLFormat xmlFormat;
 
   protected File xmiDirectory;
 
@@ -149,12 +157,14 @@ public abstract class Evaluation_ImplBas
   public Evaluation_ImplBase(
       File baseDirectory,
       File rawTextDirectory,
-      File knowtatorXMLDirectory,
+      File xmlDirectory,
+      XMLFormat xmlFormat,
       File xmiDirectory,
       File treebankDirectory) {
     super(baseDirectory);
     this.rawTextDirectory = rawTextDirectory;
-    this.knowtatorXMLDirectory = knowtatorXMLDirectory;
+    this.xmlDirectory = xmlDirectory;
+    this.xmlFormat = xmlFormat;
     this.xmiDirectory = xmiDirectory;
     this.xmiExists = this.xmiDirectory.exists() && this.xmiDirectory.listFiles().length
> 0;
     this.treebankDirectory = treebankDirectory;
@@ -233,10 +243,20 @@ public abstract class Evaluation_ImplBas
         CAS.NAME_DEFAULT_SOFA,
         ViewTextCopierAnnotator.PARAM_DESTINATION_VIEW_NAME,
         GOLD_VIEW_NAME));
-    aggregateBuilder.add(
-        THYMEKnowtatorXMLReader.getDescription(this.knowtatorXMLDirectory),
-        CAS.NAME_DEFAULT_SOFA,
-        GOLD_VIEW_NAME);
+    switch (this.xmlFormat) {
+    case Anafora:
+      aggregateBuilder.add(
+          THYMEAnaforaXMLReader.getDescription(this.xmlDirectory),
+          CAS.NAME_DEFAULT_SOFA,
+          GOLD_VIEW_NAME);
+      break;
+    case Knowtator:
+      aggregateBuilder.add(
+          THYMEKnowtatorXMLReader.getDescription(this.xmlDirectory),
+          CAS.NAME_DEFAULT_SOFA,
+          GOLD_VIEW_NAME);
+      break;
+    }
 
     // identify segments
     aggregateBuilder.add(AnalysisEngineFactory.createPrimitiveDescription(SegmentsFromBracketedSectionTagsAnnotator.class));



Mime
View raw message