You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ctakes.apache.org by tm...@apache.org on 2014/07/16 16:52:12 UTC
svn commit: r1611035 -
/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfTemporalRelations_ImplBase.java
Author: tmill
Date: Wed Jul 16 14:52:11 2014
New Revision: 1611035
URL: http://svn.apache.org/r1611035
Log:
CTAKES-82: Added backwards compatible constructor to base temporal relations.class.
Modified:
ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/eval/EvaluationOfTemporalRelations_ImplBase.java
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=1611035&r1=1611034&r2=1611035&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 Wed Jul 16 14:52:11 2014
@@ -44,49 +44,59 @@ import com.google.common.collect.Sets;
import com.lexicalscope.jewel.cli.Option;
public abstract class EvaluationOfTemporalRelations_ImplBase extends
- Evaluation_ImplBase<AnnotationStatistics<String>> {
+Evaluation_ImplBase<AnnotationStatistics<String>> {
- static interface TempRelOptions extends Evaluation_ImplBase.Options{
- @Option
- public boolean getTest();
-
- @Option
- public boolean getPrintFormattedRelations();
-
- @Option
- public boolean getBaseline();
-
- @Option
- public boolean getClosure();
-
- @Option
- public boolean getClassificationOnly();
-
- }
-
- protected static boolean DEFAULT_BOTH_DIRECTIONS = false;
- protected static float DEFAULT_DOWNSAMPLE = 1.0f;
- protected static double DEFAULT_SVM_C = 1.0;
- protected static double DEFAULT_SVM_G = 1.0;
- protected static double DEFAULT_TK = 0.5;
- protected static double DEFAULT_LAMBDA = 0.5;
-
- protected static ParameterSettings defaultParams = new ParameterSettings(DEFAULT_BOTH_DIRECTIONS, DEFAULT_DOWNSAMPLE, "linear",
- DEFAULT_SVM_C, DEFAULT_SVM_G, "polynomial", ComboOperator.SUM, DEFAULT_TK, DEFAULT_LAMBDA);
-
-
- protected ParameterSettings params = null;
- protected boolean printRelations = false;
-
- public EvaluationOfTemporalRelations_ImplBase(File baseDirectory,
- File rawTextDirectory, File xmlDirectory, XMLFormat xmlFormat,
- File xmiDirectory, File treebankDirectory, File coreferenceDirectory, boolean printErrors, boolean printRelations, ParameterSettings params) {
- super(baseDirectory, rawTextDirectory, xmlDirectory, xmlFormat, xmiDirectory,
- treebankDirectory, coreferenceDirectory);
- this.params = params;
- this.printRelations = printRelations;
- this.printErrors = printErrors;
- }
+ static interface TempRelOptions extends Evaluation_ImplBase.Options{
+ @Option
+ public boolean getTest();
+
+ @Option
+ public boolean getPrintFormattedRelations();
+
+ @Option
+ public boolean getBaseline();
+
+ @Option
+ public boolean getClosure();
+
+ @Option
+ public boolean getClassificationOnly();
+
+ }
+
+ protected static boolean DEFAULT_BOTH_DIRECTIONS = false;
+ protected static float DEFAULT_DOWNSAMPLE = 1.0f;
+ protected static double DEFAULT_SVM_C = 1.0;
+ protected static double DEFAULT_SVM_G = 1.0;
+ protected static double DEFAULT_TK = 0.5;
+ protected static double DEFAULT_LAMBDA = 0.5;
+
+ protected static ParameterSettings defaultParams = new ParameterSettings(DEFAULT_BOTH_DIRECTIONS, DEFAULT_DOWNSAMPLE, "linear",
+ DEFAULT_SVM_C, DEFAULT_SVM_G, "polynomial", ComboOperator.SUM, DEFAULT_TK, DEFAULT_LAMBDA);
+
+
+ protected ParameterSettings params = null;
+ protected boolean printRelations = false;
+
+ public EvaluationOfTemporalRelations_ImplBase(File baseDirectory,
+ File rawTextDirectory, File xmlDirectory, XMLFormat xmlFormat,
+ File xmiDirectory, File treebankDirectory, File coreferenceDirectory, boolean printErrors, boolean printRelations, ParameterSettings params) {
+ super(baseDirectory, rawTextDirectory, xmlDirectory, xmlFormat, xmiDirectory,
+ treebankDirectory, coreferenceDirectory);
+ this.params = params;
+ this.printRelations = printRelations;
+ this.printErrors = printErrors;
+ }
+
+ public EvaluationOfTemporalRelations_ImplBase(File baseDirectory,
+ File rawTextDirectory, File xmlDirectory, XMLFormat xmlFormat,
+ File xmiDirectory, File treebankDirectory, boolean printErrors, boolean printRelations, ParameterSettings params) {
+ super(baseDirectory, rawTextDirectory, xmlDirectory, xmlFormat, xmiDirectory,
+ treebankDirectory);
+ this.params = params;
+ this.printRelations = printRelations;
+ this.printErrors = printErrors;
+ }
public static class PreserveEventEventRelations extends JCasAnnotator_ImplBase {
public static final String PARAM_GOLD_VIEW = "GoldView";
@@ -97,15 +107,15 @@ public abstract class EvaluationOfTempor
@Override
public void process(JCas jCas) throws AnalysisEngineProcessException {
for(BinaryTextRelation relation : Lists.newArrayList(JCasUtil.select(jCas, BinaryTextRelation.class))){
- RelationArgument arg1 = relation.getArg1();
- RelationArgument arg2 = relation.getArg2();
- if(arg1.getArgument() instanceof EventMention && arg2.getArgument() instanceof EventMention){
- // these are the kind we keep.
- continue;
- }
- arg1.removeFromIndexes();
- arg2.removeFromIndexes();
- relation.removeFromIndexes();
+ RelationArgument arg1 = relation.getArg1();
+ RelationArgument arg2 = relation.getArg2();
+ if(arg1.getArgument() instanceof EventMention && arg2.getArgument() instanceof EventMention){
+ // these are the kind we keep.
+ continue;
+ }
+ arg1.removeFromIndexes();
+ arg2.removeFromIndexes();
+ relation.removeFromIndexes();
}
}
}
@@ -115,46 +125,46 @@ public abstract class EvaluationOfTempor
@ConfigurationParameter(name = PARAM_RELATION_VIEW)
private String relationViewName = CAS.NAME_DEFAULT_SOFA;
- @Override
- public void process(JCas jCas) throws AnalysisEngineProcessException {
- JCas relationView = null;
-
- try {
- relationView = jCas.getView(relationViewName);
- } catch (CASException e) {
- e.printStackTrace();
- }
- for (BinaryTextRelation relation : Lists.newArrayList(JCasUtil.select(
- relationView,
- BinaryTextRelation.class))) {
- String relationType = relation.getCategory();
- if (relationType.startsWith("BEFORE")|| relationType.startsWith("BEGINS-ON")|| relationType.startsWith("ENDS-ON")) {
-// relation.getArg1().removeFromIndexes();
-// relation.getArg2().removeFromIndexes();
-// relation.removeFromIndexes();
- relation.setCategory("RARE");
- }else if(relationType.startsWith("CONTAINS")|| relationType.startsWith("OVERLAP")){
- relation.setCategory("COMMON");
- }
- }
- }
-
- public static class RemoveGoldAttributes extends JCasAnnotator_ImplBase {
@Override
public void process(JCas jCas) throws AnalysisEngineProcessException {
- for(EventMention event : JCasUtil.select(jCas, EventMention.class)){
- if(event.getEvent() != null && event.getEvent().getProperties() != null){
- event.getEvent().getProperties().setContextualAspect("UNK");
- event.getEvent().getProperties().setContextualModality("UNK");
+ JCas relationView = null;
+
+ try {
+ relationView = jCas.getView(relationViewName);
+ } catch (CASException e) {
+ e.printStackTrace();
+ }
+ for (BinaryTextRelation relation : Lists.newArrayList(JCasUtil.select(
+ relationView,
+ BinaryTextRelation.class))) {
+ String relationType = relation.getCategory();
+ if (relationType.startsWith("BEFORE")|| relationType.startsWith("BEGINS-ON")|| relationType.startsWith("ENDS-ON")) {
+ // relation.getArg1().removeFromIndexes();
+ // relation.getArg2().removeFromIndexes();
+ // relation.removeFromIndexes();
+ relation.setCategory("RARE");
+ }else if(relationType.startsWith("CONTAINS")|| relationType.startsWith("OVERLAP")){
+ relation.setCategory("COMMON");
}
}
- for(TimeMention timex : JCasUtil.select(jCas, TimeMention.class)){
- timex.setTimeClass("UNK");
+ }
+
+ public static class RemoveGoldAttributes extends JCasAnnotator_ImplBase {
+ @Override
+ public void process(JCas jCas) throws AnalysisEngineProcessException {
+ for(EventMention event : JCasUtil.select(jCas, EventMention.class)){
+ if(event.getEvent() != null && event.getEvent().getProperties() != null){
+ event.getEvent().getProperties().setContextualAspect("UNK");
+ event.getEvent().getProperties().setContextualModality("UNK");
+ }
+ }
+ for(TimeMention timex : JCasUtil.select(jCas, TimeMention.class)){
+ timex.setTimeClass("UNK");
+ }
}
}
}
-}
-
+
protected static Collection<BinaryTextRelation> correctArgOrder(
Collection<BinaryTextRelation> systemRelations,
Collection<BinaryTextRelation> goldRelations) {
@@ -187,57 +197,57 @@ public abstract class EvaluationOfTempor
return result;
}
- protected static void printRelationAnnotations(String fileName, Collection<BinaryTextRelation> relations) {
+ protected static void printRelationAnnotations(String fileName, Collection<BinaryTextRelation> relations) {
+
+ for(BinaryTextRelation binaryTextRelation : relations) {
+
+ Annotation arg1 = binaryTextRelation.getArg1().getArgument();
+ Annotation arg2 = binaryTextRelation.getArg2().getArgument();
+
+ String arg1Type = arg1.getClass().getSimpleName();
+ String arg2Type = arg2.getClass().getSimpleName();
- for(BinaryTextRelation binaryTextRelation : relations) {
+ int arg1Begin = arg1.getBegin();
+ int arg1End = arg1.getEnd();
+ int arg2Begin = arg2.getBegin();
+ int arg2End = arg2.getEnd();
- Annotation arg1 = binaryTextRelation.getArg1().getArgument();
- Annotation arg2 = binaryTextRelation.getArg2().getArgument();
+ String category = binaryTextRelation.getCategory();
- String arg1Type = arg1.getClass().getSimpleName();
- String arg2Type = arg2.getClass().getSimpleName();
-
- int arg1Begin = arg1.getBegin();
- int arg1End = arg1.getEnd();
- int arg2Begin = arg2.getBegin();
- int arg2End = arg2.getEnd();
-
- String category = binaryTextRelation.getCategory();
-
- System.out.format("%s\t%s\t%s\t%d\t%d\t%s\t%d\t%d\n",
- fileName, category, arg1Type, arg1Begin, arg1End, arg2Type, arg2Begin, arg2End);
- }
- }
-
- protected static String formatRelation(BinaryTextRelation relation) {
- IdentifiedAnnotation arg1 = (IdentifiedAnnotation)relation.getArg1().getArgument();
- IdentifiedAnnotation arg2 = (IdentifiedAnnotation)relation.getArg2().getArgument();
- String arg1Type ="E";
- String arg2Type ="T";
- if(arg1 instanceof TimeMention) arg1Type = "T";
- if(arg2 instanceof EventMention) arg2Type = "E";
- String text = arg1.getCAS().getDocumentText();
- int begin = Math.min(arg1.getBegin(), arg2.getBegin());
- int end = Math.max(arg1.getBegin(), arg2.getBegin());
- begin = Math.max(0, begin - 50);
- end = Math.min(text.length(), end + 50);
- return String.format(
- "%s(%s(type=%d!%d-%d!%s), %s(type=%d!%d-%d!%s)) in ...%s...",
- relation.getCategory(),
- arg1.getCoveredText(),
- arg1.getTypeID(),
- //add extra
- arg1.getBegin(),
- arg1.getEnd(),
- arg1Type,
-
- arg2.getCoveredText(),
- arg2.getTypeID(),
- //add extra
- arg2.getBegin(),
- arg2.getEnd(),
- arg2Type,
- text.substring(begin, end).replaceAll("[\r\n]", " "));
- }
+ System.out.format("%s\t%s\t%s\t%d\t%d\t%s\t%d\t%d\n",
+ fileName, category, arg1Type, arg1Begin, arg1End, arg2Type, arg2Begin, arg2End);
+ }
+ }
+
+ protected static String formatRelation(BinaryTextRelation relation) {
+ IdentifiedAnnotation arg1 = (IdentifiedAnnotation)relation.getArg1().getArgument();
+ IdentifiedAnnotation arg2 = (IdentifiedAnnotation)relation.getArg2().getArgument();
+ String arg1Type ="E";
+ String arg2Type ="T";
+ if(arg1 instanceof TimeMention) arg1Type = "T";
+ if(arg2 instanceof EventMention) arg2Type = "E";
+ String text = arg1.getCAS().getDocumentText();
+ int begin = Math.min(arg1.getBegin(), arg2.getBegin());
+ int end = Math.max(arg1.getBegin(), arg2.getBegin());
+ begin = Math.max(0, begin - 50);
+ end = Math.min(text.length(), end + 50);
+ return String.format(
+ "%s(%s(type=%d!%d-%d!%s), %s(type=%d!%d-%d!%s)) in ...%s...",
+ relation.getCategory(),
+ arg1.getCoveredText(),
+ arg1.getTypeID(),
+ //add extra
+ arg1.getBegin(),
+ arg1.getEnd(),
+ arg1Type,
+
+ arg2.getCoveredText(),
+ arg2.getTypeID(),
+ //add extra
+ arg2.getBegin(),
+ arg2.getEnd(),
+ arg2Type,
+ text.substring(begin, end).replaceAll("[\r\n]", " "));
+ }
}