Search in sources :

Example 1 with FixedChangeListGenerator

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);
        }
    };
}
Also used : Set(java.util.Set) FixedChangeListGenerator(edu.stanford.bmir.protege.web.server.change.FixedChangeListGenerator) ArrayList(java.util.ArrayList) RenameMap(edu.stanford.bmir.protege.web.server.owlapi.RenameMap) PropertyAnnotationValue(edu.stanford.bmir.protege.web.shared.frame.PropertyAnnotationValue)

Example 2 with FixedChangeListGenerator

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"));
    }
}
Also used : FixedChangeListGenerator(edu.stanford.bmir.protege.web.server.change.FixedChangeListGenerator) ChangeManager(edu.stanford.bmir.protege.web.server.project.ChangeManager) java.util(java.util) org.semanticweb.owlapi.model(org.semanticweb.owlapi.model) OboUtil.getStringValue(edu.stanford.bmir.protege.web.server.obo.OboUtil.getStringValue) OBOFormatConstants(org.obolibrary.oboformat.parser.OBOFormatConstants) Collectors(java.util.stream.Collectors) Inject(javax.inject.Inject) OBOTermSynonymScope(edu.stanford.bmir.protege.web.shared.obo.OBOTermSynonymScope) UserId(edu.stanford.bmir.protege.web.shared.user.UserId) Obo2OWLConstants(org.obolibrary.obo2owl.Obo2OWLConstants) OboUtil.getIRI(edu.stanford.bmir.protege.web.server.obo.OboUtil.getIRI) OBOTermSynonym(edu.stanford.bmir.protege.web.shared.obo.OBOTermSynonym) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) OBOTermSynonym(edu.stanford.bmir.protege.web.shared.obo.OBOTermSynonym)

Aggregations

FixedChangeListGenerator (edu.stanford.bmir.protege.web.server.change.FixedChangeListGenerator)2 OboUtil.getIRI (edu.stanford.bmir.protege.web.server.obo.OboUtil.getIRI)1 OboUtil.getStringValue (edu.stanford.bmir.protege.web.server.obo.OboUtil.getStringValue)1 RenameMap (edu.stanford.bmir.protege.web.server.owlapi.RenameMap)1 ChangeManager (edu.stanford.bmir.protege.web.server.project.ChangeManager)1 PropertyAnnotationValue (edu.stanford.bmir.protege.web.shared.frame.PropertyAnnotationValue)1 OBOTermSynonym (edu.stanford.bmir.protege.web.shared.obo.OBOTermSynonym)1 OBOTermSynonymScope (edu.stanford.bmir.protege.web.shared.obo.OBOTermSynonymScope)1 UserId (edu.stanford.bmir.protege.web.shared.user.UserId)1 java.util (java.util)1 ArrayList (java.util.ArrayList)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Nonnull (javax.annotation.Nonnull)1 Nullable (javax.annotation.Nullable)1 Inject (javax.inject.Inject)1 Obo2OWLConstants (org.obolibrary.obo2owl.Obo2OWLConstants)1 OBOFormatConstants (org.obolibrary.oboformat.parser.OBOFormatConstants)1 org.semanticweb.owlapi.model (org.semanticweb.owlapi.model)1