Search in sources :

Example 1 with OntologyLookaheadGraph

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;
}
Also used : IRI(org.semanticweb.owlapi.model.IRI) BlankNodeOrIRI(org.apache.clerezza.commons.rdf.BlankNodeOrIRI) BufferedInputStream(java.io.BufferedInputStream) OWLOntologyID(org.semanticweb.owlapi.model.OWLOntologyID) OntologyLookaheadGraph(org.apache.stanbol.commons.owl.OntologyLookaheadGraph)

Aggregations

BufferedInputStream (java.io.BufferedInputStream)1 BlankNodeOrIRI (org.apache.clerezza.commons.rdf.BlankNodeOrIRI)1 OntologyLookaheadGraph (org.apache.stanbol.commons.owl.OntologyLookaheadGraph)1 IRI (org.semanticweb.owlapi.model.IRI)1 OWLOntologyID (org.semanticweb.owlapi.model.OWLOntologyID)1