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