Mercurial > hg > ismi-richfaces
annotate src/main/java/de/mpiwg/itgroup/ismi/search/beans/SampleSearch06.java @ 215:26138384984c
update more instances of IIIF server URL.
author | casties |
---|---|
date | Sat, 15 Jan 2022 16:09:55 +0100 |
parents | 8ae989269f51 |
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.Collection; | |
6 import java.util.Collections; | |
7 import java.util.List; | |
8 | |
9 import javax.faces.event.ValueChangeEvent; | |
10 import javax.faces.model.SelectItem; | |
11 | |
12 import org.apache.commons.lang.StringUtils; | |
13 import org.mpi.openmind.repository.bo.Entity; | |
14 import org.mpi.openmind.repository.utils.NormalizerUtils; | |
131
8ae989269f51
New ArabicNormalizer. NormalizerUtils.normalize() now does both translit and arabic normalization.
casties
parents:
1
diff
changeset
|
15 import org.mpi.openmind.repository.utils.OldNormalizerUtils; |
1 | 16 import org.mpi.openmind.repository.utils.TransliterationUtil; |
17 import org.mpi.openmind.search.utils.ResultEntry; | |
18 import org.mpi.openmind.search.utils.SAttributeMultipleName; | |
19 import org.mpi.openmind.search.utils.SAttributeUniqueName; | |
20 import org.mpi.openmind.search.utils.SEntity; | |
21 import org.mpi.openmind.search.utils.SRelLongKey; | |
22 import org.mpi.openmind.search.utils.SRelation; | |
23 import org.mpi.openmind.search.utils.SRelationMultipleName; | |
24 import org.mpi.openmind.search.utils.SRelationUniqueName; | |
25 | |
26 import de.mpiwg.itgroup.ismi.entry.beans.ApplicationBean; | |
27 | |
28 /** | |
29 * 7) Bring up people associated with a particular witness | |
30 * (not just one huge list of people, but be able to distinguish owner, say, from commentator) | |
31 * @author jurzua | |
32 * | |
33 */ | |
34 public class SampleSearch06 extends AbstractQuery implements Serializable{ | |
35 | |
36 private static final long serialVersionUID = 3749889381908517654L; | |
37 private String personName; | |
38 private String roleName = "Author"; | |
39 private static List<SelectItem> roleList; | |
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 | |
58 public SampleSearch06(ApplicationBean appBean){ | |
59 super(appBean); | |
60 this.exportUrlRoot = ApplicationBean.urlISMIExportServiceAuthors; | |
61 } | |
62 | |
63 @Override | |
64 public void reset(){ | |
65 super.reset(); | |
66 this.personName = null; | |
67 this.roleName = "Author"; | |
68 this.rs = null; | |
69 this.personTitleKeyList = null; | |
70 } | |
71 | |
72 @Override | |
73 protected void search(){ | |
74 | |
75 List<ResultEntry> rs0 = this.execute01(personName, roleName); | |
76 List<ResultEntry> rs1 = null; | |
77 if(StringUtils.isNotEmpty(personName)){ | |
78 rs1 = this.execute02(personName, roleName); | |
79 } | |
80 rs = loadResultSet(rs0, rs1); | |
81 | |
82 List<Long> idLongList = new ArrayList<Long>(); | |
83 for(Object e : rs){ | |
84 ResultEntry06 entry = (ResultEntry06)e; | |
85 if(!idLongList.contains(entry.getPersonId())) | |
86 idLongList.add(entry.getPersonId()); | |
87 } | |
88 this.idList = ApplicationBean.generateIdList(idLongList); | |
89 | |
90 this.exportDirkUrl = ApplicationBean.generateExportURL(exportUrlRoot, idList, "xml"); | |
91 } | |
92 | |
93 private List<ResultEntry06> loadResultSet(List<ResultEntry> rs0, List<ResultEntry> rs1){ | |
94 List<ResultEntry06> currentRs = new ArrayList<SampleSearch06.ResultEntry06>(); | |
95 personTitleKeyList = new ArrayList<SRelLongKey>(); | |
96 | |
97 for(ResultEntry re : rs0){ | |
98 | |
99 Entity person = getOm().getEntityById(re.getEntMap().get(1)); | |
100 Entity title = getOm().getEntityById(re.getEntMap().get(2)); | |
101 | |
102 String alias = null; | |
103 String alias2Person = null; | |
104 String role = this.roleName; | |
105 String title2Person = re.getRel(2, 1); | |
106 List<Entity> subjectList = getOm().getTargetsForSourceRelation(title.getId(), "has_subject", "SUBJECT", 1); | |
107 String subject = (subjectList.size() == 0) ? null : subjectList.get(0).getOwnValue(); | |
108 | |
109 currentRs.add(new ResultEntry06(person, title, alias, alias2Person, role, title2Person, subject)); | |
110 putPersonTitleKey(person.getId(), title.getId()); | |
111 } | |
112 if(rs1 != null){ | |
113 for(ResultEntry re : rs1){ | |
114 Entity person = getOm().getEntityById(re.getEntMap().get(1)); | |
115 Entity title = getOm().getEntityById(re.getEntMap().get(3)); | |
116 if(!containsPersonTitleKey(person.getId(), title.getId())){ | |
117 | |
118 String alias = getOm().getEntityById(re.getEntMap().get(2)).getOwnValue(); | |
119 String alias2Person = re.getRel(2, 1); | |
120 String role = this.roleName; | |
121 String title2Person = re.getRel(3, 1); | |
122 List<Entity> subjectList = getOm().getTargetsForSourceRelation(title.getId(), "has_subject", "SUBJECT", 1); | |
123 String subject = (subjectList.size() == 0) ? null : subjectList.get(0).getOwnValue(); | |
124 | |
125 currentRs.add(new ResultEntry06(person, title, alias, alias2Person, role, title2Person, subject)); | |
126 putPersonTitleKey(person.getId(), title.getId()); | |
127 } | |
128 } | |
129 } | |
130 | |
131 Collections.sort(currentRs); | |
132 | |
133 return currentRs; | |
134 } | |
135 | |
136 private List<SRelLongKey> personTitleKeyList; | |
137 private boolean containsPersonTitleKey(Long personId, Long titleId){ | |
138 return personTitleKeyList.contains(new SRelLongKey(personId, titleId)); | |
139 } | |
140 private void putPersonTitleKey(Long personId, Long titleId){ | |
141 personTitleKeyList.add(new SRelLongKey(personId, titleId)); | |
142 } | |
143 | |
144 | |
145 | |
146 private List<ResultEntry> execute01(String personName, String roleName){ | |
147 | |
148 List<SEntity> entFilters = new ArrayList<SEntity>(); | |
149 List<SRelation> relFilters = new ArrayList<SRelation>(); | |
150 | |
151 //The user can select between: | |
152 //"Author", "Annotator", "Copyist", "Corrector", "Dedicatee", "Illuminator", "Illustrator", "Owner", "Patron", "inspector" | |
153 SEntity role = new SEntity(0, "ROLE"); | |
154 role.addAtt(new SAttributeUniqueName("name", roleName)); | |
155 entFilters.add(role); | |
156 | |
157 //alias, "is_prime_alias_name_of", "PERSON" | |
158 //alias, "is_alias_name_of", "PERSON" | |
159 SEntity person = new SEntity(1, "PERSON"); | |
160 if(StringUtils.isNotEmpty(personName)){ | |
161 person.addAtt(new SAttributeMultipleName(personName, "name_translit", "name")); | |
162 } | |
163 entFilters.add(person); | |
164 | |
165 SEntity text = new SEntity(2, "TEXT"); | |
166 entFilters.add(text); | |
167 | |
168 | |
169 SRelationUniqueName has_role = new SRelationUniqueName(person, role, "has_role"); | |
170 SRelationMultipleName text_to_person = new SRelationMultipleName(text, person, "was_created_by", "had_patron", "was_dedicated_to"); | |
171 relFilters.add(text_to_person); | |
172 relFilters.add(has_role); | |
173 | |
174 return this.appBean.getSS().search(entFilters, relFilters); | |
175 } | |
176 | |
177 private List<ResultEntry> execute02(String personName, String roleName){ | |
178 | |
179 List<SEntity> entFilters = new ArrayList<SEntity>(); | |
180 List<SRelation> relFilters = new ArrayList<SRelation>(); | |
181 | |
182 //The user can select between: | |
183 //"Author", "Annotator", "Copyist", "Corrector", "Dedicatee", "Illuminator", "Illustrator", "Owner", "Patron", "inspector" | |
184 SEntity role = new SEntity(0, "ROLE"); | |
185 role.addAtt(new SAttributeUniqueName("name", roleName)); | |
186 entFilters.add(role); | |
187 | |
188 //alias, "is_prime_alias_name_of", "PERSON" | |
189 //alias, "is_alias_name_of", "PERSON" | |
190 SEntity person = new SEntity(1, "PERSON"); | |
191 entFilters.add(person); | |
192 | |
193 SEntity alias = new SEntity(2, "ALIAS"); | |
194 alias.addAtt(new SAttributeUniqueName("alias", personName)); | |
195 entFilters.add(alias); | |
196 | |
197 SEntity text = new SEntity(3, "TEXT"); | |
198 entFilters.add(text); | |
199 | |
200 | |
201 SRelationMultipleName is_alias = new SRelationMultipleName(alias, person, "is_alias_name_of", "is_prime_alias_name_of"); | |
202 SRelationUniqueName has_role = new SRelationUniqueName(person, role, "has_role"); | |
203 SRelationMultipleName text_to_person = new SRelationMultipleName(text, person, "was_created_by", "had_patron", "was_dedicated_to"); | |
204 relFilters.add(text_to_person); | |
205 relFilters.add(has_role); | |
206 relFilters.add(is_alias); | |
207 | |
208 return this.appBean.getSS().search(entFilters, relFilters); | |
209 } | |
210 | |
211 | |
212 public String getPersonName() { | |
213 return personName; | |
214 } | |
215 | |
216 public void setPersonName(String personName) { | |
217 this.personName = personName; | |
218 } | |
219 | |
220 public String getRoleName() { | |
221 return roleName; | |
222 } | |
223 | |
224 public void setRoleName(String roleName) { | |
225 this.roleName = roleName; | |
226 } | |
227 | |
228 public List<SelectItem> getRoleList() { | |
229 return roleList; | |
230 } | |
231 | |
232 public class ResultEntry06 implements Comparable<ResultEntry06>, Serializable{ | |
233 private static final long serialVersionUID = 3814421582310240565L; | |
234 | |
235 private Long personId; | |
236 private String personOv; | |
237 private String personNOv; | |
238 private String alias; | |
239 private String alias2Person; | |
240 private Long titleId; | |
241 private String titleOv; | |
242 private String titleNOv; | |
243 private String role; | |
244 private String title2Person; | |
245 private String subject; | |
246 | |
247 public ResultEntry06( | |
248 Entity person, | |
249 Entity title, | |
250 String alias, | |
251 String alias2Person, | |
252 String role, | |
253 String title2Person, | |
254 String subject | |
255 ){ | |
256 | |
257 set(person, title); | |
258 this.alias = alias; | |
259 this.alias2Person = alias2Person; | |
260 this.role = role; | |
261 this.title2Person = title2Person; | |
262 this.subject = subject; | |
263 } | |
264 | |
265 private void set(Entity person, Entity title){ | |
266 this.personId = person.getId(); | |
267 this.personOv = person.getOwnValue(); | |
268 this.personNOv = person.getNormalizedOwnValue(); | |
269 | |
270 this.titleId = title.getId(); | |
271 this.titleOv = title.getOwnValue(); | |
272 this.titleNOv = title.getNormalizedOwnValue(); | |
273 } | |
274 | |
275 public Long getPersonId() { | |
276 return personId; | |
277 } | |
278 | |
279 public String getPersonOv() { | |
280 return personOv; | |
281 } | |
282 | |
283 public String getPersonNOv() { | |
284 return personNOv; | |
285 } | |
286 | |
287 public String getAlias() { | |
288 return alias; | |
289 } | |
290 | |
291 public String getAlias2Person() { | |
292 return alias2Person; | |
293 } | |
294 | |
295 public Long getTitleId() { | |
296 return titleId; | |
297 } | |
298 | |
299 public String getTitleOv() { | |
300 return titleOv; | |
301 } | |
302 | |
303 public String getTitleNOv() { | |
304 return titleNOv; | |
305 } | |
306 | |
307 public String getRole() { | |
308 return role; | |
309 } | |
310 | |
311 public String getTitle2Person() { | |
312 return title2Person; | |
313 } | |
314 | |
315 public String getSubject() { | |
316 return subject; | |
317 } | |
318 | |
319 @Override | |
320 public int compareTo(ResultEntry06 o) { | |
321 if(!this.personId.equals(o.personId)){ | |
322 | |
131
8ae989269f51
New ArabicNormalizer. NormalizerUtils.normalize() now does both translit and arabic normalization.
casties
parents:
1
diff
changeset
|
323 int comparisonPerson = OldNormalizerUtils.normalizedToCompare(personNOv).compareTo( |
8ae989269f51
New ArabicNormalizer. NormalizerUtils.normalize() now does both translit and arabic normalization.
casties
parents:
1
diff
changeset
|
324 OldNormalizerUtils.normalizedToCompare(o.personNOv)); |
1 | 325 if(comparisonPerson != 0){ |
326 return comparisonPerson; | |
327 }else{ | |
328 if(StringUtils.isNotEmpty(role) && StringUtils.isNotEmpty(o.role)){ | |
329 int comparisonRole = this.role.compareTo(o.role); | |
330 if(comparisonRole != 0){ | |
331 return comparisonRole; | |
332 } | |
333 }else{ | |
334 if(StringUtils.isNotEmpty(role)){ | |
335 return -1; | |
336 }else if(StringUtils.isNotEmpty(o.role)){ | |
337 return 1; | |
338 } | |
339 } | |
340 } | |
341 }else{ | |
342 if(!this.titleId.equals(o.titleId)){ | |
343 //comparing subject | |
344 if(StringUtils.isNotEmpty(subject) && StringUtils.isNotEmpty(o.subject)){ | |
345 int comparisonSubject = this.subject.compareTo(o.subject); | |
346 if(comparisonSubject != 0){ | |
347 return comparisonSubject; | |
348 } | |
349 }else{ | |
350 if(StringUtils.isNotEmpty(subject)){ | |
351 return -1; | |
352 }else if(StringUtils.isNotEmpty(o.subject)){ | |
353 return 1; | |
354 } | |
355 } | |
356 //comparing title | |
131
8ae989269f51
New ArabicNormalizer. NormalizerUtils.normalize() now does both translit and arabic normalization.
casties
parents:
1
diff
changeset
|
357 int comparisonTitle = OldNormalizerUtils.normalizedToCompare(titleNOv).compareTo( |
8ae989269f51
New ArabicNormalizer. NormalizerUtils.normalize() now does both translit and arabic normalization.
casties
parents:
1
diff
changeset
|
358 OldNormalizerUtils.normalizedToCompare(o.titleNOv)); |
1 | 359 return comparisonTitle; |
360 } | |
361 } | |
362 return 0; | |
363 } | |
364 } | |
365 } |