1 | package org.greenstone.gsdl3_extension.mat.servlet;
|
---|
2 |
|
---|
3 |
|
---|
4 | import org.w3c.dom.*;
|
---|
5 | import javax.xml.parsers.*;
|
---|
6 | import javax.xml.transform.*;
|
---|
7 | import javax.xml.transform.dom.*;
|
---|
8 | import javax.xml.transform.stream.*;
|
---|
9 |
|
---|
10 |
|
---|
11 | import java.io.BufferedWriter;
|
---|
12 | import java.io.File;
|
---|
13 | import java.io.FileOutputStream;
|
---|
14 | import java.io.OutputStreamWriter;
|
---|
15 | import java.io.PrintWriter;
|
---|
16 | import java.io.Writer;
|
---|
17 |
|
---|
18 | import java.util.ArrayList;
|
---|
19 | import java.util.Collection;
|
---|
20 | import java.util.HashMap;
|
---|
21 | import java.util.Iterator;
|
---|
22 | import java.util.Set;
|
---|
23 | import java.util.StringTokenizer;
|
---|
24 |
|
---|
25 | import org.greenstone.gsdl3.core.MessageRouter;
|
---|
26 | import org.greenstone.gsdl3.util.GDBMWrapper;
|
---|
27 | import org.greenstone.gsdl3.util.GSFile;
|
---|
28 | import org.greenstone.gsdl3.util.GSXML;
|
---|
29 | import org.greenstone.gsdl3.util.GlobalProperties;
|
---|
30 | import org.greenstone.gsdl3.util.XMLConverter;
|
---|
31 | import org.greenstone.gsdl3.util.GSPath;
|
---|
32 |
|
---|
33 | import org.w3c.dom.Document;
|
---|
34 | import org.w3c.dom.Element;
|
---|
35 | import org.w3c.dom.NamedNodeMap;
|
---|
36 | import org.w3c.dom.Node;
|
---|
37 | import org.w3c.dom.NodeList;
|
---|
38 |
|
---|
39 |
|
---|
40 | public class MetadataStats {
|
---|
41 |
|
---|
42 | private Document doc=null;
|
---|
43 | private MessageRouter mr = null;
|
---|
44 | private XMLConverter converter=null;
|
---|
45 | private GDBMWrapper gdbm_src = null;
|
---|
46 | private GSPath gspath = null;
|
---|
47 | private GlobalProperties globalProperty = null;
|
---|
48 | private String site_name = "localsite";
|
---|
49 | //private String node_id = "browselist";
|
---|
50 | private String DLS_SET = "dls";
|
---|
51 | private String DC_SET = "dublin";
|
---|
52 | private String OAI_URL = "";
|
---|
53 |
|
---|
54 | private boolean status = false;
|
---|
55 |
|
---|
56 | private String oai_Prefix ="";
|
---|
57 | private PrintWriter pw;
|
---|
58 | public String StatsDirectory;
|
---|
59 | public String HTMLDirectory;
|
---|
60 |
|
---|
61 | private String destination = "";
|
---|
62 | private int TotalDoc = 0;
|
---|
63 | String linkIdentifier ="";
|
---|
64 | private HashMap MDS_list = new HashMap();
|
---|
65 | private String collection = null;
|
---|
66 | public ArrayList metadataNameList = new ArrayList();
|
---|
67 | private String collection_Name = null;
|
---|
68 |
|
---|
69 | private String DB_TYPE = "gdbm";
|
---|
70 | protected final String FrequencyNode = "Frequency";
|
---|
71 | protected final String DocumentNode = "Document";
|
---|
72 | protected final String ActualValueNode = "ActualValue";
|
---|
73 | protected final String RootDirectory = "archivedir";
|
---|
74 | protected final String FileSeparator = File.separator;
|
---|
75 |
|
---|
76 | MetadataElement me;
|
---|
77 |
|
---|
78 | private static boolean deleteDir(File dir) {
|
---|
79 | if (dir.isDirectory()) {
|
---|
80 | String[] children = dir.list();
|
---|
81 | for (int i=0; i<children.length; i++) {
|
---|
82 | boolean success = deleteDir(new File(dir, children[i]));
|
---|
83 | if (!success) {
|
---|
84 | return false;
|
---|
85 | }
|
---|
86 | }
|
---|
87 | }
|
---|
88 |
|
---|
89 | return dir.delete();
|
---|
90 | }
|
---|
91 |
|
---|
92 | public MetadataStats(String site_home, String collection,String url, PrintWriter out, String oaiPrefix){
|
---|
93 | OAI_URL = url;
|
---|
94 | collection_Name = collection;
|
---|
95 | oai_Prefix = oaiPrefix;
|
---|
96 | pw = out;
|
---|
97 |
|
---|
98 | destination = globalProperty.getGSDL3Home()+FileSeparator+"mat"+FileSeparator+collection+FileSeparator;
|
---|
99 | HTMLDirectory = destination;
|
---|
100 | StatsDirectory = HTMLDirectory+"metadataStats"+FileSeparator;
|
---|
101 |
|
---|
102 | if(new File(StatsDirectory).exists()){
|
---|
103 | deleteDir(new File(StatsDirectory));
|
---|
104 | }
|
---|
105 | new File(StatsDirectory).mkdirs();
|
---|
106 | String gdbm = GSFile.collectionDatabaseFile(site_home,collection,collection,DB_TYPE);
|
---|
107 |
|
---|
108 | mr = new MessageRouter();
|
---|
109 | mr.setSiteName(this.site_name);
|
---|
110 | mr.configure();
|
---|
111 |
|
---|
112 | this.collection = collection;
|
---|
113 | this.gdbm_src = new GDBMWrapper();
|
---|
114 | this.converter = new XMLConverter();
|
---|
115 | this.doc = this.converter.newDOM();
|
---|
116 | Setup(out, gdbm);
|
---|
117 | }
|
---|
118 |
|
---|
119 | public void getAvailableMetadataSets(String SetName,HashMap UsedMap, String SetAbbr){
|
---|
120 |
|
---|
121 |
|
---|
122 | String gsdl3Home = globalProperty.getGSDL3Home();
|
---|
123 | String metadataSetHome = gspath.removeLastLink(gsdl3Home)+FileSeparator+"gli"+FileSeparator+"metadata";
|
---|
124 | File metadata_directory = new File(metadataSetHome);
|
---|
125 |
|
---|
126 |
|
---|
127 | if (metadata_directory.exists()) {
|
---|
128 | // Load just those .mds files in this directory, and return them
|
---|
129 | File[] directory_files = metadata_directory.listFiles();
|
---|
130 |
|
---|
131 | for (int i = 0; i < directory_files.length; i++) {
|
---|
132 | File child_file = directory_files[i];
|
---|
133 |
|
---|
134 | if (!child_file.isDirectory() && child_file.getName().endsWith("mds")) {
|
---|
135 | String fileName = child_file.getName();
|
---|
136 |
|
---|
137 | /////////////////////////
|
---|
138 | //LOADING DLS CORE
|
---|
139 | //---if(fileName.equals(SetName)&& fileName.equals("dls.mds") && DLS_STATUS){
|
---|
140 | if(!MDS_list.containsKey(SetName)&& fileName.equals(SetName+".mds")){
|
---|
141 |
|
---|
142 | MetadataSet ms = new MetadataSet();
|
---|
143 | ms.setName(SetName);
|
---|
144 | ms.setAbb(SetAbbr);
|
---|
145 |
|
---|
146 | converter.newDOM();
|
---|
147 | Document d = converter.getDOM(child_file);
|
---|
148 |
|
---|
149 | NodeList e = d.getElementsByTagName("Element");
|
---|
150 |
|
---|
151 | int length = e.getLength();
|
---|
152 |
|
---|
153 | for(int y = 0; y<length; y++){
|
---|
154 | Node temp = e.item(y);
|
---|
155 | NamedNodeMap mmp = temp.getAttributes();
|
---|
156 |
|
---|
157 | if(!mmp.item(0).getNodeValue().equals("dc.Description")){
|
---|
158 | MetadataElement me = new MetadataElement();
|
---|
159 | //me.setMetadataName((SetAbbr+"."+mmp.item(0).getNodeValue().toLowerCase()));
|
---|
160 | me.setMetadataName((SetAbbr+"."+mmp.item(0).getNodeValue()));
|
---|
161 | //System.out.println(me.getMetadataName());
|
---|
162 | //.child_file............child_file
|
---|
163 | if(!metadataNameList.contains(me.getMetadataName())){
|
---|
164 | metadataNameList.add(me.getMetadataName());
|
---|
165 | ms.addIndex(me.getMetadataName());
|
---|
166 | }
|
---|
167 | UsedMap.put(me.getMetadataName(),me);
|
---|
168 | }
|
---|
169 | }
|
---|
170 | //System.out.println(ms.getName()+"loaded");
|
---|
171 | MDS_list.put(ms.getName(), ms);
|
---|
172 | //pw.write("load metadata set"+ms.getName());
|
---|
173 | //pw.flush();
|
---|
174 | //System.gc();
|
---|
175 | }// DLS FINISH
|
---|
176 | }
|
---|
177 | }
|
---|
178 | }
|
---|
179 | }
|
---|
180 |
|
---|
181 | // doc_list is the list of document ids
|
---|
182 | //MetadataElement represents which metadata element we want to explore
|
---|
183 | private void parseMetadata(ArrayList doc_list, String MetadataElement){
|
---|
184 |
|
---|
185 | //System.out.println("parse metadata starts");
|
---|
186 | int counter = 0;
|
---|
187 | //int x = 0;
|
---|
188 | int docSize = doc_list.size();
|
---|
189 |
|
---|
190 | pw.write("<!-- prepare request -->");
|
---|
191 | while(true){
|
---|
192 |
|
---|
193 | Node message = this.doc.createElement(GSXML.MESSAGE_ELEM);
|
---|
194 |
|
---|
195 | Node request = GSXML.createBasicRequest(
|
---|
196 | this.doc, GSXML.REQUEST_TYPE_PROCESS,collection+"/DocumentMetadataRetrieve","en", "");
|
---|
197 |
|
---|
198 | Node param_list = this.doc.createElement(
|
---|
199 | GSXML.PARAM_ELEM+GSXML.LIST_MODIFIER);
|
---|
200 |
|
---|
201 | param_list.appendChild(GSXML.createParameter(
|
---|
202 | this.doc, "metadata", MetadataElement));
|
---|
203 |
|
---|
204 | Node documentNode_list = this.doc.createElement(
|
---|
205 | GSXML.DOC_NODE_ELEM+GSXML.LIST_MODIFIER);
|
---|
206 |
|
---|
207 | if(docSize>=500){
|
---|
208 | docSize = docSize - 500;
|
---|
209 | for(int i = 0; i<500; i++){
|
---|
210 | Element documentNode = this.doc.createElement(GSXML.DOC_NODE_ELEM);
|
---|
211 | documentNode.setAttribute("nodeID",(String)doc_list.get(counter));
|
---|
212 | documentNode_list.appendChild(documentNode);
|
---|
213 | counter++;
|
---|
214 | }
|
---|
215 | request.appendChild(param_list);
|
---|
216 | request.appendChild(documentNode_list);
|
---|
217 | message.appendChild(request);
|
---|
218 | //System.out.println(this.converter.getPrettyString(message));
|
---|
219 | //pw.write("send request");
|
---|
220 | //pw.flush();
|
---|
221 | Node response = mr.process(message);
|
---|
222 | //pw.write("receive request");
|
---|
223 | //pw.flush();
|
---|
224 | //System.out.println(this.converter.getPrettyString(response));
|
---|
225 |
|
---|
226 | getAttributes(response);
|
---|
227 |
|
---|
228 | response = null;
|
---|
229 | request = null;
|
---|
230 | param_list = null;
|
---|
231 | documentNode_list = null;
|
---|
232 | //System.gc();
|
---|
233 | }
|
---|
234 |
|
---|
235 | else if(docSize<500){
|
---|
236 | for(int i = 0; i<docSize; i++){
|
---|
237 | Element documentNode = this.doc.createElement(GSXML.DOC_NODE_ELEM);
|
---|
238 | documentNode.setAttribute("nodeID",(String)doc_list.get(counter));
|
---|
239 | documentNode_list.appendChild(documentNode);
|
---|
240 | counter++;
|
---|
241 | }
|
---|
242 | request.appendChild(param_list);
|
---|
243 | request.appendChild(documentNode_list);
|
---|
244 | message.appendChild(request);
|
---|
245 |
|
---|
246 | //pw.write("send request");
|
---|
247 | Node response = mr.process(message);
|
---|
248 | //pw.write("receive request\n");
|
---|
249 | //pw.write(this.converter.getPrettyString(response));
|
---|
250 | //System.out.println(this.converter.getPrettyString(response));
|
---|
251 | //System.out.println(this.converter.getPrettyString(response));
|
---|
252 | getAttributes(response);
|
---|
253 | response = null;
|
---|
254 | request = null;
|
---|
255 | param_list = null;
|
---|
256 | documentNode_list = null;
|
---|
257 | //System.gc();
|
---|
258 | break;
|
---|
259 | }
|
---|
260 | }
|
---|
261 | }
|
---|
262 |
|
---|
263 | public boolean getStatus(){
|
---|
264 | return this.status;
|
---|
265 | }
|
---|
266 |
|
---|
267 |
|
---|
268 | private void Setup(PrintWriter out, String gdbm){
|
---|
269 |
|
---|
270 | if (!this.gdbm_src.openDatabase(gdbm, GDBMWrapper.READ)) {
|
---|
271 | out.println("Could not open GDBM database!");
|
---|
272 |
|
---|
273 | }
|
---|
274 |
|
---|
275 | else{
|
---|
276 |
|
---|
277 | String info = this.gdbm_src.getValue("browselist");
|
---|
278 |
|
---|
279 | if (info == null) {
|
---|
280 | System.out.println("cannot locate the list");
|
---|
281 | }
|
---|
282 | else{
|
---|
283 | if (info == null) {
|
---|
284 | System.out.println("the db does not contain any info");
|
---|
285 | }
|
---|
286 |
|
---|
287 | ArrayList children = new ArrayList();
|
---|
288 | StringTokenizer st = new StringTokenizer(info, ";");
|
---|
289 |
|
---|
290 | while (st.hasMoreTokens()) {
|
---|
291 | String part = st.nextToken(";");
|
---|
292 |
|
---|
293 | if(part.contains("<contains>")){
|
---|
294 | part = part.replace("<contains>", "");
|
---|
295 | }
|
---|
296 | else if(part.contains("<thistype>")){
|
---|
297 | int location = part.indexOf("<thistype>");
|
---|
298 | part = part.substring(0,location-1);
|
---|
299 | }
|
---|
300 | children.add(part);
|
---|
301 | }
|
---|
302 |
|
---|
303 | gdbm_src.closeDatabase();
|
---|
304 | parseMetadata(children,"all");
|
---|
305 | TotalDoc = children.size();
|
---|
306 | status = true;
|
---|
307 | }
|
---|
308 | }
|
---|
309 | }
|
---|
310 |
|
---|
311 | public void getAttributes(Node f){
|
---|
312 |
|
---|
313 | HashMap UsedMap = new HashMap();
|
---|
314 | Element e = (Element) f;
|
---|
315 | NodeList metadataNode = e.getElementsByTagName("metadata");
|
---|
316 | int length = metadataNode.getLength();
|
---|
317 |
|
---|
318 | for (int j = 0; j < length; j++){
|
---|
319 | Node aNode = metadataNode.item(j);
|
---|
320 | NamedNodeMap NodeMap = aNode.getAttributes();
|
---|
321 | Node AttributeNode = NodeMap.item(0);
|
---|
322 | String att_name = AttributeNode.getNodeValue();
|
---|
323 |
|
---|
324 | if(att_name.indexOf("dls.")!=-1){getAvailableMetadataSets(DLS_SET,UsedMap,"dls");}
|
---|
325 | else if(att_name.indexOf("dc.")!=-1){getAvailableMetadataSets(DC_SET,UsedMap,"dc");}
|
---|
326 |
|
---|
327 | }
|
---|
328 | //UsedMap = combineList(UsedMap);
|
---|
329 | adjust(UsedMap,e);
|
---|
330 | UsedMap = null;
|
---|
331 | e = null;
|
---|
332 | System.gc();
|
---|
333 | }
|
---|
334 |
|
---|
335 |
|
---|
336 | /*
|
---|
337 | * MATCH UP THE ELEMENTS FROM BOTH DOCUMENTS AND PRE-DEFINED METADATA SET
|
---|
338 | * MOVE THE ELEMENT FROM NOUSEDMAP TO USEDMAP IF THE ELEMENT HAS NOT BEEN DISCOVERED BEFORE
|
---|
339 | * INCREASE THE COUNTER ONCE THE ELEMENT IS RECONGNIZED
|
---|
340 | * CALCULATE THE TIMES OF ELEMENTS USED AND STORE IT INTO THE LIST
|
---|
341 | */
|
---|
342 |
|
---|
343 | private void adjust(HashMap UsedMap, Element response){
|
---|
344 |
|
---|
345 | pw.write("<!-- start parsing -->");
|
---|
346 | pw.flush();
|
---|
347 | //try{
|
---|
348 | String DocID;;
|
---|
349 | NodeList nList = response.getElementsByTagName("documentNode");
|
---|
350 | int length = nList.getLength();
|
---|
351 | for (int j = 0; j <length; j++){
|
---|
352 |
|
---|
353 | Node aNode = nList.item(j);
|
---|
354 | NamedNodeMap NodeMap = aNode.getAttributes();
|
---|
355 | Node AttributeNode = NodeMap.item(0);
|
---|
356 | String att_name = AttributeNode.getNodeValue();
|
---|
357 | DocID = att_name;
|
---|
358 |
|
---|
359 | NodeList childList = aNode.getChildNodes();
|
---|
360 | Node nNode = childList.item(0);
|
---|
361 | NodeList grandChildList = nNode.getChildNodes();
|
---|
362 |
|
---|
363 | int length1 = grandChildList.getLength();
|
---|
364 |
|
---|
365 | for(int e = 0; e<length1 ; e++){
|
---|
366 |
|
---|
367 | Node xNode = grandChildList.item(e);
|
---|
368 | NamedNodeMap xNodeMap = xNode.getAttributes();
|
---|
369 | Node xAttributeNode = xNodeMap.item(0);
|
---|
370 | String xatt_name = xAttributeNode.getNodeValue();
|
---|
371 |
|
---|
372 | NodeList cList = xNode.getChildNodes();
|
---|
373 |
|
---|
374 | String ActValue = cList.item(0).getNodeValue();
|
---|
375 |
|
---|
376 | //////////////
|
---|
377 | char firstchart = xatt_name.charAt(0);
|
---|
378 | //if(Character.isLetter(firstchart)
|
---|
379 | ////////////////
|
---|
380 | pw.write("<!--"+xatt_name+"-->");
|
---|
381 | pw.flush();
|
---|
382 | //System.out.println(xatt_name+" "+UsedMap.containsKey(xatt_name));
|
---|
383 |
|
---|
384 | if(xatt_name.indexOf("dc.")!=-1){
|
---|
385 | int position = xatt_name.indexOf(".");
|
---|
386 | char x = xatt_name.charAt(position+1);
|
---|
387 | x = Character.toUpperCase(x);
|
---|
388 | xatt_name = "dc."+x+xatt_name.substring(position+2);
|
---|
389 | }
|
---|
390 |
|
---|
391 | if(xatt_name.indexOf('^')!=-1){
|
---|
392 | xatt_name = xatt_name.replace('^', '.');
|
---|
393 | }
|
---|
394 |
|
---|
395 | if(UsedMap.containsKey(xatt_name)){
|
---|
396 | //pw.write("add element to list");
|
---|
397 | MetadataElement met = (MetadataElement) UsedMap.get(xatt_name);
|
---|
398 | met.IncreaseFrequency();
|
---|
399 | HashMap metadataMap = met.getMetadataList();
|
---|
400 |
|
---|
401 | if(metadataMap.containsKey(DocID)){
|
---|
402 | //pw.write("element contains ID");
|
---|
403 | DocumentInfo dc = (DocumentInfo)metadataMap.get(DocID);
|
---|
404 | dc.IncreaseFrequence();
|
---|
405 | dc.addActualValue(ActValue);
|
---|
406 | metadataMap.put(DocID, dc);
|
---|
407 | }
|
---|
408 | else{
|
---|
409 | //pw.write("element DOES NOT contain ID");
|
---|
410 | DocumentInfo dc = new DocumentInfo();
|
---|
411 | dc.IncreaseFrequence();
|
---|
412 | dc.setDocumentID(DocID);
|
---|
413 | dc.addActualValue(ActValue);
|
---|
414 | metadataMap.put(DocID, dc);
|
---|
415 | }
|
---|
416 |
|
---|
417 | HashMap valueMap = met.getValueList();
|
---|
418 | if(valueMap.containsKey(ActValue)){
|
---|
419 | Integer f = (Integer)valueMap.get(ActValue);
|
---|
420 | int fx = f.intValue();
|
---|
421 | fx++;
|
---|
422 | valueMap.put(ActValue,new Integer(fx));
|
---|
423 | }
|
---|
424 | else{
|
---|
425 | valueMap.put(ActValue, new Integer(1));
|
---|
426 | }
|
---|
427 |
|
---|
428 | }
|
---|
429 | //else if ((!UsedMap.containsKey(xatt_name)) && (xatt_name.indexOf(".")==-1) && (!xatt_name.equals("prettymd")) && (!xatt_name.equals("Description")) && (Character.isLetter(firstchart)) && (xatt_name.indexOf("-")==-1)){
|
---|
430 | else if( (!UsedMap.containsKey(xatt_name)) && xatt_name.equals(RootDirectory)){
|
---|
431 | //pw.write("NEW EX element");
|
---|
432 | String SetAbbr = "ex";
|
---|
433 | String SetName = "extracted";
|
---|
434 |
|
---|
435 | MetadataSet ms = new MetadataSet();
|
---|
436 | ms.setName(SetName);
|
---|
437 | ms.setAbb(SetAbbr);
|
---|
438 |
|
---|
439 | MetadataElement me = new MetadataElement();
|
---|
440 | me.setMetadataName(xatt_name);
|
---|
441 | me.IncreaseFrequency();
|
---|
442 | HashMap metadataMap = me.getMetadataList();
|
---|
443 |
|
---|
444 | if(metadataMap.containsKey(DocID)){
|
---|
445 | DocumentInfo dc = (DocumentInfo)metadataMap.get(DocID);
|
---|
446 | dc.IncreaseFrequence();
|
---|
447 | dc.addActualValue(ActValue);
|
---|
448 | metadataMap.put(DocID, dc);
|
---|
449 | }
|
---|
450 | else{
|
---|
451 | DocumentInfo dc = new DocumentInfo();
|
---|
452 | dc.IncreaseFrequence();
|
---|
453 | dc.setDocumentID(DocID);
|
---|
454 | dc.addActualValue(ActValue);
|
---|
455 | metadataMap.put(DocID, dc);
|
---|
456 | }
|
---|
457 |
|
---|
458 | HashMap valueMap = me.getValueList();
|
---|
459 | if(valueMap.containsKey(ActValue)){
|
---|
460 | Integer f = (Integer)valueMap.get(ActValue);
|
---|
461 | int fx = f.intValue();
|
---|
462 | fx++;
|
---|
463 | valueMap.put(ActValue,new Integer(fx));
|
---|
464 | }
|
---|
465 | else{
|
---|
466 | //System.out.println(ActValue+" doesn't already exist");
|
---|
467 | valueMap.put(ActValue, new Integer(1));
|
---|
468 | }
|
---|
469 | if(!metadataNameList.contains(me.getMetadataName())){
|
---|
470 | metadataNameList.add(me.getMetadataName());
|
---|
471 | ms.addIndex(me.getMetadataName());
|
---|
472 | }
|
---|
473 | //pw.write("adding element");
|
---|
474 | UsedMap.put(me.getMetadataName(), me);
|
---|
475 | if(!MDS_list.containsKey(ms.getName())){MDS_list.put(ms.getName(), ms);}
|
---|
476 | else{
|
---|
477 | MetadataSet msx = (MetadataSet)MDS_list.get(ms.getName());
|
---|
478 | msx.addIndex(me.getMetadataName());
|
---|
479 | MDS_list.put(ms.getName(), msx);
|
---|
480 | }
|
---|
481 | }
|
---|
482 |
|
---|
483 |
|
---|
484 | else if((!UsedMap.containsKey(xatt_name)) && xatt_name.indexOf(".")!=-1 && xatt_name.indexOf("dc.")==-1){
|
---|
485 | //pw.write("NEW EX element");
|
---|
486 | int dotLocation = xatt_name.indexOf(".");
|
---|
487 |
|
---|
488 | String SetAbbr = new String();
|
---|
489 | String SetName = new String();
|
---|
490 | if(dotLocation==0){
|
---|
491 | SetAbbr = "Other";
|
---|
492 | SetName = "Other";
|
---|
493 | }
|
---|
494 | else{
|
---|
495 | SetAbbr = xatt_name.substring(0,dotLocation);
|
---|
496 | SetName = SetAbbr;
|
---|
497 | }
|
---|
498 | MetadataSet ms = new MetadataSet();
|
---|
499 | ms.setName(SetName);
|
---|
500 | ms.setAbb(SetAbbr);
|
---|
501 |
|
---|
502 | MetadataElement me = new MetadataElement();
|
---|
503 | me.setMetadataName(xatt_name);
|
---|
504 | me.IncreaseFrequency();
|
---|
505 | HashMap metadataMap = me.getMetadataList();
|
---|
506 |
|
---|
507 | if(metadataMap.containsKey(DocID)){
|
---|
508 | DocumentInfo dc = (DocumentInfo)metadataMap.get(DocID);
|
---|
509 | dc.IncreaseFrequence();
|
---|
510 | dc.addActualValue(ActValue);
|
---|
511 | metadataMap.put(DocID, dc);
|
---|
512 | }
|
---|
513 | else{
|
---|
514 | DocumentInfo dc = new DocumentInfo();
|
---|
515 | dc.IncreaseFrequence();
|
---|
516 | dc.setDocumentID(DocID);
|
---|
517 | dc.addActualValue(ActValue);
|
---|
518 | metadataMap.put(DocID, dc);
|
---|
519 | }
|
---|
520 |
|
---|
521 | HashMap valueMap = me.getValueList();
|
---|
522 | if(valueMap.containsKey(ActValue)){
|
---|
523 | Integer f = (Integer)valueMap.get(ActValue);
|
---|
524 | int fx = f.intValue();
|
---|
525 | fx++;
|
---|
526 | valueMap.put(ActValue,new Integer(fx));
|
---|
527 | }
|
---|
528 | else{
|
---|
529 | //System.out.println(ActValue+" doesn't already exist");
|
---|
530 | valueMap.put(ActValue, new Integer(1));
|
---|
531 | }
|
---|
532 | if(!metadataNameList.contains(me.getMetadataName())){
|
---|
533 | metadataNameList.add(me.getMetadataName());
|
---|
534 | ms.addIndex(me.getMetadataName());
|
---|
535 | }
|
---|
536 | //pw.write("adding element");
|
---|
537 | UsedMap.put(me.getMetadataName(), me);
|
---|
538 | if(!MDS_list.containsKey(ms.getName())){MDS_list.put(ms.getName(), ms);}
|
---|
539 | else{
|
---|
540 | MetadataSet msx = (MetadataSet)MDS_list.get(ms.getName());
|
---|
541 | msx.addIndex(me.getMetadataName());
|
---|
542 | MDS_list.put(ms.getName(), msx);
|
---|
543 | }
|
---|
544 | }
|
---|
545 |
|
---|
546 | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
---|
547 | else if ((!UsedMap.containsKey(xatt_name)) && (xatt_name.indexOf("dc.")==0) && xatt_name.indexOf("dc.Description")!=0){
|
---|
548 |
|
---|
549 | //pw.write("QUALIFIED DC element");
|
---|
550 |
|
---|
551 | String SetName = "dublin";
|
---|
552 | xatt_name = xatt_name.replace('^', '.');
|
---|
553 |
|
---|
554 | MetadataElement me = new MetadataElement();
|
---|
555 | me.setMetadataName(xatt_name);
|
---|
556 | me.IncreaseFrequency();
|
---|
557 | HashMap metadataMap = me.getMetadataList();
|
---|
558 |
|
---|
559 | DocumentInfo dc = new DocumentInfo();
|
---|
560 | dc.IncreaseFrequence();
|
---|
561 | dc.setDocumentID(DocID);
|
---|
562 | dc.addActualValue(ActValue);
|
---|
563 | metadataMap.put(DocID, dc);
|
---|
564 |
|
---|
565 | HashMap valueMap = me.getValueList();
|
---|
566 | valueMap.put(ActValue, new Integer(1));
|
---|
567 |
|
---|
568 | if(!metadataNameList.contains(me.getMetadataName())){
|
---|
569 | metadataNameList.add(me.getMetadataName());
|
---|
570 | }
|
---|
571 |
|
---|
572 | //pw.write("adding element");
|
---|
573 | UsedMap.put(me.getMetadataName(), me);
|
---|
574 |
|
---|
575 | MetadataSet msx = (MetadataSet)MDS_list.get(SetName);
|
---|
576 | msx.addIndex(me.getMetadataName());
|
---|
577 | MDS_list.put(SetName, msx);
|
---|
578 | }
|
---|
579 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
---|
580 | }// element
|
---|
581 |
|
---|
582 | }//doc id
|
---|
583 | ////////////////////
|
---|
584 | //write file
|
---|
585 | int counter = 0;
|
---|
586 | //System.out.println("write");
|
---|
587 | //pw.write("write files" + UsedMap.size()+ metadataNameList.size() );
|
---|
588 | //pw.flush();
|
---|
589 |
|
---|
590 | Set s = UsedMap.keySet();
|
---|
591 | Iterator is = s.iterator();
|
---|
592 | //System.out.println(UsedMap.size());
|
---|
593 | while(is.hasNext()){
|
---|
594 |
|
---|
595 | String fileName = (String)is.next();
|
---|
596 | MetadataElement me = (MetadataElement)UsedMap.get(fileName);
|
---|
597 | HashMap hp = me.getMetadataList();
|
---|
598 | Collection ks = hp.values();
|
---|
599 | Iterator iks = ks.iterator();
|
---|
600 |
|
---|
601 | try{
|
---|
602 |
|
---|
603 | DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
|
---|
604 | DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
|
---|
605 | Document doc = docBuilder.newDocument();
|
---|
606 | Element root = doc.createElement("root");
|
---|
607 | boolean fileExist = (new File(StatsDirectory+fileName+".xml")).exists();
|
---|
608 |
|
---|
609 | if(!fileExist){
|
---|
610 | root = doc.createElement("root");
|
---|
611 | }
|
---|
612 | else{
|
---|
613 | doc = docBuilder.parse (new File(StatsDirectory+fileName+".xml"));
|
---|
614 | root = doc.getDocumentElement();
|
---|
615 | }
|
---|
616 |
|
---|
617 | while(iks.hasNext()){
|
---|
618 |
|
---|
619 | DocumentInfo dc = (DocumentInfo)iks.next();
|
---|
620 | Element docID = doc.createElement(DocumentNode);
|
---|
621 | docID.setAttribute("id", dc.getDocumentID());
|
---|
622 | //pw.write("doc id"+dc.getDocumentID());
|
---|
623 |
|
---|
624 | Element freq = doc.createElement(FrequencyNode);
|
---|
625 | Text text = doc.createTextNode(dc.getFrequence()+"");
|
---|
626 | freq.appendChild(text);
|
---|
627 | docID.appendChild(freq);
|
---|
628 |
|
---|
629 | Element actValue = doc.createElement(ActualValueNode);
|
---|
630 | ArrayList alist = dc.getActualValue();
|
---|
631 | if(alist.size()==0){
|
---|
632 | text = doc.createTextNode(" ");
|
---|
633 | actValue = doc.createElement(ActualValueNode);
|
---|
634 | actValue.appendChild(text);
|
---|
635 | docID.appendChild(actValue);
|
---|
636 | }
|
---|
637 |
|
---|
638 | for(int i = 0; i<alist.size(); i++){
|
---|
639 | actValue = doc.createElement(ActualValueNode);
|
---|
640 | String utf8String = new String(((String)alist.get(i)).getBytes(),"UTF-8");
|
---|
641 | Text text1 = doc.createTextNode(utf8String);
|
---|
642 | actValue.appendChild(text1);
|
---|
643 | docID.appendChild(actValue);
|
---|
644 | }
|
---|
645 |
|
---|
646 | root.appendChild(docID);
|
---|
647 | docID = null;
|
---|
648 | counter++;
|
---|
649 | }
|
---|
650 |
|
---|
651 | TransformerFactory tf=TransformerFactory.newInstance();
|
---|
652 | Transformer transformer=tf.newTransformer();
|
---|
653 | DOMSource source= new DOMSource(root);
|
---|
654 | transformer.setOutputProperty(OutputKeys.INDENT,"yes");
|
---|
655 |
|
---|
656 | Writer pwx= new BufferedWriter(new OutputStreamWriter(new FileOutputStream(StatsDirectory+fileName+".xml"),"UTF-8"));
|
---|
657 | StreamResult result= new StreamResult(pwx);
|
---|
658 | transformer.transform(source,result);
|
---|
659 | pwx.close();
|
---|
660 |
|
---|
661 | root = null;
|
---|
662 | docBuilderFactory = null;
|
---|
663 | docBuilder = null;
|
---|
664 | doc = null;
|
---|
665 |
|
---|
666 | }catch (Exception e) {
|
---|
667 | e.printStackTrace(pw);
|
---|
668 | }
|
---|
669 | }
|
---|
670 | }
|
---|
671 |
|
---|
672 | public int getDocNum(){
|
---|
673 | return TotalDoc;
|
---|
674 | }
|
---|
675 |
|
---|
676 | public HashMap getMetadataSetMap(){
|
---|
677 | MDS_list.remove("extracted");
|
---|
678 | return (HashMap)MDS_list.clone();
|
---|
679 | }
|
---|
680 |
|
---|
681 | public String getCollectionName(){
|
---|
682 | return collection_Name;
|
---|
683 | }
|
---|
684 |
|
---|
685 | public void setOAIURL(String url){
|
---|
686 | OAI_URL = url;
|
---|
687 | }
|
---|
688 |
|
---|
689 | public String getOAIURL(){
|
---|
690 | return OAI_URL;
|
---|
691 | }
|
---|
692 |
|
---|
693 | public String getOaiPrefix(){
|
---|
694 | return oai_Prefix;
|
---|
695 | }
|
---|
696 |
|
---|
697 | public ArrayList getMetadataNameList(){
|
---|
698 | return (ArrayList)metadataNameList.clone();
|
---|
699 | }
|
---|
700 | private String constructUpdateMessgae (){
|
---|
701 | String message = "<message><request type='system' to=''><system type='configure' subset=''/></request></message>";
|
---|
702 | return message;
|
---|
703 | }
|
---|
704 | public String getIdendifier(){
|
---|
705 | return linkIdentifier;
|
---|
706 | }
|
---|
707 | }
|
---|