Changeset 7188
- Timestamp:
- 2004-04-06T09:26:49+12:00 (20 years ago)
- 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 170 170 } 171 171 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) 173 174 { GS3SQLAction action; 174 175 GS3SQLSelect select; … … 210 211 action.addValue("Name", name); 211 212 action.addValue("Description", description); 213 action.addValue("ClassifyOrder", Integer.toString(orderRef), GS3SQLField.INTEGER_TYPE); 212 214 action.addValue("NumLeafDocs", Integer.toString(noOfLeafDocs), GS3SQLField.INTEGER_TYPE); 213 215 … … 262 264 } 263 265 264 int parentClassify = this.writeSQLClassifyNode(connection, "", prefix, "", "", leafCount);266 int parentClassify = this.writeSQLClassifyNode(connection, "", 0, prefix, "", "", leafCount); 265 267 266 268 if (parentClassify < 0) … … 271 273 272 274 // TODO: cope with change rather than create from scratch... 273 275 int nodeOrder = 1; 274 276 keys = this.alphaMap.keySet().iterator(); 275 277 while (keys.hasNext()) { … … 281 283 String className = prefix + "." + key.toString(); 282 284 283 int classifyRef = this.writeSQLClassifyNode(connection, prefix, className, "", "", childDocs.size());285 int classifyRef = this.writeSQLClassifyNode(connection, prefix, nodeOrder, className, "", "", childDocs.size()); 284 286 285 287 // note the child documents... 286 288 Iterator iterator = childDocs.iterator(); 287 int order = 1;289 int childOrder = 1; 288 290 while (iterator.hasNext()) { 289 291 AZDocumentItem documentItem = (AZDocumentItem) iterator.next(); … … 293 295 insert.addValue("ClassifyRef", Integer.toString(classifyRef), GS3SQLField.INTEGER_TYPE); 294 296 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); 296 298 297 299 connection.execute(insert.toString()); 298 300 299 order ++; 300 } 301 childOrder ++; 302 } 303 304 nodeOrder ++; 301 305 } 302 306 } -
trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/classifier/AbstractHierarchyNode.java
r6506 r7188 296 296 action.addValue("Name", this.name); 297 297 action.addValue("Description", this.descriptor); 298 action.addValue("ClassifyOrder", this.id, GS3SQLField.INTEGER_TYPE); 298 299 action.addValue("NumLeafDocs", Integer.toString(this.noOfLeafDocs()), GS3SQLField.INTEGER_TYPE); 299 300 -
trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/classifier/HierarchyClassifier.java
r6496 r7188 2 2 3 3 import java.io.*; 4 5 import java.net.URL; 4 6 5 7 import java.util.List; … … 7 9 import java.util.Iterator; 8 10 11 import org.apache.xerces.parsers.SAXParser; 9 12 import org.xml.sax.XMLReader; 10 13 import org.xml.sax.InputSource; … … 175 178 private String sortBy; 176 179 177 public HierarchyClassifier( Filebasefile, List fields, String sortBy)180 public HierarchyClassifier(URL basefile, List fields, String sortBy) 178 181 { 179 182 try 180 { XMLReader reader = XMLReaderFactory.createXMLReader();183 { SAXParser parser = new SAXParser(); 181 184 HierarchyHandler handler = new HierarchyHandler(); 185 /* 186 XMLReader reader = XMLReaderFactory.createXMLReader(); 182 187 reader.setContentHandler(handler); 183 reader.setErrorHandler(handler); 188 reader.setErrorHandler(handler);*/ 189 parser.setContentHandler(handler); 184 190 185 191 // A Classifier consists of one file only - get it. 192 /* 186 193 FileReader fileReader = new FileReader(basefile); 187 194 reader.parse(new InputSource(fileReader)); 195 */ 196 parser.parse(basefile.toString()); 188 197 189 198 this.hierarchy = handler.getHierarchy(); 190 199 this.fields = fields; 191 200 this.sortBy = sortBy; 201 202 System.out.println("Counting " + this.fields.size() + " fields"); 192 203 } 193 204 catch (SAXException saxException) 194 205 { // TODO: log error 206 System.out.println("unable to process hierarchy " + saxException.toString()); 195 207 } 196 208 catch (java.io.FileNotFoundException fileException) 197 209 { 210 System.out.println("unable to process hierarchy " + fileException.toString()); 198 211 } 199 212 catch (java.io.IOException ioException) 200 213 { 214 System.out.println("unable to process hierarchy " + ioException.toString()); 201 215 } 202 216 } … … 218 232 } 219 233 234 /** 235 * Indicate the database to be used for saving the hierarchy to. 236 * 237 * @param <code>GS3SQLConnection</code> the database 238 */ 220 239 public void setDatabase(GS3SQLConnection database) 221 240 { this.database = database; … … 230 249 * @param <code>DocumentID</code> the document identifier 231 250 * @param <code>DocumentInterface</code> the document interface 251 * 252 * @return <code>boolean</code> a return value - currently always 253 * <code>true</code> for success 232 254 */ 233 255 public boolean classifyDocument(DocumentID documentID, DocumentInterface document) 234 256 { // the observer records the assignment of documents to classifications 235 257 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 237 264 // get the metadata item from the document 238 265 Iterator thisField = this.fields.iterator(); … … 270 297 } 271 298 299 /** 300 * @see ClassifierInterface:getClassifierPasses 301 */ 272 302 public int getClassifierPasses() 273 303 { return 1;
Note:
See TracChangeset
for help on using the changeset viewer.