use of org.semanticweb.owlapi.change.OWLOntologyChangeRecord 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();
}
}
use of org.semanticweb.owlapi.change.OWLOntologyChangeRecord in project webprotege by protegeproject.
the class ProjectImporter method generateInitialChanges.
private void generateInitialChanges(UserId owner, OWLOntologyManager rootOntologyManager) {
ImmutableList<OWLOntologyChangeRecord> changeRecords = getInitialChangeRecords(rootOntologyManager);
revisionStore.addRevision(new Revision(owner, RevisionNumber.getRevisionNumber(1), changeRecords, System.currentTimeMillis(), "Initial import"));
}
use of org.semanticweb.owlapi.change.OWLOntologyChangeRecord in project webprotege by protegeproject.
the class ChangeManager method logAndBroadcastAppliedChanges.
private <R> Revision logAndBroadcastAppliedChanges(UserId userId, ChangeListGenerator<R> changeList, ChangeApplicationResult<R> finalResult) {
// Generate a description for the changes that were actually applied
String changeDescription = changeList.getMessage(finalResult);
// Log the changes
List<OWLOntologyChangeRecord> changeRecords = finalResult.getChangeList().stream().map(OWLOntologyChange::getChangeRecord).collect(toList());
Revision revision = changeManager.addRevision(userId, changeRecords, changeDescription);
// TODO: THis list of "listeners" should be injected
List<OWLOntologyChange> changes = finalResult.getChangeList();
documentStore.saveOntologyChanges(changes);
classHierarchyProvider.handleChanges(changes);
objectPropertyHierarchyProvider.handleChanges(changes);
dataPropertyHierarchyProvider.handleChanges(changes);
annotationPropertyHierarchyProvider.handleChanges(changes);
return revision;
}
use of org.semanticweb.owlapi.change.OWLOntologyChangeRecord in project webprotege by protegeproject.
the class EntitiesByRevisionCache method getEntitiesInternal.
private ImmutableSet<OWLEntity> getEntitiesInternal(Revision revision) {
ImmutableSet.Builder<OWLEntity> result = ImmutableSet.builder();
Set<IRI> iris = new HashSet<>();
for (OWLOntologyChangeRecord change : revision) {
if (change.getData() instanceof AxiomChangeData) {
OWLAxiom ax = ((AxiomChangeData) change.getData()).getAxiom();
java.util.Optional<? extends OWLObject> subject = axiomSubjectProvider.getSubject(ax);
if (subject.isPresent()) {
if (subject.get() instanceof OWLEntity) {
result.add((OWLEntity) subject.get());
} else if (subject.get() instanceof IRI) {
iris.add((IRI) subject.get());
}
}
}
}
for (IRI iri : iris) {
for (EntityType<?> entityType : EntityType.values()) {
OWLEntity entity = dataFactory.getOWLEntity(entityType, iri);
if (hasContainsEntityInSignature.containsEntityInSignature(entity)) {
result.add(entity);
}
}
}
return result.build();
}
use of org.semanticweb.owlapi.change.OWLOntologyChangeRecord in project webprotege by protegeproject.
the class RevisionManagerImpl method getOntologyManagerForRevision.
@Nonnull
@Override
public OWLOntologyManager getOntologyManagerForRevision(@Nonnull RevisionNumber revision) {
try {
OWLOntologyManager manager = WebProtegeOWLManager.createOWLOntologyManager();
final OWLOntologyID singletonOntologyId = new OWLOntologyID();
for (Revision rev : revisionStore.getRevisions()) {
if (rev.getRevisionNumber().compareTo(revision) <= 0) {
for (OWLOntologyChangeRecord record : rev) {
// Anonymous ontologies are not handled nicely at all.
OWLOntologyChangeRecord normalisedChangeRecord = normaliseChangeRecord(record, singletonOntologyId);
OWLOntologyID ontologyId = normalisedChangeRecord.getOntologyID();
if (!manager.contains(ontologyId)) {
manager.createOntology(ontologyId);
}
OWLOntologyChange change = normalisedChangeRecord.createOntologyChange(manager);
manager.applyChange(change);
}
}
}
if (manager.getOntologies().isEmpty()) {
// No revisions exported. Just create an empty ontology
manager.createOntology();
}
return manager;
} catch (OWLOntologyCreationException e) {
throw new RuntimeException("Problem creating ontology: " + e);
}
}
Aggregations