Ignore:
Timestamp:
11/02/08 13:05:01 (16 years ago)
Author:
ra33
Message:
 
Location:
trunk/src/org/expeditee/greenstone
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/greenstone/Greenstone3Connection.java

    r352 r376  
    1717import java.util.Set;
    1818
    19 //import org.apache.xerces.parsers.DOMParser;
     19import org.apache.xerces.parsers.DOMParser;
    2020import org.w3c.dom.Document;
    2121import org.w3c.dom.NamedNodeMap;
     
    5353         * keys. All the results returned in this session.
    5454         */
    55         private Map allResults;
     55        private Map<String, ResultDocument> allResults;
    5656
    5757        /**
     
    156156                }
    157157                this.queryList = Collections.synchronizedList(new ArrayList());
    158                 this.allResults = Collections.synchronizedMap(new HashMap());
     158                this.allResults = Collections
     159                                .synchronizedMap(new HashMap<String, ResultDocument>());
    159160                this.allKeywords = Collections.synchronizedMap(new HashMap());
    160161                this.allAuthors = Collections.synchronizedMap(new HashMap());
     
    164165        }
    165166
    166         public Map getSessionResults() {
     167        public Map<String, ResultDocument> getSessionResults() {
    167168                return this.allResults;
    168169        };
     
    270271                while (iter.hasNext()) {
    271272                        String docID = (String) iter.next();
    272                         ResultDocument resultDocument = (ResultDocument) allResults
    273                                         .get(docID);
     273                        ResultDocument resultDocument = allResults.get(docID);
    274274                        System.out.println("____________" + docID + " ___________");
    275275                        System.out.println(resultDocument.toString());
     
    286286                while (iter.hasNext()) {
    287287                        String docID = (String) iter.next();
    288                         ResultDocument resultDocument = (ResultDocument) allResults
    289                                         .get(docID);
     288                        ResultDocument resultDocument = allResults.get(docID);
    290289                        System.out.println(docID + "\t" + resultDocument.getTitle());
    291290                }
     
    305304         */
    306305        public ResultDocument getDocument(String docID) {
    307                 return (ResultDocument) allResults.get(docID);
     306                return allResults.get(docID);
    308307        }
    309308
     
    425424                StringReader sr = new StringReader(result);
    426425                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;
    499485        }
    500486
     
    545531         */
    546532        public void getDocumentMetadataFromServer(String docID, String metadata) {
    547                 ResultDocument resultDocument = (ResultDocument) allResults.get(docID);
     533                ResultDocument resultDocument = allResults.get(docID);
    548534                if (resultDocument.metadataExists(metadata)) {
    549535                        return;
     
    566552                StringReader sr = new StringReader(result);
    567553                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);
    571557                } catch (SAXException se) {
    572558                        System.err.println(se);
    573559                } catch (IOException ioe) {
    574560                        System.err.println(ioe);
    575                 }*/
    576                 //Document d = p.getDocument();
    577                 Document d = null;
     561                }
     562                Document d = p.getDocument();
    578563                NodeList metadataList = d.getElementsByTagName("metadata");
    579564                String metadataval = null;
     
    609594                                        String s = authors[i] + ", " + authors[i + 1];
    610595
    611                                         //Handle names with jr. in them
     596                                        // Handle names with jr. in them
    612597                                        if (containsExtraName) {
    613598                                                if (i + 2 < authors.length
     
    703688                StringReader sr = new StringReader(result);
    704689                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                }
    713698
    714699                String returnName = null;
    715700
    716                 //Document d = p.getDocument();
    717                 Document d = null;
     701                Document d = p.getDocument();
     702                // Document d = null;
    718703                NodeList metadataList = d.getElementsByTagName("metadata");
    719704                for (int i = 0; i < metadataList.getLength(); i++) {
     
    750735                StringReader sr = new StringReader(result);
    751736                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
    762747                NodeList childList = d.getElementsByTagName("classifierNode");
    763748                NodeList documentList = d.getElementsByTagName("documentNode");
  • trunk/src/org/expeditee/greenstone/ResultDocument.java

    r313 r376  
    3535
    3636        private Set<String> retrievedMetadata;
     37
     38        private double sessionScore;
    3739
    3840        public ResultDocument() {
     
    5052                publisher = null;
    5153                frequencyReturned = 1;
     54                sessionScore = 0;
    5255                queryContexts = new Vector<QueryContext>();
    5356                retrievedMetadata = new HashSet<String>();
     
    158161                this.retrievedMetadata.add("Publisher");
    159162        }
     163       
     164        public double getSessionScore() {
     165                return this.sessionScore;
     166        }
     167        public void setSessionScore(double s) {
     168                this.sessionScore  = s;
     169        }
    160170
    161171        public void incrementFrequencyReturned() {
     
    165175        public void addQueryContext(QueryContext queryContext) {
    166176                this.queryContexts.addElement(queryContext);
     177                if (this.frequencyReturned == 1)
     178                        this.sessionScore = Double.parseDouble(queryContext.getScore());
    167179        }
    168180
     
    170182                return authors;
    171183        }
     184       
     185        public Vector<String> getAuthor() {
     186                return getAuthors();
     187        }
    172188
    173189        public Vector<String> getKeywords() {
    174190                return keywords;
    175191        }
     192       
     193        public Vector<String> getKeyword() {
     194                return getKeywords();
     195        }
    176196
    177197        public String getTitle() {
     
    218238                return frequencyReturned;
    219239        }
    220 
    221         public Vector getQueryContexts() {
     240       
     241        public Vector<QueryContext> getQueryContexts() {
    222242                return this.queryContexts;
    223243        }
Note: See TracChangeset for help on using the changeset viewer.