use of edu.stanford.bmir.protege.web.server.change.FixedChangeListGenerator in project webprotege by protegeproject.
the class SetOntologyAnnotationsActionHandler method getChangeListGenerator.
@Override
protected ChangeListGenerator<Set<OWLAnnotation>> getChangeListGenerator(SetOntologyAnnotationsAction action, ExecutionContext executionContext) {
final Set<PropertyAnnotationValue> fromAnnotations = action.getFromAnnotations();
final Set<PropertyAnnotationValue> toAnnotations = action.getToAnnotations();
List<OWLOntologyChange> changeList = new ArrayList<>();
OWLDataFactory dataFactory = rootOntology.getOWLOntologyManager().getOWLDataFactory();
for (PropertyAnnotationValue annotation : fromAnnotations) {
if (!toAnnotations.contains(annotation)) {
annotation.getValue().asAnnotationValue().ifPresent(av -> {
changeList.add(new RemoveOntologyAnnotation(rootOntology, dataFactory.getOWLAnnotation(annotation.getProperty().getEntity().asOWLAnnotationProperty(), av)));
});
}
}
for (PropertyAnnotationValue annotation : toAnnotations) {
if (!fromAnnotations.contains(annotation)) {
annotation.getValue().asAnnotationValue().ifPresent(av -> {
changeList.add(new AddOntologyAnnotation(rootOntology, dataFactory.getOWLAnnotation(annotation.getProperty().getEntity().asOWLAnnotationProperty(), av)));
});
}
}
return new FixedChangeListGenerator<Set<OWLAnnotation>>(changeList, Collections.emptySet(), "Edited ontology annotations") {
@Override
public Set<OWLAnnotation> getRenamedResult(Set<OWLAnnotation> result, RenameMap renameMap) {
return super.getRenamedResult(result, renameMap);
}
};
}
use of edu.stanford.bmir.protege.web.server.change.FixedChangeListGenerator in project webprotege by protegeproject.
the class TermSynonymsManager method setSynonyms.
public void setSynonyms(@Nonnull UserId userId, @Nonnull OWLEntity term, @Nonnull Collection<OBOTermSynonym> synonyms) {
List<OWLOntologyChange> changes = new ArrayList<>();
rootOntology.getAnnotationAssertionAxioms(term.getIRI()).stream().filter(ax -> getSynonymScope(ax) != null).map(ax -> new RemoveAxiom(rootOntology, ax)).forEach(changes::add);
for (OBOTermSynonym synonym : synonyms) {
OWLAnnotationProperty synonymProperty = getSynonymAnnoationProperty(df, synonym.getScope());
OWLLiteral synonymNameLiteral = df.getOWLLiteral(synonym.getName());
Set<OWLAnnotation> synonymXRefs = synonym.getXRefs().stream().filter(x -> !x.isEmpty()).map(xRefConverter::toAnnotation).collect(Collectors.toSet());
OWLAnnotationAssertionAxiom synonymAnnotationAssertion = df.getOWLAnnotationAssertionAxiom(synonymProperty, term.getIRI(), synonymNameLiteral, synonymXRefs);
changes.add(new AddAxiom(rootOntology, synonymAnnotationAssertion));
}
if (!changes.isEmpty()) {
changeManager.applyChanges(userId, new FixedChangeListGenerator<>(changes, term, "Edited term synonyms"));
}
}
Aggregations