incubator-ctakes-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From stevenbeth...@apache.org
Subject svn commit: r1410300 - in /incubator/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor: ae/RelationExtractorAnnotator.java cr/GoldEntityAndRelationReader.java knowtator/XMLReader.java
Date Fri, 16 Nov 2012 10:56:05 GMT
Author: stevenbethard
Date: Fri Nov 16 10:56:04 2012
New Revision: 1410300

URL: http://svn.apache.org/viewvc?rev=1410300&view=rev
Log:
Fixes bug in relation reader where arg1 was sometimes arg1 and sometimes arg2

Modified:
    incubator/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/ae/RelationExtractorAnnotator.java
    incubator/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/cr/GoldEntityAndRelationReader.java
    incubator/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/knowtator/XMLReader.java

Modified: incubator/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/ae/RelationExtractorAnnotator.java
URL: http://svn.apache.org/viewvc/incubator/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/ae/RelationExtractorAnnotator.java?rev=1410300&r1=1410299&r2=1410300&view=diff
==============================================================================
--- incubator/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/ae/RelationExtractorAnnotator.java
(original)
+++ incubator/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/ae/RelationExtractorAnnotator.java
Fri Nov 16 10:56:04 2012
@@ -346,43 +346,37 @@ public abstract class RelationExtractorA
    */
   public static class HashableArguments {
 
-  	protected int arg1begin;
+    protected int arg1begin;
     protected int arg1end;
     protected int arg2begin;
     protected int arg2end;
 
+    public HashableArguments(int arg1begin, int arg1end, int arg2begin, int arg2end) {
+      this.arg1begin = arg1begin;
+      this.arg1end = arg1end;
+      this.arg2begin = arg2begin;
+      this.arg2end = arg2end;
+    }
+
     public HashableArguments(Annotation arg1, Annotation arg2) {
-    	arg1begin = arg1.getBegin();
-    	arg1end = arg1.getEnd();
-    	arg2begin = arg2.getBegin();
-    	arg2end = arg2.getEnd();
-    	this.init(arg1begin, arg1end, arg2begin, arg2end);
+      this(arg1.getBegin(), arg1.getEnd(), arg2.getBegin(), arg2.getEnd());
+    }
+
+    public HashableArguments(BinaryTextRelation relation) {
+      this(getArg1(relation), getArg2(relation));
     }
-    
-	public HashableArguments(BinaryTextRelation relation) {
-		Annotation arg1, arg2;
-		String role = relation.getArg1().getRole();
-		if (role == null || role.equals("Argument")) {
-			arg1 = relation.getArg1().getArgument();
-			arg2 = relation.getArg2().getArgument();
-		} else {
-			arg2 = relation.getArg1().getArgument();
-			arg1 = relation.getArg2().getArgument();
-		}	
-		this.init(arg1.getBegin(), arg1.getEnd(), arg2.getBegin(), arg2.getEnd());
-	}
-    
-	public void init (
-			int arg1begin,
-			int arg1end,
-			int arg2begin,
-			int arg2end) {
-		this.arg1begin = arg1begin;
-		this.arg1end = arg1end;
-		this.arg2begin = arg2begin;
-		this.arg2end = arg2end;
-	}
 
+    // HACK: arg1 is not always arg1 because of bugs in the reader
+    private static Annotation getArg1(BinaryTextRelation rel) {
+      RelationArgument arg1 = rel.getArg1();
+      return arg1.getRole().equals("Argument") ? arg1.getArgument() : rel.getArg2().getArgument();
+    }
+
+    // HACK: arg2 is not always arg2 because of bugs in the reader
+    private static Annotation getArg2(BinaryTextRelation rel) {
+      RelationArgument arg2 = rel.getArg2();
+      return arg2.getRole().equals("Related_to") ? arg2.getArgument() : rel.getArg1().getArgument();
+    }
 
 	@Override
 	public boolean equals(Object otherObject) {

Modified: incubator/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/cr/GoldEntityAndRelationReader.java
URL: http://svn.apache.org/viewvc/incubator/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/cr/GoldEntityAndRelationReader.java?rev=1410300&r1=1410299&r2=1410300&view=diff
==============================================================================
--- incubator/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/cr/GoldEntityAndRelationReader.java
(original)
+++ incubator/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/cr/GoldEntityAndRelationReader.java
Fri Nov 16 10:56:04 2012
@@ -247,13 +247,13 @@ public class GoldEntityAndRelationReader
 
 			RelationArgument relationArgument1 = new RelationArgument(jCas);
 			relationArgument1.setId(relationArgumentId++);
-			relationArgument1.setArgument(modifier);
-			relationArgument1.setRole(Constants.shareModifierRole);
+			relationArgument1.setArgument(entityMention);
+			relationArgument1.setRole(Constants.shareEntityMentionRole);
 
-			RelationArgument relationArgument2 = new RelationArgument(jCas);
-			relationArgument2.setId(relationArgumentId++);
-			relationArgument2.setArgument(entityMention);
-			relationArgument2.setRole(Constants.shareEntityMentionRole);
+      RelationArgument relationArgument2 = new RelationArgument(jCas);
+      relationArgument2.setId(relationArgumentId++);
+      relationArgument2.setArgument(modifier);
+      relationArgument2.setRole(Constants.shareModifierRole);
 
 			BinaryTextRelation binaryTextRelation = new BinaryTextRelation(jCas);
 			binaryTextRelation.setArg1(relationArgument1);

Modified: incubator/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/knowtator/XMLReader.java
URL: http://svn.apache.org/viewvc/incubator/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/knowtator/XMLReader.java?rev=1410300&r1=1410299&r2=1410300&view=diff
==============================================================================
--- incubator/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/knowtator/XMLReader.java
(original)
+++ incubator/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/knowtator/XMLReader.java
Fri Nov 16 10:56:04 2012
@@ -149,7 +149,13 @@ public class XMLReader {
   	String id2 = hashComplexSlotMentions.get(ids.get(1)).value;          // obtain mention
id2                                       
   	String role2 = hashComplexSlotMentions.get(ids.get(1)).role;         // e.g. Related_to
    
 
-  	relations.add(new RelationInfo(id1, id2, role1, role2, relationType));
+  	if (role1.equals("Argument") && role2.equals("Related_to")) {
+  	  relations.add(new RelationInfo(id1, id2, role1, role2, relationType));
+  	} else if (role2.equals("Argument") && role1.equals("Related_to")) {
+  	  relations.add(new RelationInfo(id2, id1, role2, role1, relationType));
+  	} else {
+  	  throw new RuntimeException(String.format("Unexpected roles: %s %s", role1, role2));
+  	}
   }
   
   /**



Mime
View raw message