Mercurial > hg > ismi-richfaces
annotate src/main/java/de/mpiwg/itgroup/ismi/search/beans/Titles4PersonQuery.java @ 131:8ae989269f51
New ArabicNormalizer. NormalizerUtils.normalize() now does both translit and arabic normalization.
108: arabic normalization is not applied
Task-Url: https://it-dev.mpiwg-berlin.mpg.de/tracs/ismi/ticket/108
author | casties |
---|---|
date | Thu, 02 Feb 2017 17:59:35 +0100 |
parents | 4aa8c425685d |
children | 3c83f42a8a39 |
rev | line source |
---|---|
1 | 1 package de.mpiwg.itgroup.ismi.search.beans; |
2 | |
3 import java.io.Serializable; | |
4 import java.util.ArrayList; | |
5 import java.util.HashMap; | |
6 import java.util.List; | |
7 import java.util.Map; | |
8 | |
9 import javax.faces.model.SelectItem; | |
10 | |
11 import org.apache.commons.lang.StringUtils; | |
12 import org.mpi.openmind.repository.bo.Entity; | |
13 import org.mpi.openmind.repository.bo.Relation; | |
14 import org.mpi.openmind.repository.utils.NormalizerUtils; | |
131
8ae989269f51
New ArabicNormalizer. NormalizerUtils.normalize() now does both translit and arabic normalization.
casties
parents:
119
diff
changeset
|
15 import org.mpi.openmind.repository.utils.OldNormalizerUtils; |
1 | 16 import org.mpi.openmind.search.utils.ResultEntry; |
17 import org.mpi.openmind.search.utils.SAttributeMultipleName; | |
18 import org.mpi.openmind.search.utils.SAttributeUniqueName; | |
19 import org.mpi.openmind.search.utils.SEntity; | |
20 import org.mpi.openmind.search.utils.SRelLongKey; | |
21 import org.mpi.openmind.search.utils.SRelation; | |
22 import org.mpi.openmind.search.utils.SRelationMultipleName; | |
23 import org.mpi.openmind.search.utils.SRelationUniqueName; | |
24 | |
25 import de.mpiwg.itgroup.ismi.entry.beans.ApplicationBean; | |
26 | |
27 public class Titles4PersonQuery extends AbstractQuery implements Serializable{ | |
28 | |
29 /** | |
30 * | |
31 */ | |
32 private static final long serialVersionUID = -5342126098161866749L; | |
33 private String personName; | |
34 private String roleName = "Author"; | |
35 private static List<SelectItem> roleList; | |
36 private List<SRelLongKey> personTitleKeyList; | |
37 | |
38 private boolean displayCodex = false; | |
39 private boolean displayAlias = false; | |
40 | |
41 public Titles4PersonQuery(ApplicationBean appBean){ | |
42 super(appBean); | |
43 this.exportUrlRoot = ApplicationBean.urlISMIExportServiceAuthors; | |
44 } | |
45 | |
46 //"Author", "Annotator", "Copyist", "Corrector", "Dedicatee", "Illuminator", "Illustrator", "Owner", "Patron", "inspector" | |
47 static{ | |
48 roleList = new ArrayList<SelectItem>(); | |
49 roleList.add(new SelectItem("Author")); | |
50 roleList.add(new SelectItem("Annotator")); | |
51 roleList.add(new SelectItem("Copyist")); | |
52 roleList.add(new SelectItem("Corrector")); | |
53 roleList.add(new SelectItem("Dedicatee")); | |
54 roleList.add(new SelectItem("Illuminator")); | |
55 roleList.add(new SelectItem("Illustrator")); | |
56 roleList.add(new SelectItem("Owner")); | |
57 roleList.add(new SelectItem("Patron")); | |
58 roleList.add(new SelectItem("Inspector")); | |
59 } | |
60 | |
61 @Override | |
62 public void reset(){ | |
63 super.reset(); | |
64 this.personName = null; | |
65 this.roleName = "Author"; | |
66 this.rs = null; | |
67 this.personTitleKeyList = null; | |
68 this.displayAlias = false; | |
69 this.displayCodex = false; | |
70 } | |
71 | |
72 @Override | |
73 protected void search(){ | |
74 | |
75 this.displayAlias = false; | |
76 this.displayCodex = false; | |
77 | |
78 List<ResultEntry> rs0 = this.execute01(personName, roleName); | |
79 List<ResultEntry> rs1 = null; | |
80 if(StringUtils.isNotEmpty(personName)){ | |
81 rs1 = this.execute02(personName, roleName); | |
82 } | |
83 rs = loadResultSet(rs0, rs1); | |
84 | |
85 List<Long> idLongList = new ArrayList<Long>(); | |
86 for(Object e : rs){ | |
87 Titles4PersonEntry entry = (Titles4PersonEntry)e; | |
88 if(!idLongList.contains(entry.getPersonId())) | |
89 idLongList.add(entry.getPersonId()); | |
90 } | |
91 this.idList = ApplicationBean.generateIdList(idLongList); | |
92 | |
93 this.exportDirkUrl = ApplicationBean.generateExportURL(exportUrlRoot, idList, "xml"); | |
94 } | |
95 | |
96 | |
97 | |
98 private List<Titles4PersonEntry> loadResultSet(List<ResultEntry> rs0, List<ResultEntry> rs1){ | |
99 List<Titles4PersonEntry> currentRS = new ArrayList<Titles4PersonEntry>(); | |
100 | |
101 List<Long> personIdList = new ArrayList<Long>(); | |
102 | |
103 | |
104 for(ResultEntry re : rs0){ | |
105 Entity person = getOm().getEntityById(re.getEntMap().get(1)); | |
106 personIdList.add(person.getId()); | |
107 currentRS.addAll(getEntryFromPerson(person, null, null, this.roleName)); | |
108 } | |
109 | |
110 if(rs1 != null){ | |
111 for(ResultEntry re : rs1){ | |
112 Entity person = getOm().getEntityById(re.getEntMap().get(1)); | |
113 if(!personIdList.contains(person.getId())){ | |
114 String alias = getOm().getEntityById(re.getEntMap().get(2)).getOwnValue(); | |
115 String alias2Person = re.getRel(2, 1); | |
116 currentRS.addAll(getEntryFromPerson(person, alias, alias2Person, this.roleName)); | |
117 this.displayAlias = true; | |
118 } | |
119 } | |
120 } | |
121 | |
122 return currentRS; | |
123 } | |
124 | |
125 | |
126 /** | |
127 * Possible ways to find a title from a given person | |
128 * 1- TEXT is_exemplar_of WITNESS is_part_of CODEX owned_by PERSON | |
129 * 2- | |
130 * TEXT was_created_by PERSON | |
131 * TEXT had_patron PERSON | |
132 * TEXT was_dedicated_to PERSON | |
133 */ | |
134 private List<Titles4PersonEntry> getEntryFromPerson(Entity person, String alias, String alias2Person, String role){ | |
135 //rs.add(new Titles4PersonEntry(person, title, title2Person, codex, codex2Person, alias, alias2Person, role, subject, )); | |
136 List<Titles4PersonEntry> rs = new ArrayList<Titles4PersonQuery.Titles4PersonEntry>(); | |
137 | |
138 List<Entity> entList = getOm().getSourcesForTargetRelation(person.getId(), "was_created_by", "TEXT", -1); | |
139 for(Entity title : entList){ | |
140 String subject = getSubject(title); | |
141 rs.add(new Titles4PersonEntry(person, title, alias, alias2Person, role, subject, "TEXT was_created_by PERSON")); | |
142 } | |
143 | |
144 entList = getOm().getSourcesForTargetRelation(person.getId(), "had_patron", "TEXT", -1); | |
145 for(Entity title : entList){ | |
146 String subject = getSubject(title); | |
147 rs.add(new Titles4PersonEntry(person, title, alias, alias2Person, role, subject, "TEXT had_patron PERSON")); | |
148 } | |
149 | |
150 | |
151 entList = getOm().getSourcesForTargetRelation(person.getId(), "was_dedicated_to", "TEXT", -1); | |
152 for(Entity title : entList){ | |
153 String subject = getSubject(title); | |
154 rs.add(new Titles4PersonEntry(person, title, alias, alias2Person, role, subject, "TEXT was_dedicated_to PERSON")); | |
155 } | |
156 | |
157 entList = getOm().getSourcesForTargetRelation(person.getId(), "owned_by", "CODEX", -1); | |
158 for(Entity codex : entList){ | |
159 List<Entity> witnessList = getOm().getSourcesForTargetRelation(codex.getId(), "is_part_of", "WITNESS", -1); | |
160 for(Entity witness : witnessList){ | |
161 List<Entity> textList = getOm().getTargetsForSourceRelation(witness.getId(), "is_exemplar_of", "TEXT", -1); | |
162 for(Entity title : textList){ | |
163 String subject = getSubject(title); | |
164 rs.add(new Titles4PersonEntry(person, title, codex, witness, alias, alias2Person, role, subject, | |
165 "TEXT is_exemplar_of WITNESS is_part_of CODEX owned_by PERSON")); | |
166 this.displayCodex = true; | |
119 | 167 //System.out.println("this.displayCodex = true;"); |
1 | 168 } |
169 } | |
170 } | |
171 | |
172 return rs; | |
173 } | |
174 | |
175 private String getSubject(Entity title){ | |
176 List<Entity> subjectList = getOm().getTargetsForSourceRelation(title.getId(), "has_subject", "SUBJECT", 1); | |
177 return (subjectList.size() == 0) ? null : subjectList.get(0).getOwnValue(); | |
178 } | |
179 | |
180 private List<ResultEntry> execute01(String personName, String roleName){ | |
181 | |
182 List<SEntity> entFilters = new ArrayList<SEntity>(); | |
183 List<SRelation> relFilters = new ArrayList<SRelation>(); | |
184 | |
185 //The user can select between: | |
186 //"Author", "Annotator", "Copyist", "Corrector", "Dedicatee", "Illuminator", "Illustrator", "Owner", "Patron", "inspector" | |
187 SEntity role = new SEntity(0, "ROLE"); | |
188 role.addAtt(new SAttributeUniqueName("name", roleName)); | |
189 entFilters.add(role); | |
190 | |
191 //alias, "is_prime_alias_name_of", "PERSON" | |
192 //alias, "is_alias_name_of", "PERSON" | |
193 SEntity person = new SEntity(1, "PERSON"); | |
194 if(StringUtils.isNotEmpty(personName)){ | |
195 person.addAtt(new SAttributeMultipleName(personName, "name_translit", "name")); | |
196 } | |
197 entFilters.add(person); | |
198 | |
199 SRelationUniqueName has_role = new SRelationUniqueName(person, role, "has_role"); | |
200 relFilters.add(has_role); | |
201 | |
202 return this.appBean.getSS().search(entFilters, relFilters); | |
203 } | |
204 | |
205 private List<ResultEntry> execute02(String personName, String roleName){ | |
206 | |
207 List<SEntity> entFilters = new ArrayList<SEntity>(); | |
208 List<SRelation> relFilters = new ArrayList<SRelation>(); | |
209 | |
210 //The user can select between: | |
211 //"Author", "Annotator", "Copyist", "Corrector", "Dedicatee", "Illuminator", "Illustrator", "Owner", "Patron", "inspector" | |
212 SEntity role = new SEntity(0, "ROLE"); | |
213 role.addAtt(new SAttributeUniqueName("name", roleName)); | |
214 entFilters.add(role); | |
215 | |
216 //alias, "is_prime_alias_name_of", "PERSON" | |
217 //alias, "is_alias_name_of", "PERSON" | |
218 SEntity person = new SEntity(1, "PERSON"); | |
219 entFilters.add(person); | |
220 | |
221 SEntity alias = new SEntity(2, "ALIAS"); | |
222 alias.addAtt(new SAttributeUniqueName("alias", personName)); | |
223 entFilters.add(alias); | |
224 | |
225 SRelationMultipleName is_alias = new SRelationMultipleName(alias, person, "is_alias_name_of", "is_prime_alias_name_of"); | |
226 SRelationUniqueName has_role = new SRelationUniqueName(person, role, "has_role"); | |
227 relFilters.add(has_role); | |
228 relFilters.add(is_alias); | |
229 | |
230 return this.appBean.getSS().search(entFilters, relFilters); | |
231 } | |
232 | |
233 public String getPersonName() { | |
234 return personName; | |
235 } | |
236 | |
237 public void setPersonName(String personName) { | |
238 this.personName = personName; | |
239 } | |
240 | |
241 public String getRoleName() { | |
242 return roleName; | |
243 } | |
244 | |
245 public void setRoleName(String roleName) { | |
246 this.roleName = roleName; | |
247 } | |
248 | |
249 public List<SRelLongKey> getPersonTitleKeyList() { | |
250 return personTitleKeyList; | |
251 } | |
252 | |
253 public void setPersonTitleKeyList(List<SRelLongKey> personTitleKeyList) { | |
254 this.personTitleKeyList = personTitleKeyList; | |
255 } | |
256 | |
257 public List<SelectItem> getRoleList() { | |
258 return roleList; | |
259 } | |
260 | |
261 public boolean isDisplayCodex() { | |
262 return displayCodex; | |
263 } | |
264 | |
265 public boolean isDisplayAlias() { | |
266 return displayAlias; | |
267 } | |
268 | |
269 | |
270 | |
271 public class Titles4PersonEntry implements Comparable<Titles4PersonEntry>, Serializable{ | |
272 private static final long serialVersionUID = 7798695003500406910L; | |
273 | |
274 private Long personId; | |
275 private String personOv; | |
276 private String personNOv; | |
277 | |
278 private Long titleId; | |
279 private String titleOv; | |
280 private String titleNOv; | |
281 | |
282 private Long codexId; | |
283 private String codexOv; | |
284 private String codex2Person; | |
285 | |
286 private Long witnessId; | |
287 private String witnessOv; | |
288 private String witnessNOv; | |
289 | |
290 private String alias; | |
291 private String alias2Person; | |
292 | |
293 private String role; | |
294 //private String title2Person; | |
295 private String subject; | |
296 | |
297 | |
298 | |
299 private String query; | |
300 | |
301 public Titles4PersonEntry( | |
302 Entity person, | |
303 Entity title, | |
304 Entity codex, | |
305 Entity witness, | |
306 String alias, | |
307 String alias2Person, | |
308 String role, | |
309 String subject, | |
310 String query | |
311 ){ | |
312 | |
313 set(person, title); | |
314 this.alias = alias; | |
315 this.alias2Person = alias2Person; | |
316 this.role = role; | |
317 this.subject = subject; | |
318 this.query = query; | |
319 if(codex != null){ | |
320 this.codexId = codex.getId(); | |
321 this.codexOv = codex.getOwnValue(); | |
322 } | |
323 if(witness != null){ | |
324 this.witnessId = witness.getId(); | |
325 this.witnessOv = witness.getOwnValue(); | |
326 this.witnessNOv = witness.getNormalizedOwnValue(); | |
327 } | |
328 } | |
329 | |
330 public Titles4PersonEntry( | |
331 Entity person, | |
332 Entity title, | |
333 String alias, | |
334 String alias2Person, | |
335 String role, | |
336 String subject, | |
337 String query | |
338 ){ | |
339 | |
340 set(person, title); | |
341 this.alias = alias; | |
342 this.alias2Person = alias2Person; | |
343 this.role = role; | |
344 this.subject = subject; | |
345 this.query = query; | |
346 } | |
347 | |
348 private void set(Entity person, Entity title){ | |
349 this.personId = person.getId(); | |
350 this.personOv = person.getOwnValue(); | |
351 this.personNOv = person.getNormalizedOwnValue(); | |
352 | |
353 this.titleId = title.getId(); | |
354 this.titleOv = title.getOwnValue(); | |
355 this.titleNOv = title.getNormalizedOwnValue(); | |
356 } | |
357 | |
358 public Long getPersonId() { | |
359 return personId; | |
360 } | |
361 | |
362 public String getPersonOv() { | |
363 return personOv; | |
364 } | |
365 | |
366 public String getPersonNOv() { | |
367 return personNOv; | |
368 } | |
369 | |
370 public String getAlias() { | |
371 return alias; | |
372 } | |
373 | |
374 public String getAlias2Person() { | |
375 return alias2Person; | |
376 } | |
377 | |
378 public Long getTitleId() { | |
379 return titleId; | |
380 } | |
381 | |
382 public String getTitleOv() { | |
383 return titleOv; | |
384 } | |
385 | |
386 public String getTitleNOv() { | |
387 return titleNOv; | |
388 } | |
389 | |
390 public String getRole() { | |
391 return role; | |
392 } | |
393 | |
394 public String getSubject() { | |
395 return subject; | |
396 } | |
397 | |
398 public Long getCodexId() { | |
399 return codexId; | |
400 } | |
401 | |
402 public String getCodexOv() { | |
403 return codexOv; | |
404 } | |
405 | |
406 | |
407 public String getCodex2Person() { | |
408 return codex2Person; | |
409 } | |
410 | |
411 public String getQuery() { | |
412 return query; | |
413 } | |
414 | |
415 public Long getWitnessId() { | |
416 return witnessId; | |
417 } | |
418 | |
419 public String getWitnessOv() { | |
420 return witnessOv; | |
421 } | |
422 | |
423 public String getWitnessNOv() { | |
424 return witnessNOv; | |
425 } | |
426 | |
427 @Override | |
428 public int compareTo(Titles4PersonEntry o) { | |
429 if(!this.personId.equals(o.personId)){ | |
430 | |
131
8ae989269f51
New ArabicNormalizer. NormalizerUtils.normalize() now does both translit and arabic normalization.
casties
parents:
119
diff
changeset
|
431 int comparisonPerson = OldNormalizerUtils.normalizedToCompare(personNOv).compareTo( |
8ae989269f51
New ArabicNormalizer. NormalizerUtils.normalize() now does both translit and arabic normalization.
casties
parents:
119
diff
changeset
|
432 OldNormalizerUtils.normalizedToCompare(o.personNOv)); |
1 | 433 if(comparisonPerson != 0){ |
434 return comparisonPerson; | |
435 }else{ | |
436 if(StringUtils.isNotEmpty(role) && StringUtils.isNotEmpty(o.role)){ | |
437 int comparisonRole = this.role.compareTo(o.role); | |
438 if(comparisonRole != 0){ | |
439 return comparisonRole; | |
440 } | |
441 }else{ | |
442 if(StringUtils.isNotEmpty(role)){ | |
443 return -1; | |
444 }else if(StringUtils.isNotEmpty(o.role)){ | |
445 return 1; | |
446 } | |
447 } | |
448 } | |
449 }else{ | |
450 if(!this.titleId.equals(o.titleId)){ | |
451 //comparing subject | |
452 if(StringUtils.isNotEmpty(subject) && StringUtils.isNotEmpty(o.subject)){ | |
453 int comparisonSubject = this.subject.compareTo(o.subject); | |
454 if(comparisonSubject != 0){ | |
455 return comparisonSubject; | |
456 } | |
457 }else{ | |
458 if(StringUtils.isNotEmpty(subject)){ | |
459 return -1; | |
460 }else if(StringUtils.isNotEmpty(o.subject)){ | |
461 return 1; | |
462 } | |
463 } | |
464 //comparing title | |
131
8ae989269f51
New ArabicNormalizer. NormalizerUtils.normalize() now does both translit and arabic normalization.
casties
parents:
119
diff
changeset
|
465 int comparisonTitle = OldNormalizerUtils.normalizedToCompare(titleNOv).compareTo( |
8ae989269f51
New ArabicNormalizer. NormalizerUtils.normalize() now does both translit and arabic normalization.
casties
parents:
119
diff
changeset
|
466 OldNormalizerUtils.normalizedToCompare(o.titleNOv)); |
1 | 467 return comparisonTitle; |
468 } | |
469 } | |
470 return 0; | |
471 } | |
472 } | |
473 | |
474 } |