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 import java.util.Map;
|
|
7 import java.util.Map.Entry;
|
|
8
|
|
9 import javax.faces.event.ValueChangeEvent;
|
|
10 import javax.faces.model.SelectItem;
|
|
11
|
|
12 import org.apache.log4j.Logger;
|
|
13 import org.mpi.openmind.repository.bo.Attribute;
|
|
14 import org.mpi.openmind.search.utils.ResultEntry;
|
|
15 import org.mpi.openmind.search.utils.SAttribute;
|
|
16 import org.mpi.openmind.search.utils.SAttributeMultipleName;
|
|
17 import org.mpi.openmind.search.utils.SAttributeMultipleValue;
|
|
18 import org.mpi.openmind.search.utils.SAttributeUniqueName;
|
|
19 import org.mpi.openmind.search.utils.SEntity;
|
|
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.AbstractISMIBean;
|
|
25 import de.mpiwg.itgroup.ismi.entry.beans.SessionBean;
|
|
26 import de.mpiwg.itgroup.ismi.util.guiComponents.Calendar;
|
|
27
|
|
28 public class AdvancedSearchBean extends AbstractISMIBean implements Serializable{
|
|
29
|
|
30 private static Logger logger = Logger.getLogger(AdvancedSearchBean.class);
|
|
31
|
|
32 private static final long serialVersionUID = 1L;
|
|
33
|
|
34 private String currentTemplate;
|
|
35 private static List<SelectItem> templateList;
|
|
36
|
|
37 private transient Witness4TitleQuery witness4TitleQuery;
|
|
38 //private SampleSearch06 sample06;
|
|
39 private SampleSearch07 sample07;
|
|
40 private Titles4PersonQuery titles4PersonQuery;
|
|
41 private CodexOwnershipQuery codexOwnershipQuery;
|
|
42
|
|
43 static{
|
|
44 templateList = new ArrayList<SelectItem>();
|
|
45 //templateList.add(new SelectItem("sample01"));
|
|
46 templateList.add(new SelectItem("witness4Title", "Witnesses for a title"));
|
|
47 //templateList.add(new SelectItem("sample03"));
|
|
48 //templateList.add(new SelectItem("sample04"));
|
|
49 //templateList.add(new SelectItem("sample05"));
|
|
50 templateList.add(new SelectItem("titles4Person", "Titles for a person"));
|
|
51 templateList.add(new SelectItem("codexOwnership", "Codex ownership"));
|
|
52 //templateList.add(new SelectItem("sample07"));
|
|
53 //templateList.add(new SelectItem("sample08"));
|
|
54 //templateList.add(new SelectItem("sample09"));
|
|
55 }
|
|
56
|
|
57 public AdvancedSearchBean(){
|
|
58 //logger.info("AdvancedSearchBean");
|
|
59 this.reset();
|
|
60 }
|
|
61
|
|
62 public void reset(){
|
|
63 //logger.info("AdvancedSearchBean.reset()");
|
|
64 this.witness4TitleQuery = new Witness4TitleQuery(getAppBean());
|
|
65 this.titles4PersonQuery = new Titles4PersonQuery(getAppBean());
|
|
66 this.sample07 = new SampleSearch07(getAppBean());
|
|
67 this.codexOwnershipQuery = new CodexOwnershipQuery(getAppBean());
|
|
68 currentTemplate = "witness4Title";
|
|
69 }
|
|
70
|
|
71 public void listenerChange(ValueChangeEvent event){
|
|
72 /*
|
|
73 logger.info(event.getOldValue());
|
|
74 logger.info(event.getNewValue());
|
|
75 */
|
|
76 }
|
|
77
|
|
78 public String actionSearch(){
|
|
79 this.search();
|
|
80 return null;
|
|
81 }
|
|
82
|
|
83 public SampleSearch07 getSample07() {
|
|
84 return sample07;
|
|
85 }
|
|
86
|
|
87 public CodexOwnershipQuery getCodexOwnershipQuery() {
|
|
88 return codexOwnershipQuery;
|
|
89 }
|
|
90
|
|
91 public Witness4TitleQuery getWitness4TitleQuery() {
|
|
92 return witness4TitleQuery;
|
|
93 }
|
|
94
|
|
95 public void search(){
|
|
96 long start = System.currentTimeMillis();
|
|
97
|
|
98 List<ResultEntry> rs = sample06();
|
|
99
|
|
100 //printRs(rs);
|
|
101
|
|
102 long end = System.currentTimeMillis();
|
|
103 logger.info("execution time [ms] = " + (end - start));
|
|
104 logger.info("Search resultSet size= " + rs.size());
|
|
105 }
|
|
106
|
|
107
|
|
108 private List<ResultEntry> test01(){
|
|
109 List<SEntity> entFilters = new ArrayList<SEntity>();
|
|
110 List<SRelation> relFilters = new ArrayList<SRelation>();
|
|
111
|
|
112 SEntity e1 = new SEntity(0, "PERSON");
|
|
113 e1.addAtt(new SAttributeUniqueName("name_translit", "abu"));
|
|
114 entFilters.add(e1);
|
|
115
|
|
116 SEntity e2 = new SEntity(1, "ROLE");
|
|
117 e2.addAtt(new SAttributeUniqueName("name", "Author"));
|
|
118 entFilters.add(e2);
|
|
119
|
|
120 SEntity e3 = new SEntity(2, "PLACE");
|
|
121 e3.addAtt(new SAttributeUniqueName("name", "Spain"));
|
|
122 entFilters.add(e3);
|
|
123
|
|
124 SEntity e4 = new SEntity(3, "ALIAS");
|
|
125 e4.addAtt(new SAttributeUniqueName("alias", "Samuel"));
|
|
126 entFilters.add(e4);
|
|
127
|
|
128 SRelationUniqueName has_role = new SRelationUniqueName(e1.getIndex(), e2.getIndex(), "has_role");
|
|
129 SRelationUniqueName was_born_in = new SRelationUniqueName(e1.getIndex(), e3.getIndex(), "was_born_in");
|
|
130 SRelationUniqueName is_prime_alias_name_of = new SRelationUniqueName(e4.getIndex(), e1.getIndex(), "is_prime_alias_name_of");
|
|
131 relFilters.add(has_role);
|
|
132 relFilters.add(was_born_in);
|
|
133 relFilters.add(is_prime_alias_name_of);
|
|
134
|
|
135 return getAppBean().getSS().search(entFilters, relFilters);
|
|
136
|
|
137 }
|
|
138
|
|
139 private List<ResultEntry> test02(){
|
|
140 List<SEntity> entFilters = new ArrayList<SEntity>();
|
|
141 List<SRelation> relFilters = new ArrayList<SRelation>();
|
|
142
|
|
143 SEntity e2 = new SEntity(1, "ALIAS");
|
|
144 e2.addAtt(new SAttributeUniqueName("alias", "abu"));
|
|
145 entFilters.add(e2);
|
|
146
|
|
147 SEntity e1 = new SEntity(0, "TEXT");
|
|
148 e1.addAtt(new SAttributeUniqueName("full_title_translit", "abu"));
|
|
149 entFilters.add(e1);
|
|
150
|
|
151
|
|
152 SRelationMultipleName hasAlias = new SRelationMultipleName(e2.getIndex(), e1.getIndex(),
|
|
153 "is_prime_alias_title_of",
|
|
154 "is_alias_title_of",
|
|
155 "is_alias_incipit_of",
|
|
156 "is_alias_explicit_of");
|
|
157 relFilters.add(hasAlias);
|
|
158
|
|
159 return getAppBean().getSS().search(entFilters, relFilters);
|
|
160 }
|
|
161
|
|
162 private List<ResultEntry> sample01(){
|
|
163
|
|
164 List<SEntity> entFilters = new ArrayList<SEntity>();
|
|
165 List<SRelation> relFilters = new ArrayList<SRelation>();
|
|
166
|
|
167 SEntity role = new SEntity(0, "ROLE");
|
|
168 role.addAtt(new SAttributeUniqueName("name", "Author"));
|
|
169 entFilters.add(role);
|
|
170
|
|
171 //alias, "is_prime_alias_name_of", "PERSON"
|
|
172 //alias, "is_alias_name_of", "PERSON"
|
|
173 SEntity person = new SEntity(1, "PERSON");
|
|
174 person.addAtt(new SAttributeMultipleName("a", "name_translit", "name"));
|
|
175 entFilters.add(person);
|
|
176
|
|
177 /*
|
|
178 SEntity alias = new SEntity(1, "ALIAS");
|
|
179 alias.addAtt(new SAttributeUniqueName("alias", "abu"));
|
|
180 entFilters.add(alias);
|
|
181 */
|
|
182
|
|
183 SEntity title = new SEntity(2, "TEXT");
|
|
184 //title.addAtt(new SAttributeMultipleName("abu", "full_title_translit", "full_title"));
|
|
185 entFilters.add(title);
|
|
186
|
|
187
|
|
188 SRelationUniqueName has_role = new SRelationUniqueName(person, role, "has_role");
|
|
189 SRelationUniqueName was_created_by = new SRelationUniqueName(title, person, "was_created_by");
|
|
190 relFilters.add(was_created_by);
|
|
191 relFilters.add(has_role);
|
|
192
|
|
193 List<ResultEntry> rs = getAppBean().getSS().search(entFilters, relFilters);
|
|
194
|
|
195 return rs;
|
|
196 }
|
|
197
|
|
198 /**
|
|
199 * 5) List of all people who had other “roles” associated with a title (e.g. copyists , owners, patrons, teachers, students, etc.)
|
|
200 * @return
|
|
201 */
|
|
202 private List<ResultEntry> sample05(){
|
|
203
|
|
204 List<SEntity> entFilters = new ArrayList<SEntity>();
|
|
205 List<SRelation> relFilters = new ArrayList<SRelation>();
|
|
206
|
|
207 SEntity role = new SEntity(0, "ROLE");
|
|
208 role.addAtt(new SAttributeMultipleValue("name", "Annotator", "Copyist", "Corrector", "Dedicatee", "Illuminator", "Illustrator", "Owner", "Patron", "inspector"));
|
|
209 entFilters.add(role);
|
|
210
|
|
211 //alias, "is_prime_alias_name_of", "PERSON"
|
|
212 //alias, "is_alias_name_of", "PERSON"
|
|
213 SEntity person = new SEntity(1, "PERSON");
|
|
214 person.addAtt(new SAttributeMultipleName("a", "name_translit", "name"));
|
|
215 entFilters.add(person);
|
|
216
|
|
217 /*
|
|
218 SEntity alias = new SEntity(1, "ALIAS");
|
|
219 alias.addAtt(new SAttributeUniqueName("alias", "abu"));
|
|
220 entFilters.add(alias);
|
|
221 */
|
|
222
|
|
223 SEntity title = new SEntity(2, "TEXT");
|
|
224 //title.addAtt(new SAttributeMultipleName("abu", "full_title_translit", "full_title"));
|
|
225 entFilters.add(title);
|
|
226
|
|
227
|
|
228 SRelationUniqueName has_role = new SRelationUniqueName(person, role, "has_role");
|
|
229 SRelationMultipleName title_to_person = new SRelationMultipleName(title, person, "had_patron", "was_dedicated_to", "was_created_by");
|
|
230 relFilters.add(title_to_person);
|
|
231 relFilters.add(has_role);
|
|
232
|
|
233 List<ResultEntry> rs = getAppBean().getSS().search(entFilters, relFilters);
|
|
234
|
|
235 return rs;
|
|
236 }
|
|
237
|
|
238 /**
|
|
239 * 6) Bring up people associated with a particular title (not just one huge list of people, but be able to distinguish author, student, teacher)
|
|
240 * @return
|
|
241 */
|
|
242 private List<ResultEntry> sample06(){
|
|
243
|
|
244 List<SEntity> entFilters = new ArrayList<SEntity>();
|
|
245 List<SRelation> relFilters = new ArrayList<SRelation>();
|
|
246
|
|
247 //The user can select between:
|
|
248 //"Author", "Annotator", "Copyist", "Corrector", "Dedicatee", "Illuminator", "Illustrator", "Owner", "Patron", "inspector"
|
|
249 SEntity role = new SEntity(0, "ROLE");
|
|
250 role.addAtt(new SAttributeUniqueName("name", "Annotator"));
|
|
251 entFilters.add(role);
|
|
252
|
|
253 //alias, "is_prime_alias_name_of", "PERSON"
|
|
254 //alias, "is_alias_name_of", "PERSON"
|
|
255 SEntity person = new SEntity(1, "PERSON");
|
|
256 person.addAtt(new SAttributeMultipleName("a", "name_translit", "name"));
|
|
257 entFilters.add(person);
|
|
258
|
|
259 /*
|
|
260 SEntity alias = new SEntity(1, "ALIAS");
|
|
261 alias.addAtt(new SAttributeUniqueName("alias", "abu"));
|
|
262 entFilters.add(alias);
|
|
263 */
|
|
264
|
|
265 SEntity title = new SEntity(2, "TEXT");
|
|
266 title.addAtt(new SAttributeMultipleName("abu", "full_title_translit", "full_title"));
|
|
267 entFilters.add(title);
|
|
268
|
|
269
|
|
270 SRelationUniqueName has_role = new SRelationUniqueName(person, role, "has_role");
|
|
271 SRelationMultipleName title_to_person = new SRelationMultipleName(title, person, "had_patron", "was_dedicated_to", "was_created_by");
|
|
272 relFilters.add(title_to_person);
|
|
273 relFilters.add(has_role);
|
|
274
|
|
275 List<ResultEntry> rs = getAppBean().getSS().search(entFilters, relFilters);
|
|
276
|
|
277 return rs;
|
|
278
|
|
279 }
|
|
280
|
|
281 /**
|
|
282 * 7) Bring up people associated with a particular witness (not just one huge list of people, but be able to distinguish owner, say, from commentator)
|
|
283 * @return
|
|
284 */
|
|
285 private List<ResultEntry> sample07(){
|
|
286
|
|
287 List<SEntity> entFilters = new ArrayList<SEntity>();
|
|
288 List<SRelation> relFilters = new ArrayList<SRelation>();
|
|
289
|
|
290 //The user can select between:
|
|
291 //"Author", "Annotator", "Copyist", "Corrector", "Dedicatee", "Illuminator", "Illustrator", "Owner", "Patron", "inspector"
|
|
292 SEntity role = new SEntity(0, "ROLE");
|
|
293 role.addAtt(new SAttributeUniqueName("name", "Owner"));
|
|
294 entFilters.add(role);
|
|
295
|
|
296 //alias, "is_prime_alias_name_of", "PERSON"
|
|
297 //alias, "is_alias_name_of", "PERSON"
|
|
298 SEntity person = new SEntity(1, "PERSON");
|
|
299 person.addAtt(new SAttributeMultipleName("a", "name_translit", "name"));
|
|
300 entFilters.add(person);
|
|
301
|
|
302 /*
|
|
303 SEntity alias = new SEntity(1, "ALIAS");
|
|
304 alias.addAtt(new SAttributeUniqueName("alias", "abu"));
|
|
305 entFilters.add(alias);
|
|
306 */
|
|
307
|
|
308 SEntity witness = new SEntity(2, "WITNESS");
|
|
309 //witness.addAtt(new SAttributeMultipleName("abu", "full_title_translit", "full_title"));
|
|
310 entFilters.add(witness);
|
|
311
|
|
312
|
|
313 SRelationUniqueName has_role = new SRelationUniqueName(person, role, "has_role");
|
|
314 SRelationMultipleName witness_to_person = new SRelationMultipleName(witness, person, "had_patron", "was_copied_by", "was_created_by", "was_studied_by");
|
|
315 relFilters.add(witness_to_person);
|
|
316 relFilters.add(has_role);
|
|
317
|
|
318 List<ResultEntry> rs = getAppBean().getSS().search(entFilters, relFilters);
|
|
319
|
|
320 return rs;
|
|
321
|
|
322 }
|
|
323
|
|
324 /**
|
|
325 * 9) Bring up all owners of a particular codex
|
|
326 * @return
|
|
327 */
|
|
328 private List<ResultEntry> sample08(){
|
|
329
|
|
330 List<SEntity> entFilters = new ArrayList<SEntity>();
|
|
331 List<SRelation> relFilters = new ArrayList<SRelation>();
|
|
332
|
|
333 //The user can select between:
|
|
334 //"Author", "Annotator", "Copyist", "Corrector", "Dedicatee", "Illuminator", "Illustrator", "Owner", "Patron", "inspector"
|
|
335 SEntity role = new SEntity(0, "ROLE");
|
|
336 role.addAtt(new SAttributeUniqueName("name", "Owner"));
|
|
337 entFilters.add(role);
|
|
338
|
|
339 //alias, "is_prime_alias_name_of", "PERSON"
|
|
340 //alias, "is_alias_name_of", "PERSON"
|
|
341 SEntity person = new SEntity(1, "PERSON");
|
|
342 person.addAtt(new SAttributeMultipleName("a", "name_translit", "name"));
|
|
343 entFilters.add(person);
|
|
344
|
|
345 /*
|
|
346 SEntity alias = new SEntity(1, "ALIAS");
|
|
347 alias.addAtt(new SAttributeUniqueName("alias", "abu"));
|
|
348 entFilters.add(alias);
|
|
349 */
|
|
350
|
|
351 SEntity codex = new SEntity(2, "CODEX");
|
|
352 //witness.addAtt(new SAttributeMultipleName("abu", "full_title_translit", "full_title"));
|
|
353 entFilters.add(codex);
|
|
354
|
|
355 SRelationUniqueName has_role = new SRelationUniqueName(person, role, "has_role");
|
|
356 SRelationUniqueName was_owned_by = new SRelationUniqueName(codex, person, "was_owned_by");
|
|
357 relFilters.add(was_owned_by);
|
|
358 relFilters.add(has_role);
|
|
359
|
|
360 List<ResultEntry> rs = getAppBean().getSS().search(entFilters, relFilters);
|
|
361
|
|
362 return rs;
|
|
363
|
|
364 }
|
|
365
|
|
366 /*
|
|
367 private void printRs(List<ResultEntry> rs){
|
|
368 logger.info("--------------");
|
|
369 for(ResultEntry entry : rs){
|
|
370 for(Entry<Integer, Long> ent : entry.getEntMap().entrySet()){
|
|
371 logger.info(ent.getKey() + ") " + getWrapper().getEntityById(ent.getValue()).toSmallString());
|
|
372 }
|
|
373 }
|
|
374 logger.info("--------------");
|
|
375 }*/
|
|
376
|
|
377 public String getCurrentTemplate() {
|
|
378 return currentTemplate;
|
|
379 }
|
|
380
|
|
381 public void setCurrentTemplate(String currentTemplate) {
|
|
382 this.currentTemplate = currentTemplate;
|
|
383 }
|
|
384
|
|
385 public List<SelectItem> getTemplateList() {
|
|
386 return templateList;
|
|
387 }
|
|
388
|
|
389 public Titles4PersonQuery getTitles4PersonQuery() {
|
|
390 return titles4PersonQuery;
|
|
391 }
|
|
392 }
|