/** * Creates or adds documents to an index. * @param ontologyIndex The index to use * @param mappings Mappings of ontology name/urls * @param create If true, remove the index if existed. Otherwise, add to the index * @throws OBOParseException thrown if there is a problem parsing the OBO file * @throws IOException thrown if there is a problem writing to the index */ public static void buildIndexFromObo(Directory ontologyIndex, OntologyMapping[] mappings, boolean create) throws OBOParseException, IOException { OntologyIndexWriter writer = new OntologyIndexWriter( ontologyIndex, create ); for (OntologyMapping mapping : mappings) { addOboOntologyToIndex( mapping, writer ); } writer.flush(); writer.optimize(); writer.close(); }
private static void addOboOntologyToIndex( OntologyMapping mapping, OntologyIndexWriter writer ) throws OBOParseException, IOException { final long start = System.currentTimeMillis(); OboOntologyIterator iterator = new OboOntologyIterator( mapping.getName(), mapping.getUrl() ); if ( log.isDebugEnabled() ) log.debug( "Starting to index " + mapping.getName() + " (URL: "+ mapping.getUrl() +")"); int count = 0; while ( iterator.hasNext() ) { count++; if ( log.isTraceEnabled() && ( (count % 1000 ) == 0 ) ) { log.trace( "Processed " + count + " " + mapping.getName() + " terms" ); } final OntologyDocument ontologyDocument = iterator.next(); writer.addDocument( ontologyDocument ); } final long stop = System.currentTimeMillis(); if ( log.isDebugEnabled() ) log.debug( "Completed indexing of " + mapping.getName() + " in " + (stop - start) + "ms" ); } }