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