use of org.apache.stanbol.commons.owl.OntologyLookaheadGraph in project stanbol by apache.
the class OWLUtils method guessOntologyID.
public static OWLOntologyID guessOntologyID(InputStream content, Parser parser, String format, int limit, int versionIriOffset) throws IOException {
long before = System.currentTimeMillis();
log.info("Guessing ontology ID. Read limit = {} triples; offset = {} triples.", limit, versionIriOffset);
BufferedInputStream bIn = new BufferedInputStream(content);
// set an appropriate limit
bIn.mark(limit * 512);
OntologyLookaheadGraph graph = new OntologyLookaheadGraph(limit, versionIriOffset);
try {
parser.parse(graph, bIn, format);
} catch (RuntimeException e) {
log.error("Parsing failed for format {}. Returning null.", format);
}
OWLOntologyID result;
if (graph.getOntologyIRI() == null) {
// No Ontology ID found
log.warn(" *** No ontology ID found, ontology has a chance of being anonymous.");
result = new OWLOntologyID();
} else {
// bIn.reset(); // reset set the stream to the start
IRI oiri = IRI.create(graph.getOntologyIRI().getUnicodeString());
result = graph.getVersionIRI() == null ? new OWLOntologyID(oiri) : new OWLOntologyID(oiri, IRI.create(graph.getVersionIRI().getUnicodeString()));
log.info(" *** Guessed ID : {}", result);
}
log.info(" ... Triples scanned : {}; filtered in : {}", graph.getScannedTripleCount(), graph.size());
log.info(" ... Time : {} ms", System.currentTimeMillis() - before);
return result;
}
Aggregations