Changeset 6517


Ignore:
Timestamp:
2004-01-15T17:00:41+13:00 (20 years ago)
Author:
kjdon
Message:

now classifiers work, and searching works, and hierarchical docs work

Location:
trunk/gsdl3/src/java/org/greenstone/gsdl3/service
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS3MGRetrieve.java

    r6304 r6517  
    122122        //ystem.out.println("translated id = "+doc_id);
    123123        }
    124         int doc_num = this.database.OID2MGNum(doc_id);
     124        if (GS3OID.isDocTop(doc_id)) {
     125        System.out.println("adding the structure bit to doc id");
     126        doc_id = GS3OID.createOID(doc_id, "1");
     127        }
     128        String doc_num = this.database.OID2MGNum(doc_id);
     129       
    125130        //long doc_num = this.gdbm_src.oid2Docnum(doc_id);
    126         //ystem.out.println("mg doc num = "+doc_num);
     131        System.out.println("mg doc num = "+doc_num);
     132        // doc nums have the index prefixed
     133        doc_num = doc_num.substring(doc_num.indexOf(".")+1);
     134        int doc_int = Integer.parseInt(doc_num);
     135        System.out.println("actual mg doc num="+doc_int);
    127136        String doc_content = "";
    128137        try {
    129           doc_content = this.mg_src.getDocument(basedir, textdir, doc_num);
     138          doc_content = this.mg_src.getDocument(basedir, textdir, doc_int);
    130139        } catch (Exception e) {
    131140          System.out.println("exception happended with mg_src.getDocument()");
    132           doc_content = "this is the content for section hash id "+ doc_id+", mg doc num "+doc_num+"\n";
     141          doc_content = "this is the content for section hash id "+ doc_id+", mg doc num "+doc_int+"\n";
    133142        }
    134143        //ystem.out.println("Doc content: " + doc_content + "|");
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS3MGSearch.java

    r6304 r6517  
    140140    for (int d = 0; d < docs.size(); d++) {
    141141        long docnum = ((MGDocInfo) docs.elementAt(d)).num_;
    142         String doc_id = database.MGNum2OID((int)docnum);
     142        String mg_id = index+"."+docnum;
     143        String doc_id = database.MGNum2OID(mg_id);
    143144        //String doc_id = this.gdbm_src.docnum2Oid(docnum);
    144145        Element doc_node = createDocumentNodeElement(doc_id);
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS3Retrieve.java

    r6358 r6517  
    9999    dsr_service.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_RETRIEVE);
    100100    dsr_service.setAttribute(GSXML.NAME_ATT, DOCUMENT_STRUCTURE_RETRIEVE_SERVICE);
    101     //this.short_service_info.appendChild(dsr_service);
     101    this.short_service_info.appendChild(dsr_service);
    102102
    103103    Element dmr_service = this.doc.createElement(GSXML.SERVICE_ELEM);
     
    342342       
    343343        node = this.doc.createElement(GSXML.DOC_NODE_ELEM);
    344         node.setAttribute(GSXML.DOC_TYPE_ATT, "simple");
    345 
    346 //          String top_id = OID.getTop(node_id);
     344        node.setAttribute(GSXML.DOC_TYPE_ATT, "hierarchy"); // need to work this out dynamically
     345
     346        if (GS3OID.isTop(node_id)) {
     347        node.setAttribute(GSXML.NODE_TYPE_ATT, GSXML.NODE_TYPE_ROOT);
     348        } else if (database.documentHasChildren(node_id)){
     349        node.setAttribute(GSXML.NODE_TYPE_ATT, GSXML.NODE_TYPE_INTERIOR);
     350        } else {
     351        node.setAttribute(GSXML.NODE_TYPE_ATT, GSXML.NODE_TYPE_LEAF);
     352        }
     353//          String top_id = GS3OID.getTop(node_id);
    347354//          boolean is_top = (top_id.equals(node_id) ? true : false);
    348355   
     
    385392    protected Element getParent(String doc_id)
    386393    {
    387     String parent_id = OID.getParent(doc_id);
     394    String parent_id = GS3OID.getParent(doc_id);
    388395    if (parent_id.equals(doc_id))
    389396        return null;
     
    398405                  int type, boolean recursive)
    399406    {
     407   
    400408    if (type == DOCUMENT) {
    401         return;
    402     }
    403     if (type == CLASSIFIER) {
     409        ArrayList children = database.getDocumentChildren(doc_id);
     410        if (children == null) return;
     411        for (int i=0; i<children.size(); i++) {
     412        String child_id = (String) children.get(i);
     413        Element child = createDocNode(child_id, false, true);
     414        doc.appendChild(child);
     415        // Apply recursively, if desired
     416        if (recursive) {
     417            addDescendants(child, child_id, type, recursive);
     418        }
     419        }
     420       
     421    }
     422    else if (type == CLASSIFIER) {
    404423        ArrayList documents = database.getClassifierDocChildren(doc_id);
    405424        for (int i=0; i<documents.size(); i++) {
     
    423442
    424443    /** adds all the siblings of current_id to the parent element. */
    425 //      protected Element addSiblings(Element parent, String parent_id, String current_id) {
    426 //      Element current_node = (Element)parent.getFirstChild();
    427 //      if (current_node ==null) {
    428 //          // create a sensible error message
    429 //          System.err.println("GS3Retrieve Error: there should be a first child.");
    430 //          return null;
    431 //      }
    432 //      // remove the current child,- will add it in later in its correct place
    433 //      parent.removeChild(current_node);
    434 
    435 //      // add in all the siblings,
    436 //      addDescendants(parent, parent_id, false);
    437 
    438 //      // find the node that is now the current node
    439 //      // this assumes that the new node that was created is the same as
    440 //      // the old one that was removed - we may want to replace the new one
    441 //      // with the old one.
    442 //      Element new_current = GSXML.getNamedElement(parent, current_node.getNodeName(), GSXML.NODE_ID_ATT, current_id);
    443 //      return new_current;
    444 
    445 //      }
     444    protected Element addSiblings(Element parent, String parent_id, String current_id) {
     445    Element current_node = (Element)parent.getFirstChild();
     446    if (current_node ==null) {
     447        // create a sensible error message
     448        System.err.println("GS3Retrieve Error: there should be a first child.");
     449        return null;
     450    }
     451    // remove the current child,- will add it in later in its correct place
     452    parent.removeChild(current_node);
     453
     454    // add in all the siblings,
     455    addDescendants(parent, parent_id, DOCUMENT, false);
     456
     457    // find the node that is now the current node
     458    // this assumes that the new node that was created is the same as
     459    // the old one that was removed - we may want to replace the new one
     460    // with the old one.
     461    Element new_current = GSXML.getNamedElement(parent, current_node.getNodeName(), GSXML.NODE_ID_ATT, current_id);
     462    return new_current;
     463
     464    }
    446465    /** Returns true if the OID specifies a leaf node, false otherwise
    447466    Note: this makes a request to the GDBM database so it may not be
     
    462481    }
    463482
    464 //      protected Element processDocumentStructureRetrieve(Element request) {
    465 //      return genericStructureRetrieve(request, DOCUMENT);
    466 //      }
     483    protected Element processDocumentStructureRetrieve(Element request) {
     484    return genericStructureRetrieve(request, DOCUMENT);
     485    }
    467486
    468487    protected Element processClassifierBrowse(Element request) {
     
    565584        String doc_id = doc_ids[i];
    566585       
    567         if (OID.needsTranslating(doc_id)) {
     586        if (GS3OID.needsTranslating(doc_id)) {
    568587        doc_id = translateOID(doc_id);
    569588        }
    570 
     589        if (type==DOCUMENT && GS3OID.isDocTop(doc_id)) {
     590        doc_id = GS3OID.createOID(doc_id, "1");
     591        }
    571592        // Add the document to the list
    572593        Element doc = this.doc.createElement(node_name);
     
    593614        doc.appendChild(structure_elem);
    594615       
    595 //          if (want_entire_structure) {
    596 //              String top_id = OID.getTop(doc_id);
    597 //              Element top_node = createDocNode(top_id, true, false);
    598 //              addDescendants(top_node, top_id, true);
    599 //              structure_elem.appendChild(top_node);
    600 //              continue; // with the next document, we dont need to do any more here
    601 //          }
     616        if (want_entire_structure) {
     617            String top_id = GS3OID.getTop(doc_id);
     618            Element top_node = createDocNode(top_id, true, false);
     619            addDescendants(top_node, top_id, type, true);
     620            structure_elem.appendChild(top_node);
     621            continue; // with the next document, we dont need to do any more here
     622        }
    602623       
    603624        // Add the requested structure information
     
    632653       
    633654        //Siblings: get the other descendants of the selected node's parent
    634 //          if (want_siblings) {
    635 //              Element parent = (Element)current.getParentNode(); // this may be the structure element if there has been no request for parents or ancestors
    636 //              String parent_id = OID.getParent(doc_id);
     655        if (want_siblings) {
     656            Element parent = (Element)current.getParentNode(); // this may be the structure element if there has been no request for parents or ancestors
     657            String parent_id = GS3OID.getParent(doc_id);
    637658           
    638 //              // add siblings, - returns a pointer to the new current node
    639 //              current = addSiblings(parent, parent_id, doc_id);
    640 //          }
     659            // add siblings, - returns a pointer to the new current node
     660            current = addSiblings(parent, parent_id, doc_id);
     661        }
    641662       
    642663        // Children: get the descendants, but only one level deep
     
    720741        String node_id = request_node.getAttribute(GSXML.NODE_ID_ATT);
    721742
    722         if (OID.needsTranslating(node_id)) {
     743        if (GS3OID.needsTranslating(node_id)) {
    723744        //node_id = this.gdbm_src.translateOID(node_id);
    724745        node_id = translateOID(node_id);
     
    786807//      String relation_id = "";
    787808//      if (relation.equals("root")) {
    788 //          relation_id = OID.getTop(node_id);
     809//          relation_id = GS3OID.getTop(node_id);
    789810//      } else {
    790 //          relation_id = OID.getParent(node_id);
     811//          relation_id = GS3OID.getParent(node_id);
    791812//      }
    792813   
     
    818839//      value.append(relation_info.getInfo(new_meta));
    819840//      String current_id = relation_id;
    820 //      relation_id = OID.getParent(current_id);
     841//      relation_id = GS3OID.getParent(current_id);
    821842//      while (!relation_id.equals(current_id)) {
    822843//          relation_info = this.gdbm_src.getInfo(relation_id);
     
    826847       
    827848//          current_id = relation_id;
    828 //          relation_id = OID.getParent(current_id);
     849//          relation_id = GS3OID.getParent(current_id);
    829850//      }
    830851   
     
    838859//      protected String resolveImages(String doc_content, String doc_id)
    839860//      {
    840 //      String top_doc_id = OID.getTop(doc_id);
     861//      String top_doc_id = GS3OID.getTop(doc_id);
    841862//      DBInfo info = this.gdbm_src.getInfo(top_doc_id);
    842863//      String archivedir = info.getInfo("archivedir");
     
    852873//      String value="";
    853874//      if (info_type.equals(INFO_NUM_SIBS)) {
    854 //          String parent_id = OID.getParent(doc_id);
     875//          String parent_id = GS3OID.getParent(doc_id);
    855876//          if (parent_id.equals(doc_id)) {
    856877//          value="0";
     
    861882//          value = String.valueOf(getNumChildren(doc_id));
    862883//      } else if (info_type.equals(INFO_SIB_POS)) {
    863 //          String parent_id = OID.getParent(doc_id);
     884//          String parent_id = GS3OID.getParent(doc_id);
    864885//          if (parent_id.equals(doc_id)) {
    865886//          value="-1";
     
    907928    String suff = oid.substring(p+1);
    908929    if (suff.equals("pr")) {
    909         return OID.getParent(top);
     930        return GS3OID.getParent(top);
    910931    } else if (suff.equals("rt")) {
    911         return OID.getTop(top);
     932        return GS3OID.getTop(top);
    912933    }
    913934    return oid;
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/service/GS3Search.java

    r6304 r6517  
    260260    boolean is_top = (top_id.equals(node_id) ? true : false);
    261261   
    262     doc_node.setAttribute(GSXML.DOC_TYPE_ATT, "simple");
     262    doc_node.setAttribute(GSXML.DOC_TYPE_ATT, "hierarchy");
     263
     264    if (GS3OID.isTop(node_id)) {
     265        doc_node.setAttribute(GSXML.NODE_TYPE_ATT, GSXML.NODE_TYPE_ROOT);
     266    } else if (database.documentHasChildren(node_id)){
     267        doc_node.setAttribute(GSXML.NODE_TYPE_ATT, GSXML.NODE_TYPE_INTERIOR);
     268    } else {
     269        doc_node.setAttribute(GSXML.NODE_TYPE_ATT, GSXML.NODE_TYPE_LEAF);
     270    }
     271   
    263272    return doc_node;
    264273    }
Note: See TracChangeset for help on using the changeset viewer.