Changeset 7188


Ignore:
Timestamp:
2004-04-06T09:26:49+12:00 (20 years ago)
Author:
cs025
Message:

Classifier fixes and improvements.

Location:
trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/classifier
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/classifier/AZListClassifier.java

    r6699 r7188  
    170170  }
    171171
    172   public int writeSQLClassifyNode(GS3SQLConnection connection, String parentId, String label, String name, String description, int noOfLeafDocs)
     172  public int writeSQLClassifyNode(GS3SQLConnection connection, String parentId, int orderRef,
     173                  String label, String name, String description, int noOfLeafDocs)
    173174  { GS3SQLAction action;
    174175    GS3SQLSelect select;
     
    210211      action.addValue("Name", name);
    211212      action.addValue("Description", description);
     213      action.addValue("ClassifyOrder", Integer.toString(orderRef), GS3SQLField.INTEGER_TYPE);
    212214      action.addValue("NumLeafDocs", Integer.toString(noOfLeafDocs), GS3SQLField.INTEGER_TYPE);
    213215
     
    262264    }
    263265
    264     int parentClassify = this.writeSQLClassifyNode(connection, "", prefix, "", "", leafCount);
     266    int parentClassify = this.writeSQLClassifyNode(connection, "", 0, prefix, "", "", leafCount);
    265267
    266268    if (parentClassify < 0)
     
    271273   
    272274    // TODO: cope with change rather than create from scratch...
    273    
     275    int nodeOrder = 1;
    274276    keys = this.alphaMap.keySet().iterator();
    275277    while (keys.hasNext()) {
     
    281283    String className = prefix + "." + key.toString();
    282284
    283     int classifyRef = this.writeSQLClassifyNode(connection, prefix, className, "", "", childDocs.size());
     285    int classifyRef = this.writeSQLClassifyNode(connection, prefix, nodeOrder, className, "", "", childDocs.size());
    284286
    285287    // note the child documents...
    286288        Iterator iterator = childDocs.iterator();
    287     int order = 1;
     289    int childOrder = 1;
    288290    while (iterator.hasNext()) {
    289291      AZDocumentItem documentItem = (AZDocumentItem) iterator.next();
     
    293295      insert.addValue("ClassifyRef", Integer.toString(classifyRef), GS3SQLField.INTEGER_TYPE);
    294296      insert.addValue("DocID", docId.toString());
    295       insert.addValue("DocOrder", Integer.toString(order), GS3SQLField.INTEGER_TYPE);     
     297      insert.addValue("DocOrder", Integer.toString(childOrder), GS3SQLField.INTEGER_TYPE);   
    296298
    297299      connection.execute(insert.toString());
    298300
    299       order ++;
    300     }
     301      childOrder ++;
     302    }
     303
     304    nodeOrder ++;
    301305      }
    302306    }
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/classifier/AbstractHierarchyNode.java

    r6506 r7188  
    296296      action.addValue("Name", this.name);
    297297      action.addValue("Description", this.descriptor);
     298      action.addValue("ClassifyOrder", this.id, GS3SQLField.INTEGER_TYPE);
    298299      action.addValue("NumLeafDocs", Integer.toString(this.noOfLeafDocs()), GS3SQLField.INTEGER_TYPE);
    299300
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/classifier/HierarchyClassifier.java

    r6496 r7188  
    22
    33import java.io.*;
     4
     5import java.net.URL;
    46
    57import java.util.List;
     
    79import java.util.Iterator;
    810
     11import org.apache.xerces.parsers.SAXParser;
    912import org.xml.sax.XMLReader;
    1013import org.xml.sax.InputSource;
     
    175178  private String           sortBy;
    176179
    177   public HierarchyClassifier(File basefile, List fields, String sortBy)
     180  public HierarchyClassifier(URL basefile, List fields, String sortBy)
    178181  {
    179182    try
    180     { XMLReader reader = XMLReaderFactory.createXMLReader();
     183      { SAXParser parser = new SAXParser();
    181184      HierarchyHandler handler = new HierarchyHandler();
     185      /*
     186      XMLReader reader = XMLReaderFactory.createXMLReader();
    182187      reader.setContentHandler(handler);
    183       reader.setErrorHandler(handler);
     188      reader.setErrorHandler(handler);*/
     189      parser.setContentHandler(handler);
    184190
    185191      // A Classifier consists of one file only - get it.
     192      /*
    186193      FileReader fileReader = new FileReader(basefile);
    187194      reader.parse(new InputSource(fileReader));
     195      */
     196      parser.parse(basefile.toString());
    188197
    189198      this.hierarchy = handler.getHierarchy();
    190199      this.fields = fields;
    191200      this.sortBy = sortBy;
     201
     202      System.out.println("Counting " + this.fields.size() + " fields");
    192203    }
    193204    catch (SAXException saxException)
    194205    { // TODO: log error
     206    System.out.println("unable to process hierarchy " + saxException.toString());
    195207    }
    196208    catch (java.io.FileNotFoundException fileException)
    197209    {
     210    System.out.println("unable to process hierarchy " + fileException.toString());
    198211    }
    199212    catch (java.io.IOException ioException)
    200213    {
     214    System.out.println("unable to process hierarchy " + ioException.toString());
    201215    }
    202216  }
     
    218232  }
    219233
     234  /**
     235   *  Indicate the database to be used for saving the hierarchy to.
     236   *
     237   *  @param <code>GS3SQLConnection</code> the database
     238   */
    220239  public void setDatabase(GS3SQLConnection database)
    221240  { this.database = database;
     
    230249   *  @param <code>DocumentID</code> the document identifier
    231250   *  @param <code>DocumentInterface</code> the document interface
     251   *
     252   *  @return <code>boolean</code> a return value - currently always
     253   *          <code>true</code> for success
    232254   */
    233255  public boolean classifyDocument(DocumentID documentID, DocumentInterface document)
    234256  { // the observer records the assignment of documents to classifications
    235257    HierarchyClassifierObserver classifyObserver = new HierarchyClassifierObserver(document);
    236        
     258
     259    // if we have no fields, there is nothing to do...
     260    if (this.fields == null)
     261    { return true;
     262    }
     263
    237264    // get the metadata item from the document
    238265    Iterator thisField = this.fields.iterator();
     
    270297  }
    271298
     299  /**
     300   *  @see ClassifierInterface:getClassifierPasses
     301   */
    272302  public int getClassifierPasses()
    273303  { return 1;
Note: See TracChangeset for help on using the changeset viewer.