public Ontology parse ( BufferedReader in , OntologyFactory of ) throws IOException , OntologyException { String name = "" ; String description = "" ; Ontology onto = null ; for ( String line = in . readLine ( ) ; line != null ; line = in . readLine ( ) ) { line = line . trim ( ) ; if ( line . length ( ) > 0 ) { if ( line . startsWith ( "#" ) ) { // comment line - let's try to pull out name or description if ( line . startsWith ( "#name:" ) ) { name = line . substring ( "#name:" . length ( ) ) . trim ( ) ; } else if ( line . startsWith ( "#description:" ) ) { description = line . substring ( "#description:" . length ( ) ) . trim ( ) ; } } else { try { // make sure we have an ontology if ( onto == null ) { onto = of . createOntology ( name , description ) ; } // build a tripple /* int t1 = line.indexOf("\t"); int t2 = line.indexOf("\t", t1 + 1); String subject = line.substring(0, t1); String predicate = line.substring(t1 + 1, t2); String object = line.substring(t2 + 1); */ StringTokenizer toke = new StringTokenizer ( line ) ; String subject = toke . nextToken ( ) ; String predicate = toke . nextToken ( ) ; String object = toke . nextToken ( ) ; Term subT = resolveTerm ( subject , onto ) ; Term objT = resolveTerm ( object , onto ) ; Term relT = resolveTerm ( predicate , onto ) ; Triple trip = resolveTriple ( subT , objT , relT , onto ) ; trip = trip == null ? null : trip ; // prevent unused field error } catch ( StringIndexOutOfBoundsException e ) { throw new IOException ( "Could not parse line: " + line ) ; } } } } return onto ; }
Parse an ontology from a reader . The reader will be emptied of text . It is the caller s responsibility to close the reader .