1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package ubic.basecode.ontology.ncbo;
16
17
18
19
20 public class AnnotatorResponse implements Comparable<AnnotatorResponse> {
21
22 private String valueUri = "";
23 private String matchType = "";
24 private String txtMatched = "";
25 private Integer indexFrom = null;
26 private Integer indexTo = null;
27 private String ontologyUsed = "";
28 private String searchQueryUsed = "";
29
30 private boolean exactSynonym = false;
31 private boolean exactMatch = false;
32
33 public AnnotatorResponse( String valueUri, String matchType, String txtMatched, Integer indexFrom, Integer indexTo,
34 String ontologyUsed, String searchQueryUsed ) {
35 super();
36 this.valueUri = valueUri;
37 this.matchType = matchType;
38 this.txtMatched = txtMatched;
39 this.indexFrom = indexFrom;
40 this.indexTo = indexTo;
41 this.ontologyUsed = ontologyUsed;
42 this.searchQueryUsed = searchQueryUsed;
43
44 if ( indexFrom.equals( 1 ) && indexTo.equals( searchQueryUsed.length() ) ) {
45
46 if ( matchType.equals( "SYN" ) ) {
47 exactSynonym = true;
48 } else {
49 exactMatch = true;
50 }
51
52 }
53
54 }
55
56 @Override
57 public String toString() {
58 return "AnnotatorResponse [valueUri=" + valueUri + ", matchType=" + matchType + ", txtMatched=" + txtMatched
59 + ", indexFrom=" + indexFrom + ", indexTo=" + indexTo + ", ontologyUsed=" + ontologyUsed
60 + ", searchQueryUsed=" + searchQueryUsed + ", exactSynonym=" + exactSynonym + ", exactMatch="
61 + exactMatch + "]";
62 }
63
64 @Override
65 public int compareTo( AnnotatorResponse annotatorResponse ) {
66
67 boolean exactMatchFound = exactMatch;
68 boolean exactMatchCompare = annotatorResponse.isExactMatch();
69 boolean isSynonyme = exactSynonym;
70 boolean isSynonymeCompare = annotatorResponse.isExactSynonym();
71 boolean diseaseOntology = isDiseaseUsed();
72 boolean diseaseCompare = annotatorResponse.isDiseaseUsed();
73
74 if ( diseaseOntology ) {
75
76 if ( exactMatchFound ) {
77 return -1;
78 } else if ( isSynonyme ) {
79 if ( !diseaseCompare ) {
80 return -1;
81 } else if ( !exactMatchCompare ) {
82 return -1;
83 }
84 }
85 } else if ( exactMatchFound || isSynonyme ) {
86 if ( diseaseCompare ) {
87 if ( exactMatchCompare || isSynonymeCompare ) {
88 return 1;
89 }
90 }
91 if ( exactMatchFound ) {
92 return -1;
93 } else if ( isSynonyme && !exactMatchCompare ) {
94 return -1;
95 }
96 }
97 return 1;
98 }
99
100 public boolean isDiseaseUsed() {
101 if ( ontologyUsed.equalsIgnoreCase( AnnotatorClient.DOID_ONTOLOGY ) ) {
102 return true;
103 }
104 return false;
105 }
106
107 public boolean isHpUsed() {
108 if ( ontologyUsed.equalsIgnoreCase( AnnotatorClient.HP_ONTOLOGY ) ) {
109 return true;
110 }
111 return false;
112 }
113
114 public String getValueUri() {
115 return valueUri;
116 }
117
118 public void setValueUri( String valueUri ) {
119 this.valueUri = valueUri;
120 }
121
122 public String getMatchType() {
123 return matchType;
124 }
125
126 public void setMatchType( String matchType ) {
127 this.matchType = matchType;
128 }
129
130 public String getTxtMatched() {
131 return txtMatched;
132 }
133
134 public void setTxtMatched( String txtMatched ) {
135 this.txtMatched = txtMatched;
136 }
137
138 public Integer getIndexFrom() {
139 return indexFrom;
140 }
141
142 public void setIndexFrom( Integer indexFrom ) {
143 this.indexFrom = indexFrom;
144 }
145
146 public Integer getIndexTo() {
147 return indexTo;
148 }
149
150 public void setIndexTo( Integer indexTo ) {
151 this.indexTo = indexTo;
152 }
153
154 public String getOntologyUsed() {
155 return ontologyUsed;
156 }
157
158 public void setOntologyUsed( String ontologyUsed ) {
159 this.ontologyUsed = ontologyUsed;
160 }
161
162 public String getSearchQueryUsed() {
163 return searchQueryUsed;
164 }
165
166 public void setSearchQueryUsed( String searchQueryUsed ) {
167 this.searchQueryUsed = searchQueryUsed;
168 }
169
170 public boolean isExactSynonym() {
171 return exactSynonym;
172 }
173
174 public void setExactSynonym( boolean exactSynonym ) {
175 this.exactSynonym = exactSynonym;
176 }
177
178 public boolean isExactMatch() {
179 return exactMatch;
180 }
181
182 public void setExactMatch( boolean exactMatch ) {
183 this.exactMatch = exactMatch;
184 }
185
186 @Override
187 public int hashCode() {
188 final int prime = 31;
189 int result = 1;
190 result = prime * result + ( ( indexFrom == null ) ? 0 : indexFrom.hashCode() );
191 result = prime * result + ( ( indexTo == null ) ? 0 : indexTo.hashCode() );
192 result = prime * result + ( ( matchType == null ) ? 0 : matchType.hashCode() );
193 result = prime * result + ( ( ontologyUsed == null ) ? 0 : ontologyUsed.hashCode() );
194 result = prime * result + ( ( searchQueryUsed == null ) ? 0 : searchQueryUsed.hashCode() );
195 result = prime * result + ( ( txtMatched == null ) ? 0 : txtMatched.hashCode() );
196 result = prime * result + ( ( valueUri == null ) ? 0 : valueUri.hashCode() );
197 return result;
198 }
199
200 @Override
201 public boolean equals( Object obj ) {
202 if ( this == obj ) return true;
203 if ( obj == null ) return false;
204 if ( getClass() != obj.getClass() ) return false;
205 AnnotatorResponse/ubic/basecode/ontology/ncbo/AnnotatorResponse.html#AnnotatorResponse">AnnotatorResponse other = ( AnnotatorResponse ) obj;
206 if ( indexFrom == null ) {
207 if ( other.indexFrom != null ) return false;
208 } else if ( !indexFrom.equals( other.indexFrom ) ) return false;
209 if ( indexTo == null ) {
210 if ( other.indexTo != null ) return false;
211 } else if ( !indexTo.equals( other.indexTo ) ) return false;
212 if ( matchType == null ) {
213 if ( other.matchType != null ) return false;
214 } else if ( !matchType.equals( other.matchType ) ) return false;
215 if ( ontologyUsed == null ) {
216 if ( other.ontologyUsed != null ) return false;
217 } else if ( !ontologyUsed.equals( other.ontologyUsed ) ) return false;
218 if ( searchQueryUsed == null ) {
219 if ( other.searchQueryUsed != null ) return false;
220 } else if ( !searchQueryUsed.equals( other.searchQueryUsed ) ) return false;
221 if ( txtMatched == null ) {
222 if ( other.txtMatched != null ) return false;
223 } else if ( !txtMatched.equals( other.txtMatched ) ) return false;
224 if ( valueUri == null ) {
225 if ( other.valueUri != null ) return false;
226 } else if ( !valueUri.equals( other.valueUri ) ) return false;
227 return true;
228 }
229
230
231 public String findCondition( boolean modifiedSearch ) {
232
233 String condition = null;
234
235 if ( isDiseaseUsed() ) {
236
237 if ( isExactMatch() ) {
238 condition = "A) Found Exact With Disease Annotator";
239
240 } else if ( isExactSynonym() ) {
241 condition = "B) Found Synonym With Disease Annotator Synonym";
242 }
243 } else if ( isHpUsed() ) {
244
245 if ( isExactMatch() ) {
246 condition = "C) Found Exact With HP Annotator";
247 } else if ( isExactSynonym() ) {
248 condition = "D) Found Synonym With HP Annotator Synonym";
249 }
250 }
251
252 if ( condition != null && modifiedSearch ) {
253 condition = condition + " modified search ";
254 }
255
256 return condition;
257 }
258
259 }