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