Search in sources :

Example 1 with OntologyChangeDataList

use of org.semanticweb.binaryowl.change.OntologyChangeDataList in project webprotege by protegeproject.

the class ProjectDocumentStore method saveOntologyChanges.

// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public void saveOntologyChanges(List<OWLOntologyChange> rawChangeList) {
    // Put changes into a buffer
    try {
        writeLock.lock();
        try {
            ListMultimap<OWLOntology, OWLOntologyChange> changesByOntology = ArrayListMultimap.create();
            for (OWLOntologyChange change : rawChangeList) {
                changesByOntology.put(change.getOntology(), change);
            }
            for (OWLOntology ontology : changesByOntology.keySet()) {
                IRI docIRI = ontology.getOWLOntologyManager().getOntologyDocumentIRI(ontology);
                if (!"file".equalsIgnoreCase(docIRI.toURI().getScheme())) {
                    throw new RuntimeException("Document IRI is not a local file IRI");
                }
                List<OWLOntologyChange> ontologyChangeList = changesByOntology.get(ontology);
                List<OWLOntologyChangeData> infoList = new ArrayList<>();
                for (OWLOntologyChange change : ontologyChangeList) {
                    OWLOntologyChangeRecord changeRecord = change.getChangeRecord();
                    infoList.add(changeRecord.getData());
                }
                File file = new File(docIRI.toURI());
                BinaryOWLOntologyDocumentSerializer serializer = new BinaryOWLOntologyDocumentSerializer();
                serializer.appendOntologyChanges(file, new OntologyChangeDataList(infoList, System.currentTimeMillis(), BinaryOWLMetadata.emptyMetadata()));
            }
        } catch (IOException e) {
            logger.error("An error occurred whilst saving ontology changes: {}", e.getMessage(), e);
            e.printStackTrace();
        }
    } finally {
        writeLock.unlock();
    }
}
Also used : ArrayList(java.util.ArrayList) OntologyChangeDataList(org.semanticweb.binaryowl.change.OntologyChangeDataList) OWLOntologyCreationIOException(org.semanticweb.owlapi.io.OWLOntologyCreationIOException) BinaryOWLOntologyDocumentSerializer(org.semanticweb.binaryowl.BinaryOWLOntologyDocumentSerializer) OWLOntologyChangeRecord(org.semanticweb.owlapi.change.OWLOntologyChangeRecord) OWLOntologyChangeData(org.semanticweb.owlapi.change.OWLOntologyChangeData)

Aggregations

ArrayList (java.util.ArrayList)1 BinaryOWLOntologyDocumentSerializer (org.semanticweb.binaryowl.BinaryOWLOntologyDocumentSerializer)1 OntologyChangeDataList (org.semanticweb.binaryowl.change.OntologyChangeDataList)1 OWLOntologyChangeData (org.semanticweb.owlapi.change.OWLOntologyChangeData)1 OWLOntologyChangeRecord (org.semanticweb.owlapi.change.OWLOntologyChangeRecord)1 OWLOntologyCreationIOException (org.semanticweb.owlapi.io.OWLOntologyCreationIOException)1