ctakes-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c...@apache.org
Subject svn commit: r1735676 - /ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/eval/RelationExtractorEvaluation.java
Date Fri, 18 Mar 2016 20:36:42 GMT
Author: clin
Date: Fri Mar 18 20:36:42 2016
New Revision: 1735676

URL: http://svn.apache.org/viewvc?rev=1735676&view=rev
Log:
modify the equals() and hashCode() so that sorting will not violate hashcode contract for
event-time relation evaluation.

Modified:
    ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/eval/RelationExtractorEvaluation.java

Modified: ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/eval/RelationExtractorEvaluation.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/eval/RelationExtractorEvaluation.java?rev=1735676&r1=1735675&r2=1735676&view=diff
==============================================================================
--- ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/eval/RelationExtractorEvaluation.java
(original)
+++ ctakes/trunk/ctakes-relation-extractor/src/main/java/org/apache/ctakes/relationextractor/eval/RelationExtractorEvaluation.java
Fri Mar 18 20:36:42 2016
@@ -767,21 +767,67 @@ public class RelationExtractorEvaluation
 
 		@Override
 		public boolean equals(Object otherObject) {
+			int preArgBegin;
+			int preArgEnd;
+			int ltrArgBegin;
+			int ltrArgEnd;
+			if(this.arg1begin< this.arg2begin){
+				preArgBegin = this.arg1begin;
+				preArgEnd   = this.arg1end;
+				ltrArgBegin = this.arg2begin;
+				ltrArgEnd   = this.arg2end;
+			}else{
+				preArgBegin = this.arg2begin;
+				preArgEnd 	= this.arg2end;
+				ltrArgBegin = this.arg1begin;
+				ltrArgEnd 	= this.arg1end;
+			}
 			boolean result = false;
 			if (otherObject instanceof HashableArguments) {
 				HashableArguments other = (HashableArguments) otherObject;
+				int otherPreArgBegin;
+				int otherPreArgEnd;
+				int otherLtrArgBegin;
+				int otherLtrArgEnd;
+				if(other.arg1begin< other.arg2begin){
+					otherPreArgBegin = other.arg1begin;
+					otherPreArgEnd   = other.arg1end;
+					otherLtrArgBegin = other.arg2begin;
+					otherLtrArgEnd   = other.arg2end;
+				}else{
+					otherPreArgBegin = other.arg2begin;
+					otherPreArgEnd   = other.arg2end;
+					otherLtrArgBegin = other.arg1begin;
+					otherLtrArgEnd   = other.arg1end;
+				}
 				result =
 						(this.getClass() == other.getClass()
-						&& this.arg1begin == other.arg1begin
-						&& this.arg1end == other.arg1end
-						&& this.arg2begin == other.arg2begin && this.arg2end == other.arg2end);
+						&& preArgBegin == otherPreArgBegin
+						&& preArgEnd == otherPreArgEnd
+						&& ltrArgBegin == otherLtrArgBegin 
+						&& ltrArgEnd == otherLtrArgEnd);
 			}
 			return result;
 		}
 
 		@Override
 		public int hashCode() {
-			return Objects.hashCode(this.arg1begin, this.arg1end, this.arg2begin, this.arg2end);
+			int preArgBegin;
+			int preArgEnd;
+			int ltrArgBegin;
+			int ltrArgEnd;
+			if(this.arg1begin< this.arg2begin){
+				preArgBegin = this.arg1begin;
+				preArgEnd   = this.arg1end;
+				ltrArgBegin = this.arg2begin;
+				ltrArgEnd   = this.arg2end;
+			}else{
+				preArgBegin = this.arg2begin;
+				preArgEnd 	= this.arg2end;
+				ltrArgBegin = this.arg1begin;
+				ltrArgEnd 	= this.arg1end;
+			}
+			return Objects.hashCode(preArgBegin, preArgEnd, ltrArgBegin, ltrArgEnd);
 		}
 
 		@Override



Mime
View raw message