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