public void setRelationships(ProjectId projectId, OWLClass lastEntity, OBOTermRelationships relationships) {
ensureSignedIn();
if (relationships == null) {
throw new NullPointerException("relationships must not be null");
}
OWLAPIProject project = getProject(projectId);
OWLDataFactory dataFactory = project.getDataFactory();
Set<OWLObjectSomeValuesFrom> superClsesToSet = new HashSet<OWLObjectSomeValuesFrom>();
for (OBORelationship relationship : relationships.getRelationships()) {
OWLObjectSomeValuesFrom someValuesFrom = toSomeValuesFrom(dataFactory, relationship);
superClsesToSet.add(someValuesFrom);
}
List<OWLOntologyChange> changes = new ArrayList<OWLOntologyChange>();
OWLOntology ontology = project.getRootOntology();
OWLClass cls = dataFactory.getOWLClass(lastEntity.getIRI());
Set<OWLObjectSomeValuesFrom> existingSuperClsesToReplace = new HashSet<OWLObjectSomeValuesFrom>();
for (OWLSubClassOfAxiom ax : ontology.getSubClassAxiomsForSubClass(cls)) {
if (ax.getSuperClass() instanceof OWLObjectSomeValuesFrom) {
OWLObjectSomeValuesFrom existing = (OWLObjectSomeValuesFrom) ax.getSuperClass();
existingSuperClsesToReplace.add(existing);
}
}
// What's changed?
StringBuilder description = new StringBuilder();
for (OWLObjectSomeValuesFrom toReplace : existingSuperClsesToReplace) {
if (!superClsesToSet.contains(toReplace)) {
// Was there but not any longer
changes.add(new RemoveAxiom(ontology, dataFactory.getOWLSubClassOfAxiom(cls, toReplace)));
description.append("Removed ");
description.append(project.getRenderingManager().getBrowserText(toReplace.getProperty()));
description.append(" relationship to ");
description.append(project.getRenderingManager().getBrowserText(toReplace.getFiller()));
description.append(" ");
}
}
// What do we add?
for (OWLObjectSomeValuesFrom toSet : superClsesToSet) {
if (!existingSuperClsesToReplace.contains(toSet)) {
// Not already there - we're adding it.
changes.add(new AddAxiom(ontology, dataFactory.getOWLSubClassOfAxiom(cls, toSet)));
description.append("Added ");
description.append(project.getRenderingManager().getBrowserText(toSet.getProperty()));
description.append(" relationship to ");
description.append(project.getRenderingManager().getBrowserText(toSet.getFiller()));
description.append(" ");
}
}
if (!changes.isEmpty()) {
UserId userId = getUserInSessionAndEnsureSignedIn();
project.applyChanges(userId, changes, "Edited relationship values: " + description.toString());
}
}