Search in sources :

Example 1 with OWLOntologyWrapper

use of org.semanticweb.binaryowl.owlapi.OWLOntologyWrapper in project webprotege by protegeproject.

the class ImportsCacheManager method cacheOntologyIfNotAlreadyCached.

private void cacheOntologyIfNotAlreadyCached(OWLOntology ont) {
    try {
        WRITE_LOCK.lock();
        if (ontologyIDs.contains(ont.getOntologyID())) {
            return;
        }
        final File file = getFreshImportCacheFile();
        try (DataOutputStream os = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(file)))) {
            final long timestamp = System.currentTimeMillis();
            IRI documentIRI = ont.getOWLOntologyManager().getOntologyDocumentIRI(ont);
            final ImportedOntologyMetadata value = new ImportedOntologyMetadata(ont.getOntologyID(), documentIRI, timestamp);
            BinaryOWLMetadata metadata = toBinaryOWLMetadata(value);
            BinaryOWLOntologyDocumentSerializer serializer = new BinaryOWLOntologyDocumentSerializer();
            serializer.write(new OWLOntologyWrapper(ont), os, metadata);
            ontologyIDs.add(ont.getOntologyID());
            metadataMap.put(ont.getOntologyID(), value);
            logger.info("Cached imported ontology: " + ont.getOntologyID() + " in " + file.getName());
        } catch (IOException e) {
            logger.error("An error occurred whilst caching an ontology: {}", e.getMessage(), e);
        }
    } finally {
        WRITE_LOCK.unlock();
    }
}
Also used : OWLOntologyWrapper(org.semanticweb.binaryowl.owlapi.OWLOntologyWrapper) BinaryOWLMetadata(org.semanticweb.binaryowl.BinaryOWLMetadata) ImportedOntologyMetadata(edu.stanford.bmir.protege.web.shared.project.ImportedOntologyMetadata) BinaryOWLOntologyDocumentSerializer(org.semanticweb.binaryowl.BinaryOWLOntologyDocumentSerializer)

Aggregations

ImportedOntologyMetadata (edu.stanford.bmir.protege.web.shared.project.ImportedOntologyMetadata)1 BinaryOWLMetadata (org.semanticweb.binaryowl.BinaryOWLMetadata)1 BinaryOWLOntologyDocumentSerializer (org.semanticweb.binaryowl.BinaryOWLOntologyDocumentSerializer)1 OWLOntologyWrapper (org.semanticweb.binaryowl.owlapi.OWLOntologyWrapper)1