ctakes-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dlig...@apache.org
Subject svn commit: r1763626 - /ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/nn/ae/EventEventTokenBasedAnnotator.java
Date Thu, 06 Oct 2016 16:30:52 GMT
Author: dligach
Date: Thu Oct  6 16:30:52 2016
New Revision: 1763626

URL: http://svn.apache.org/viewvc?rev=1763626&view=rev
Log:
fixed a few issues (args weren't numbered; context size was 5)

Modified:
    ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/nn/ae/EventEventTokenBasedAnnotator.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=1763626&r1=1763625&r2=1763626&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
Thu Oct  6 16:30:52 2016
@@ -34,9 +34,6 @@ public class EventEventTokenBasedAnnotat
 	@Override
 	public void process(JCas jCas) throws AnalysisEngineProcessException {
 
-//		Map<EventMention, Collection<EventMention>> coveringMap =
-//				JCasUtil.indexCovering(jCas, EventMention.class, EventMention.class);
-
 		//get all gold relation lookup
 		Map<List<Annotation>, BinaryTextRelation> relationLookup;
 		relationLookup = new HashMap<>();
@@ -71,12 +68,10 @@ public class EventEventTokenBasedAnnotat
 				String context;
 				if(arg2.getBegin() < arg1.getBegin()) {
 					// ... time ... event ... scenario
-					context = EventEventRelPrinter.getTokensBetween(jCas, sentence, arg2, "e", arg1, "e",
5); 
-//					context = getTokensBetweenExpanded(jCas, sentence, arg2, "e", arg1, "e", 5, coveringMap);
+					context = EventEventRelPrinter.getTokensBetween(jCas, sentence, arg2, "e2", arg1, "e1",
2); 
 				} else {
 					// ... event ... time ... scenario
-					context = EventEventRelPrinter.getTokensBetween(jCas, sentence, arg1, "e", arg2, "e",
5);
-//					context = getTokensBetweenExpanded(jCas, sentence, arg1, "e", arg2, "e", 5, coveringMap);
+					context = EventEventRelPrinter.getTokensBetween(jCas, sentence, arg1, "e1", arg2, "e2",
2);
 				}
 
 				//derive features based on context:
@@ -87,11 +82,11 @@ public class EventEventTokenBasedAnnotat
 				}
 
 				// during training, feed the features to the data writer
-				if (this.isTraining()) {
+				if(this.isTraining()) {
 					String category = getRelationCategory(relationLookup, arg1, arg2);
-					if (category == null) {
+					if(category == null) {
 						category = NO_RELATION_CATEGORY;
-					}else{
+					} else{
 						category = category.toLowerCase();
 					}
 					this.dataWriter.write(new Instance<>(category, feats));
@@ -117,114 +112,7 @@ public class EventEventTokenBasedAnnotat
 
 		}
 	}
-
-	/**
-	 * Print context from left to right.
-	 * @param contextSize number of tokens to include on the left of arg1 and on the right of
arg2
-	 */
-	public static String getTokensBetweenExpanded(
-			JCas jCas, 
-			Sentence sent, 
-			Annotation left,
-			String leftType,
-			Annotation right,
-			String rightType,
-			int contextSize,
-			Map<EventMention, Collection<EventMention>> coveringMap) {
-
-		boolean leftIsExpanded = false;
-		Annotation longerLeft = left;
-		if(left instanceof EventMention){
-			longerLeft = getLongerEvent(coveringMap, left);
-			if(longerLeft != left){
-				leftIsExpanded = true;
-			}
-		}
-
-		boolean rightIsExpanded = false;
-		Annotation longerRight = right;
-		if(right instanceof EventMention){
-			longerRight = getLongerEvent(coveringMap, right);
-			if(longerRight != right){
-				rightIsExpanded = true;
-			}
-		}
-
-		List<String> tokens = new ArrayList<>();
-		if(leftIsExpanded){
-			for(BaseToken baseToken :  JCasUtil.selectPreceding(jCas, BaseToken.class, longerLeft,
contextSize)) {
-				if(sent.getBegin() <= baseToken.getBegin()) {
-					tokens.add(baseToken.getCoveredText()); 
-				}
-			}
-		}else{
-			for(BaseToken baseToken :  JCasUtil.selectPreceding(jCas, BaseToken.class, left, contextSize))
{
-				if(sent.getBegin() <= baseToken.getBegin()) {
-					tokens.add(baseToken.getCoveredText()); 
-				}
-			}
-		}
-		tokens.add("<" + leftType + ">");
-		tokens.add(left.getCoveredText());
-		tokens.add("</" + leftType + ">");
-		if(leftIsExpanded){
-			if(rightIsExpanded){
-				for(BaseToken baseToken : JCasUtil.selectBetween(jCas, BaseToken.class, longerLeft, longerRight))
{
-					tokens.add(baseToken.getCoveredText());
-				}
-			}else{
-				for(BaseToken baseToken : JCasUtil.selectBetween(jCas, BaseToken.class, longerLeft, right))
{
-					tokens.add(baseToken.getCoveredText());
-				}
-			}
-		}else if(rightIsExpanded){
-			for(BaseToken baseToken : JCasUtil.selectBetween(jCas, BaseToken.class, left, longerRight))
{
-				tokens.add(baseToken.getCoveredText());
-			}
-		}else{
-			for(BaseToken baseToken : JCasUtil.selectBetween(jCas, BaseToken.class, left, right))
{
-				tokens.add(baseToken.getCoveredText());
-			}
-		}
-		tokens.add("<" + rightType + ">");
-		tokens.add(right.getCoveredText());
-		tokens.add("</" + rightType + ">");
-		if(rightIsExpanded){
-			for(BaseToken baseToken : JCasUtil.selectFollowing(jCas, BaseToken.class, longerRight,
contextSize)) {
-				if(baseToken.getEnd() <= sent.getEnd()) {
-					tokens.add(baseToken.getCoveredText());
-				}
-			}
-		}else{
-			for(BaseToken baseToken : JCasUtil.selectFollowing(jCas, BaseToken.class, right, contextSize))
{
-				if(baseToken.getEnd() <= sent.getEnd()) {
-					tokens.add(baseToken.getCoveredText());
-				}
-			}
-		}
-
-		return String.join(" ", tokens).replaceAll("[\r\n]", " ");
-	}
-
-	private static Annotation getLongerEvent(Map<EventMention, Collection<EventMention>>
coveringMap,
-			Annotation event) {
-		int maxSpan = getSpan(event);
-		Annotation longerEvent = event;
-		Collection<EventMention> eventList = coveringMap.get(event);
-		for(EventMention covEvent : eventList){
-			int span = getSpan(covEvent);
-			if(span > maxSpan){
-				maxSpan = span;
-				longerEvent = covEvent;
-			}
-		}
-		return longerEvent;
-	}
-
-	private static int getSpan(Annotation left) {
-		return (left.getEnd()-left.getBegin());
-	}
-
+	
 	/**
 	 * original way of getting label
 	 * @param relationLookup
@@ -308,8 +196,6 @@ public class EventEventTokenBasedAnnotat
 	}
 
 	private static List<IdentifiedAnnotationPair> getCandidateRelationArgumentPairs(JCas
jCas, Sentence sentence) {
-//		Map<EventMention, Collection<EventMention>> coveringMap =
-//				JCasUtil.indexCovering(jCas, EventMention.class, EventMention.class);
 
 		List<IdentifiedAnnotationPair> pairs = Lists.newArrayList();
 		List<EventMention> events = new ArrayList<>(JCasUtil.selectCovered(jCas, EventMention.class,
sentence));
@@ -328,44 +214,6 @@ public class EventEventTokenBasedAnnotat
 			for(int j = i+1; j < eventNum; j++){
 				EventMention eventA = events.get(i);
 				EventMention eventB = events.get(j);
-
-//				boolean eventAMedical = false;
-//				for( EventMention aEve : JCasUtil.selectCovering(jCas, EventMention.class, eventA)){
-//					if(!aEve.getClass().equals(EventMention.class)){//this event cover a UMLS semantic
type
-//						eventAMedical = true;
-//						break;
-//					}
-//				}
-//
-//				boolean eventBMedical = false;
-//				for( EventMention bEve : JCasUtil.selectCovering(jCas, EventMention.class, eventB)){
-//					if(!bEve.getClass().equals(EventMention.class)){//this event cover a UMLS semantic
type
-//						eventBMedical = true;
-//						break;
-//					}
-//				}
-
-//				if(this.isTraining()){
-//					//pairing covering system events:
-//					if(eventAMedical || eventBMedical){
-//						for (EventMention event1 : coveringMap.get(eventA)){
-//							if(!hasOverlap(event1,eventB)){//don't generate overlapping arguments
-//								pairs.add(new IdentifiedAnnotationPair(event1, eventB));
-//							}
-//
-//							for(EventMention event2 : coveringMap.get(eventB)){
-//								if(!hasOverlap(event1,event2)){//don't generate overlapping arguments
-//									pairs.add(new IdentifiedAnnotationPair(event1, event2));
-//								}
-//							}
-//						}
-//						for(EventMention event2 : coveringMap.get(eventB)){
-//							if(!hasOverlap(eventA,event2)){//don't generate overlapping arguments
-//								pairs.add(new IdentifiedAnnotationPair(eventA, event2));
-//							}
-//						}
-//					}
-//				}
 				pairs.add(new IdentifiedAnnotationPair(eventA, eventB));
 
 			}
@@ -373,15 +221,4 @@ public class EventEventTokenBasedAnnotat
 
 		return pairs;
 	}
-	
-	private static boolean hasOverlap(Annotation event1, Annotation event2) {
-		if(event1.getEnd()>=event2.getBegin()&&event1.getEnd()<=event2.getEnd()){
-			return true;
-		}
-		if(event2.getEnd()>=event1.getBegin()&&event2.getEnd()<=event1.getEnd()){
-			return true;
-		}
-		return false;
-	}
-
 }



Mime
View raw message