Changeset 376 for trunk/src/org/expeditee/greenstone
- Timestamp:
- 11/02/08 13:05:01 (16 years ago)
- Location:
- trunk/src/org/expeditee/greenstone
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/greenstone/Greenstone3Connection.java
r352 r376 17 17 import java.util.Set; 18 18 19 //import org.apache.xerces.parsers.DOMParser;19 import org.apache.xerces.parsers.DOMParser; 20 20 import org.w3c.dom.Document; 21 21 import org.w3c.dom.NamedNodeMap; … … 53 53 * keys. All the results returned in this session. 54 54 */ 55 private Map allResults;55 private Map<String, ResultDocument> allResults; 56 56 57 57 /** … … 156 156 } 157 157 this.queryList = Collections.synchronizedList(new ArrayList()); 158 this.allResults = Collections.synchronizedMap(new HashMap()); 158 this.allResults = Collections 159 .synchronizedMap(new HashMap<String, ResultDocument>()); 159 160 this.allKeywords = Collections.synchronizedMap(new HashMap()); 160 161 this.allAuthors = Collections.synchronizedMap(new HashMap()); … … 164 165 } 165 166 166 public Map getSessionResults() {167 public Map<String, ResultDocument> getSessionResults() { 167 168 return this.allResults; 168 169 }; … … 270 271 while (iter.hasNext()) { 271 272 String docID = (String) iter.next(); 272 ResultDocument resultDocument = (ResultDocument) allResults 273 .get(docID); 273 ResultDocument resultDocument = allResults.get(docID); 274 274 System.out.println("____________" + docID + " ___________"); 275 275 System.out.println(resultDocument.toString()); … … 286 286 while (iter.hasNext()) { 287 287 String docID = (String) iter.next(); 288 ResultDocument resultDocument = (ResultDocument) allResults 289 .get(docID); 288 ResultDocument resultDocument = allResults.get(docID); 290 289 System.out.println(docID + "\t" + resultDocument.getTitle()); 291 290 } … … 305 304 */ 306 305 public ResultDocument getDocument(String docID) { 307 return (ResultDocument)allResults.get(docID);306 return allResults.get(docID); 308 307 } 309 308 … … 425 424 StringReader sr = new StringReader(result); 426 425 InputSource is = new InputSource(sr); 427 428 429 430 431 432 433 434 435 436 437 return null; 438 439 // DOMParser p = new DOMParser(); 440 // 441 // try { 442 // p.parse(is); 443 // } catch (SAXException se) { 444 // System.err.println(se); 445 // } catch (IOException ioe) { 446 // System.err.println(ioe); 447 // } 448 // Document d = p.getDocument(); 449 // NodeList metadataList = d.getElementsByTagName("metadata"); 450 // for (int i = 0; i < metadataList.getLength(); i++) { 451 // Node n = metadataList.item(i); 452 // NamedNodeMap nnm = n.getAttributes(); 453 // Node att = nnm.getNamedItem("name"); 454 // if (att.getNodeValue().compareTo("numDocsMatched") == 0) { 455 // queryOutcome.setHowManyDocsMatched(n.getFirstChild() 456 // .getNodeValue()); 457 // } else if (att.getNodeValue().compareTo("numDocsReturned") == 0) { 458 // queryOutcome.setHowManyDocsReturned(n.getFirstChild() 459 // .getNodeValue()); 460 // } 461 // } 462 // 463 // NodeList documentList = d.getElementsByTagName("documentNode"); 464 // for (int i = 0; i < documentList.getLength(); i++) { 465 // Node n = documentList.item(i); 466 // NamedNodeMap nnm = n.getAttributes(); 467 // Node nid = nnm.getNamedItem("nodeID"); 468 // Node nscore = nnm.getNamedItem("rank"); 469 // String docID = nid.getFirstChild().getNodeValue(); 470 // queryOutcome.addResult(docID, firstDoc + i, nscore.getFirstChild() 471 // .getNodeValue()); 472 // } 473 // query.addQueryOutcome(queryOutcome); 474 // Query q = (Query) query.clone(); 475 // queryList.add(q); 476 // 477 // for (int i = 0; i < documentList.getLength(); i++) { 478 // Node n = documentList.item(i); 479 // NamedNodeMap nnm = n.getAttributes(); 480 // Node nid = nnm.getNamedItem("nodeID"); 481 // Node nscore = nnm.getNamedItem("rank"); 482 // String docID = nid.getFirstChild().getNodeValue(); 483 // 484 // QueryContext queryContext = new QueryContext(firstDoc + i, nscore 485 // .getFirstChild().getNodeValue(), q); 486 // if (allResults.containsKey(docID)) { 487 // ResultDocument resultDocument = (ResultDocument) allResults 488 // .get(docID); 489 // resultDocument.incrementFrequencyReturned(); 490 // resultDocument.addQueryContext(queryContext); 491 // allResults.put(docID, resultDocument); 492 // } else { 493 // ResultDocument resultDocument = new ResultDocument(); 494 // resultDocument.addQueryContext(queryContext); 495 // allResults.put(docID, resultDocument); 496 // } 497 // } 498 // return queryOutcome; 426 427 DOMParser p = new DOMParser(); 428 try { 429 p.parse(is); 430 } catch (SAXException se) { 431 System.err.println(se); 432 } catch (IOException ioe) { 433 System.err.println(ioe); 434 } 435 Document d = p.getDocument(); 436 NodeList metadataList = d.getElementsByTagName("metadata"); 437 for (int i = 0; i < metadataList.getLength(); i++) { 438 Node n = metadataList.item(i); 439 NamedNodeMap nnm = n.getAttributes(); 440 Node att = nnm.getNamedItem("name"); 441 if (att.getNodeValue().compareTo("numDocsMatched") == 0) { 442 queryOutcome.setHowManyDocsMatched(n.getFirstChild() 443 .getNodeValue()); 444 } else if (att.getNodeValue().compareTo("numDocsReturned") == 0) { 445 queryOutcome.setHowManyDocsReturned(n.getFirstChild() 446 .getNodeValue()); 447 } 448 } 449 450 NodeList documentList = d.getElementsByTagName("documentNode"); 451 for (int i = 0; i < documentList.getLength(); i++) { 452 Node n = documentList.item(i); 453 NamedNodeMap nnm = n.getAttributes(); 454 Node nid = nnm.getNamedItem("nodeID"); 455 Node nscore = nnm.getNamedItem("rank"); 456 String docID = nid.getFirstChild().getNodeValue(); 457 queryOutcome.addResult(docID, firstDoc + i, nscore.getFirstChild() 458 .getNodeValue()); 459 } 460 query.addQueryOutcome(queryOutcome); 461 Query q = (Query) query.clone(); 462 queryList.add(q); 463 464 for (int i = 0; i < documentList.getLength(); i++) { 465 Node n = documentList.item(i); 466 NamedNodeMap nnm = n.getAttributes(); 467 Node nid = nnm.getNamedItem("nodeID"); 468 Node nscore = nnm.getNamedItem("rank"); 469 String docID = nid.getFirstChild().getNodeValue(); 470 471 QueryContext queryContext = new QueryContext(firstDoc + i, nscore 472 .getFirstChild().getNodeValue(), q); 473 if (allResults.containsKey(docID)) { 474 ResultDocument resultDocument = allResults.get(docID); 475 resultDocument.incrementFrequencyReturned(); 476 resultDocument.addQueryContext(queryContext); 477 allResults.put(docID, resultDocument); 478 } else { 479 ResultDocument resultDocument = new ResultDocument(); 480 resultDocument.addQueryContext(queryContext); 481 allResults.put(docID, resultDocument); 482 } 483 } 484 return queryOutcome; 499 485 } 500 486 … … 545 531 */ 546 532 public void getDocumentMetadataFromServer(String docID, String metadata) { 547 ResultDocument resultDocument = (ResultDocument)allResults.get(docID);533 ResultDocument resultDocument = allResults.get(docID); 548 534 if (resultDocument.metadataExists(metadata)) { 549 535 return; … … 566 552 StringReader sr = new StringReader(result); 567 553 InputSource is = new InputSource(sr); 568 //DOMParser p = new DOMParser();569 /*try {570 //p.parse(is);554 DOMParser p = new DOMParser(); 555 try { 556 p.parse(is); 571 557 } catch (SAXException se) { 572 558 System.err.println(se); 573 559 } catch (IOException ioe) { 574 560 System.err.println(ioe); 575 }*/ 576 //Document d = p.getDocument(); 577 Document d = null; 561 } 562 Document d = p.getDocument(); 578 563 NodeList metadataList = d.getElementsByTagName("metadata"); 579 564 String metadataval = null; … … 609 594 String s = authors[i] + ", " + authors[i + 1]; 610 595 611 // Handle names with jr. in them596 // Handle names with jr. in them 612 597 if (containsExtraName) { 613 598 if (i + 2 < authors.length … … 703 688 StringReader sr = new StringReader(result); 704 689 InputSource is = new InputSource(sr); 705 //DOMParser p = new DOMParser();706 //try {707 //p.parse(is);708 //} catch (SAXException se) {709 //System.err.println(se);710 //} catch (IOException ioe) {711 //System.err.println(ioe);712 //}690 DOMParser p = new DOMParser(); 691 try { 692 p.parse(is); 693 } catch (SAXException se) { 694 System.err.println(se); 695 } catch (IOException ioe) { 696 System.err.println(ioe); 697 } 713 698 714 699 String returnName = null; 715 700 716 //Document d = p.getDocument();717 Document d = null;701 Document d = p.getDocument(); 702 // Document d = null; 718 703 NodeList metadataList = d.getElementsByTagName("metadata"); 719 704 for (int i = 0; i < metadataList.getLength(); i++) { … … 750 735 StringReader sr = new StringReader(result); 751 736 InputSource is = new InputSource(sr); 752 //DOMParser p = new DOMParser();753 //try {754 //p.parse(is);755 //} catch (SAXException se) {756 //System.err.println(se);757 //} catch (IOException ioe) {758 //System.err.println(ioe);759 //}760 //Document d = p.getDocument();761 Document d = null; 737 DOMParser p = new DOMParser(); 738 try { 739 p.parse(is); 740 } catch (SAXException se) { 741 System.err.println(se); 742 } catch (IOException ioe) { 743 System.err.println(ioe); 744 } 745 Document d = p.getDocument(); 746 762 747 NodeList childList = d.getElementsByTagName("classifierNode"); 763 748 NodeList documentList = d.getElementsByTagName("documentNode"); -
trunk/src/org/expeditee/greenstone/ResultDocument.java
r313 r376 35 35 36 36 private Set<String> retrievedMetadata; 37 38 private double sessionScore; 37 39 38 40 public ResultDocument() { … … 50 52 publisher = null; 51 53 frequencyReturned = 1; 54 sessionScore = 0; 52 55 queryContexts = new Vector<QueryContext>(); 53 56 retrievedMetadata = new HashSet<String>(); … … 158 161 this.retrievedMetadata.add("Publisher"); 159 162 } 163 164 public double getSessionScore() { 165 return this.sessionScore; 166 } 167 public void setSessionScore(double s) { 168 this.sessionScore = s; 169 } 160 170 161 171 public void incrementFrequencyReturned() { … … 165 175 public void addQueryContext(QueryContext queryContext) { 166 176 this.queryContexts.addElement(queryContext); 177 if (this.frequencyReturned == 1) 178 this.sessionScore = Double.parseDouble(queryContext.getScore()); 167 179 } 168 180 … … 170 182 return authors; 171 183 } 184 185 public Vector<String> getAuthor() { 186 return getAuthors(); 187 } 172 188 173 189 public Vector<String> getKeywords() { 174 190 return keywords; 175 191 } 192 193 public Vector<String> getKeyword() { 194 return getKeywords(); 195 } 176 196 177 197 public String getTitle() { … … 218 238 return frequencyReturned; 219 239 } 220 221 public Vector getQueryContexts() {240 241 public Vector<QueryContext> getQueryContexts() { 222 242 return this.queryContexts; 223 243 }
Note:
See TracChangeset
for help on using the changeset viewer.