ctakes-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dlig...@apache.org
Subject svn commit: r1763767 - in /ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/nn: ae/EventEventTokenBasedAnnotator.java data/EventEventRelPrinter.java eval/EventEventNeuralEvaluation.java
Date Fri, 07 Oct 2016 14:21:48 GMT
Author: dligach
Date: Fri Oct  7 14:21:47 2016
New Revision: 1763767

URL: http://svn.apache.org/viewvc?rev=1763767&view=rev
Log:
cleanup + added error checking + fixed mistake where in test() we ran a wrong ae

Modified:
    ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/nn/ae/EventEventTokenBasedAnnotator.java
    ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/nn/data/EventEventRelPrinter.java
    ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/nn/eval/EventEventNeuralEvaluation.java

Modified: ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/nn/ae/EventEventTokenBasedAnnotator.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/nn/ae/EventEventTokenBasedAnnotator.java?rev=1763767&r1=1763766&r2=1763767&view=diff
==============================================================================
--- ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/nn/ae/EventEventTokenBasedAnnotator.java
(original)
+++ ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/nn/ae/EventEventTokenBasedAnnotator.java
Fri Oct  7 14:21:47 2016
@@ -2,7 +2,6 @@ package org.apache.ctakes.temporal.nn.ae
 
 import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -12,7 +11,6 @@ import org.apache.ctakes.temporal.nn.dat
 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.syntax.BaseToken;
 import org.apache.ctakes.typesystem.type.textsem.EventMention;
 import org.apache.ctakes.typesystem.type.textsem.IdentifiedAnnotation;
 import org.apache.ctakes.typesystem.type.textspan.Sentence;
@@ -34,7 +32,7 @@ public class EventEventTokenBasedAnnotat
 	@Override
 	public void process(JCas jCas) throws AnalysisEngineProcessException {
 
-		//get all gold relation lookup
+		// get all gold relation lookup
 		Map<List<Annotation>, BinaryTextRelation> relationLookup;
 		relationLookup = new HashMap<>();
 		if (this.isTraining()) {
@@ -47,18 +45,18 @@ public class EventEventTokenBasedAnnotat
 				if(relationLookup.containsKey(key)){
 					String reln = relationLookup.get(key).getCategory();
 					System.err.println("Error in: "+ ViewUriUtil.getURI(jCas).toString());
-					System.err.println("Error! This attempted relation " + relation.getCategory() + " already
has a relation " + reln + " at this span: " + arg1.getCoveredText() + " -- " + arg2.getCoveredText());
-				}else{
+					System.err.println("Error! This attempted relation " + relation.getCategory() + 
+					    " already has a relation " + reln + " at this span: " + 
+					    arg1.getCoveredText() + " -- " + arg2.getCoveredText());
+				} else {
 					relationLookup.put(key, relation);
 				}
 			}
 		}
 
-		// go over sentences, extracting event-time relation instances
 		for(Sentence sentence : JCasUtil.select(jCas, Sentence.class)) {
 			// collect all relevant relation arguments from the sentence
-			List<IdentifiedAnnotationPair> candidatePairs =
-					getCandidateRelationArgumentPairs(jCas, sentence);
+			List<IdentifiedAnnotationPair> candidatePairs = getCandidateRelationArgumentPairs(jCas,
sentence);
 
 			// walk through the pairs of annotations
 			for (IdentifiedAnnotationPair pair : candidatePairs) {
@@ -67,10 +65,11 @@ public class EventEventTokenBasedAnnotat
 
 				String context;
 				if(arg2.getBegin() < arg1.getBegin()) {
-					// ... time ... event ... scenario
+					// ... event2 ... event1 ... scenario
+          System.out.println("\n-------------- aTHIS NEVER NAPPENS ------------\n");
 					context = EventEventRelPrinter.getTokensBetween(jCas, sentence, arg2, "e2", arg1, "e1",
2); 
 				} else {
-					// ... event ... time ... scenario
+					// ... event1 ... event2 ... scenario
 					context = EventEventRelPrinter.getTokensBetween(jCas, sentence, arg1, "e1", arg2, "e2",
2);
 				}
 
@@ -90,7 +89,7 @@ public class EventEventTokenBasedAnnotat
 						category = category.toLowerCase();
 					}
 					this.dataWriter.write(new Instance<>(category, feats));
-				}else {
+				} else {
 					String predictedCategory = this.classifier.classify(feats);
 
 					// add a relation annotation if a true relation was predicted
@@ -129,7 +128,7 @@ public class EventEventTokenBasedAnnotat
 		if (relation != null) {
 			if(arg2.getBegin() < arg1.getBegin()){
 				category = relation.getCategory() + "-1";
-			}else{
+			} else {
 				category = relation.getCategory();
 			}
 		} else {
@@ -137,7 +136,7 @@ public class EventEventTokenBasedAnnotat
 			if (relation != null) {
 				if(arg2.getBegin() < arg1.getBegin()){
 					category = relation.getCategory();
-				}else{
+				} else {
 					category = relation.getCategory() + "-1";
 				}
 			}
@@ -199,7 +198,7 @@ public class EventEventTokenBasedAnnotat
 
 		List<IdentifiedAnnotationPair> pairs = Lists.newArrayList();
 		List<EventMention> events = new ArrayList<>(JCasUtil.selectCovered(jCas, EventMention.class,
sentence));
-		//filter events:
+		// filter events
 		List<EventMention> realEvents = Lists.newArrayList();
 		for( EventMention event : events){
 			if(event.getClass().equals(EventMention.class)){
@@ -209,13 +208,11 @@ public class EventEventTokenBasedAnnotat
 		events = realEvents;
 
 		int eventNum = events.size();
-
-		for (int i = 0; i < eventNum-1; i++){
-			for(int j = i+1; j < eventNum; j++){
+		for (int i = 0; i < eventNum-1; i++) {
+			for(int j = i+1; j < eventNum; j++) {
 				EventMention eventA = events.get(i);
 				EventMention eventB = events.get(j);
 				pairs.add(new IdentifiedAnnotationPair(eventA, eventB));
-
 			}
 		}
 

Modified: ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/nn/data/EventEventRelPrinter.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/nn/data/EventEventRelPrinter.java?rev=1763767&r1=1763766&r2=1763767&view=diff
==============================================================================
--- ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/nn/data/EventEventRelPrinter.java
(original)
+++ ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/nn/data/EventEventRelPrinter.java
Fri Oct  7 14:21:47 2016
@@ -167,11 +167,11 @@ public class EventEventRelPrinter {
             String label = "none";            
             if(forwardRelation != null) {
               if(forwardRelation.getCategory().equals("CONTAINS")) {
-                label = "contains";   // this is contains relation
+                label = "contains";   // mention1 contains mention2
               }
             } else if(reverseRelation != null) {
               if(reverseRelation.getCategory().equals("CONTAINS")) {
-                label = "contains-1"; // this is contains relation
+                label = "contains-1"; // mention2 contains mention1
               }
             } 
 

Modified: ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/nn/eval/EventEventNeuralEvaluation.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/nn/eval/EventEventNeuralEvaluation.java?rev=1763767&r1=1763766&r2=1763767&view=diff
==============================================================================
--- ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/nn/eval/EventEventNeuralEvaluation.java
(original)
+++ ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/nn/eval/EventEventNeuralEvaluation.java
Fri Oct  7 14:21:47 2016
@@ -33,7 +33,6 @@ import java.util.Map;
 import java.util.Set;
 
 import org.apache.ctakes.relationextractor.eval.RelationExtractorEvaluation.HashableArguments;
-import org.apache.ctakes.temporal.ae.EventEventCNNAnnotator;
 import org.apache.ctakes.temporal.ae.baselines.RecallBaselineEventTimeRelationAnnotator;
 import org.apache.ctakes.temporal.eval.EvaluationOfEventEventThymeRelations.RemoveCrossSentenceRelations;
 import org.apache.ctakes.temporal.eval.EvaluationOfEventTimeRelations.ParameterSettings;
@@ -153,11 +152,8 @@ EvaluationOfTemporalRelations_ImplBase{
 		}
 		ParameterSettings params = allParams;
 
-		//    possibleParams.add(defaultParams);
-
-		//    for(ParameterSettings params : possibleParams){
 		try{
-			File workingDir = new File("target/eval/thyme/"); // new File("/Volumes/chip-nlp/Public/THYME/eval/thyme/");//target/eval/thyme/");
+			File workingDir = new File("target/eval/thyme/"); 
 			if(!workingDir.exists()) workingDir.mkdirs();
 			if(options.getUseTmp()){
 				File tempModelDir = File.createTempFile("temporal", null, workingDir);
@@ -200,8 +196,6 @@ EvaluationOfTemporalRelations_ImplBase{
 				evaluation.prepareXMIsFor(patientSets);
 			}
 
-			//			evaluation.printErrors = true;
-
 			//sort list:
 			Collections.sort(training);
 			Collections.sort(testing);
@@ -213,8 +207,6 @@ EvaluationOfTemporalRelations_ImplBase{
 			}else{//test on testing set
 				params.stats = evaluation.trainAndTest(training, testing);//training
 			}
-			//      System.err.println(options.getKernelParams() == null ? params : options.getKernelParams());
-			//			System.err.println("No closure on gold::Closure on System::Recall Mode");
 			System.err.println(params.stats);
 
 			System.err.println("System predict relations #: "+ sysRelationCount);
@@ -233,14 +225,12 @@ EvaluationOfTemporalRelations_ImplBase{
 		}
 	}
 
-	//  private ParameterSettings params;
 	private boolean baseline;
 	protected boolean useClosure;
 	protected boolean useGoldAttributes;
 	protected boolean skipTrain=false;
 	public boolean skipWrite = false;
 	protected boolean testOnTrain=false;
-	//  protected boolean printRelations = false;
 
 	public EventEventNeuralEvaluation(
 			File baseDirectory,
@@ -279,7 +269,7 @@ EvaluationOfTemporalRelations_ImplBase{
 
 	@Override
 	protected void train(CollectionReader collectionReader, File directory) throws Exception
{
-		//	  if(this.baseline) return;
+
 		if(this.skipTrain) return;
 
 		if(!this.skipWrite){
@@ -297,18 +287,8 @@ EvaluationOfTemporalRelations_ImplBase{
 				//			aggregateBuilder.add(AnalysisEngineFactory.createPrimitiveDescription(AddTransitiveBeforeAndOnRelations.class));
 			}
 			aggregateBuilder.add(AnalysisEngineFactory.createEngineDescription(RemoveNonContainsRelations.class));
-
 			aggregateBuilder.add(AnalysisEngineFactory.createEngineDescription(Overlap2Contains.class));
 
-
-			//count how many sentences have timex, and how many sentences have only one timex
-			//aggregateBuilder.add(AnalysisEngineFactory.createEngineDescription(CountSentenceContainsTimes.class));
-
-			//add unlabeled nearby system events as potential links: 
-//			aggregateBuilder.add(AnalysisEngineFactory.createEngineDescription(AddEEPotentialRelations.class));
-
-			//directory = new File(directory,"event-time");//for normalization
-
 			aggregateBuilder.add(
 					AnalysisEngineFactory.createEngineDescription(EventEventTokenBasedAnnotator.class,
 							CleartkAnnotator.PARAM_IS_TRAINING,
@@ -323,13 +303,13 @@ EvaluationOfTemporalRelations_ImplBase{
 
 			SimplePipeline.runPipeline(collectionReader, aggregateBuilder.createAggregate());
 		}
-		JarClassifierBuilder.trainAndPackage(new File(directory,"event-event"));//, weightArray
+		JarClassifierBuilder.trainAndPackage(new File(directory,"event-event"));
 	}
 
 	@Override
 	protected AnnotationStatistics<String> test(CollectionReader collectionReader, File
directory)
 			throws Exception {
-		this.useClosure=false;//don't do closure for test
+		this.useClosure=false; //don't do closure for test
 		AggregateBuilder aggregateBuilder = this.getPreprocessorAggregateBuilder();
 		aggregateBuilder.add(CopyFromGold.getDescription(EventMention.class, TimeMention.class));
 
@@ -347,7 +327,7 @@ EvaluationOfTemporalRelations_ImplBase{
 
 		if (!recallModeEvaluation && this.useClosure) { //closure for gold
 			aggregateBuilder.add(
-					AnalysisEngineFactory.createEngineDescription(AddClosure.class),//AnalysisEngineFactory.createPrimitiveDescription(AddTransitiveContainsRelations.class),
+					AnalysisEngineFactory.createEngineDescription(AddClosure.class),
 					CAS.NAME_DEFAULT_SOFA,
 					GOLD_VIEW_NAME);
 		}
@@ -355,12 +335,10 @@ EvaluationOfTemporalRelations_ImplBase{
 		aggregateBuilder.add(AnalysisEngineFactory.createEngineDescription(RemoveNonContainsRelations.class),
 				CAS.NAME_DEFAULT_SOFA,
 				GOLD_VIEW_NAME);
-		//		aggregateBuilder.add(AnalysisEngineFactory.createEngineDescription(RemoveNonUMLSEtEvents.class));
 
 		aggregateBuilder.add(AnalysisEngineFactory.createEngineDescription(RemoveRelations.class));
 		aggregateBuilder.add(this.baseline ? RecallBaselineEventTimeRelationAnnotator.createAnnotatorDescription(directory)
:
-			//			EventTimeSelfRelationAnnotator.createEngineDescription(new File(directory,"event-time")));
-			AnalysisEngineFactory.createEngineDescription(EventEventCNNAnnotator.class,
+			AnalysisEngineFactory.createEngineDescription(EventEventTokenBasedAnnotator.class,
 					CleartkAnnotator.PARAM_IS_TRAINING,
 					false,
 					GenericJarClassifierFactory.PARAM_CLASSIFIER_JAR_PATH,
@@ -374,9 +352,9 @@ EvaluationOfTemporalRelations_ImplBase{
 		}
 
 		File outf = null;
-		if (recallModeEvaluation && this.useClosure) {//add closure for system output
+		if (recallModeEvaluation && this.useClosure) { //add closure for system output
 			aggregateBuilder.add(
-					AnalysisEngineFactory.createEngineDescription(AddClosure.class),//AnalysisEngineFactory.createPrimitiveDescription(AddTransitiveContainsRelations.class),
+					AnalysisEngineFactory.createEngineDescription(AddClosure.class),
 					GOLD_VIEW_NAME,
 					CAS.NAME_DEFAULT_SOFA
 					);
@@ -412,19 +390,6 @@ EvaluationOfTemporalRelations_ImplBase{
 					systemView,
 					BinaryTextRelation.class);
 
-			//newly add
-			//			systemRelations = removeNonGoldRelations(systemRelations, goldRelations, getSpan);//for
removing non-gold pairs
-			//			systemRelations = correctArgOrder(systemRelations, goldRelations);//change the argument
order of "OVERLAP" relation, if the order is flipped
-			//find duplicates in gold relations:
-			//			Collection<BinaryTextRelation> duplicateGoldRelations = getDuplicateRelations(goldRelations,
getSpan);
-			//			if(!duplicateGoldRelations.isEmpty()){
-			//				System.err.println("******Duplicate gold relations in : " + ViewURIUtil.getURI(jCas).toString());
-			//				for (BinaryTextRelation rel : duplicateGoldRelations){
-			//					System.err.println("Duplicate : "+ formatRelation(rel));
-			//				}
-			//			}
-			//end newly add
-
 			stats.add(goldRelations, systemRelations, getSpan, getOutcome);
 			if(this.printRelations){
 				URI uri = ViewUriUtil.getURI(jCas);
@@ -514,7 +479,6 @@ EvaluationOfTemporalRelations_ImplBase{
 
 		}
 
-
 		private static boolean hasOverlap(Annotation event1, Annotation event2) {
 			if(event1.getEnd()>=event2.getBegin()&&event1.getEnd()<=event2.getEnd()){
 				return true;



Mime
View raw message