Search in sources :

Example 1 with OBORelationship

use of edu.stanford.bmir.protege.web.shared.obo.OBORelationship in project webprotege by protegeproject.

the class TermCrossProductsManager method getCrossProduct.

@Nonnull
public OBOTermCrossProduct getCrossProduct(@Nonnull OWLClass term) {
    Optional<OWLEquivalentClassesAxiom> axiom = getCrossProductEquivalentClassesAxiom(term);
    if (!axiom.isPresent()) {
        return OBOTermCrossProduct.emptyOBOTermCrossProduct();
    }
    Set<OWLObjectSomeValuesFrom> relationships = new HashSet<>();
    Optional<OWLClass> genus = Optional.empty();
    for (OWLClassExpression operand : axiom.get().getClassExpressionsMinus(term)) {
        Set<OWLClassExpression> conjuncts = operand.asConjunctSet();
        for (OWLClassExpression conjunct : conjuncts) {
            if (conjunct instanceof OWLObjectSomeValuesFrom) {
                OWLObjectSomeValuesFrom svf = (OWLObjectSomeValuesFrom) conjunct;
                if (!svf.getProperty().isAnonymous() && !svf.getFiller().isAnonymous()) {
                    relationships.add((OWLObjectSomeValuesFrom) conjunct);
                }
            } else if (conjunct instanceof OWLClass) {
                genus = Optional.of((OWLClass) conjunct);
            }
        }
    }
    Optional<OWLClassData> visualCls = genus.map(renderingManager::getRendering);
    Set<OBORelationship> discriminatingRelationships = relationships.stream().map(relationshipConverter::toOboRelationship).collect(toSet());
    return new OBOTermCrossProduct(visualCls, new OBOTermRelationships(discriminatingRelationships));
}
Also used : OBOTermCrossProduct(edu.stanford.bmir.protege.web.shared.obo.OBOTermCrossProduct) OBOTermRelationships(edu.stanford.bmir.protege.web.shared.obo.OBOTermRelationships) OWLClassData(edu.stanford.bmir.protege.web.shared.entity.OWLClassData) OBORelationship(edu.stanford.bmir.protege.web.shared.obo.OBORelationship) Nonnull(javax.annotation.Nonnull)

Example 2 with OBORelationship

use of edu.stanford.bmir.protege.web.shared.obo.OBORelationship in project webprotege by protegeproject.

the class OBOTermRelationshipPortletPresenter method displayEntity.

@Override
protected void displayEntity(OWLEntity entity) {
    Optional<OWLEntity> current = getSelectedEntity();
    if (!current.isPresent()) {
        editor.clearValue();
        pristineValue = Optional.empty();
        return;
    }
    if (!(current.get() instanceof OWLClass)) {
        editor.clearValue();
        pristineValue = Optional.empty();
        return;
    }
    dispatch.execute(new GetOboTermRelationshipsAction(getProjectId(), entity.asOWLClass()), this, result -> {
        List<OBORelationship> listOfRels = new ArrayList<>(result.getRelationships().getRelationships());
        pristineValue = Optional.of(listOfRels);
        editor.setValue(listOfRels);
    });
}
Also used : OBORelationship(edu.stanford.bmir.protege.web.shared.obo.OBORelationship) OWLEntity(org.semanticweb.owlapi.model.OWLEntity) ArrayList(java.util.ArrayList) GetOboTermRelationshipsAction(edu.stanford.bmir.protege.web.shared.obo.GetOboTermRelationshipsAction) OWLClass(org.semanticweb.owlapi.model.OWLClass)

Example 3 with OBORelationship

use of edu.stanford.bmir.protege.web.shared.obo.OBORelationship in project webprotege by protegeproject.

the class OBOTermRelationshipPortletPresenter method commitChangesForEntity.

@Override
protected void commitChangesForEntity(OWLEntity entity) {
    if (!(entity instanceof OWLClass)) {
        return;
    }
    List<OBORelationship> relationships = editor.getValue().orElse(Collections.emptyList());
    dispatch.execute(new SetOboTermRelationshipsAction(getProjectId(), entity, new OBOTermRelationships(Sets.newHashSet(relationships))), result -> {
    });
}
Also used : OBORelationship(edu.stanford.bmir.protege.web.shared.obo.OBORelationship) OBOTermRelationships(edu.stanford.bmir.protege.web.shared.obo.OBOTermRelationships) OWLClass(org.semanticweb.owlapi.model.OWLClass) SetOboTermRelationshipsAction(edu.stanford.bmir.protege.web.shared.obo.SetOboTermRelationshipsAction)

Example 4 with OBORelationship

use of edu.stanford.bmir.protege.web.shared.obo.OBORelationship in project webprotege by protegeproject.

the class OBOTermCrossProductEditorImpl method getValue.

@Override
public java.util.Optional<OBOTermCrossProduct> getValue() {
    if (!genusField.getValue().isPresent()) {
        return java.util.Optional.empty();
    }
    if (!relationshipsField.getValue().isPresent()) {
        return java.util.Optional.empty();
    }
    final OWLClassData genus = (OWLClassData) genusField.getValue().get();
    final OBOTermRelationships relationships = new OBOTermRelationships(new HashSet<OBORelationship>(relationshipsField.getValue().get()));
    return java.util.Optional.of(new OBOTermCrossProduct(Optional.of(genus), relationships));
}
Also used : OWLClassData(edu.stanford.bmir.protege.web.shared.entity.OWLClassData) OBORelationship(edu.stanford.bmir.protege.web.shared.obo.OBORelationship) OBOTermCrossProduct(edu.stanford.bmir.protege.web.shared.obo.OBOTermCrossProduct) OBOTermRelationships(edu.stanford.bmir.protege.web.shared.obo.OBOTermRelationships)

Example 5 with OBORelationship

use of edu.stanford.bmir.protege.web.shared.obo.OBORelationship in project webprotege by protegeproject.

the class TermRelationshipsManager method setRelationships.

public void setRelationships(@Nonnull UserId userId, @Nonnull OWLClass lastEntity, @Nonnull OBOTermRelationships relationships) {
    Set<OWLObjectSomeValuesFrom> superClsesToSet = new HashSet<>();
    for (OBORelationship relationship : relationships.getRelationships()) {
        OWLObjectSomeValuesFrom someValuesFrom = relationshipConverter.toSomeValuesFrom(relationship);
        superClsesToSet.add(someValuesFrom);
    }
    List<OWLOntologyChange> changes = new ArrayList<>();
    OWLClass cls = dataFactory.getOWLClass(lastEntity.getIRI());
    Set<OWLObjectSomeValuesFrom> existingSuperClsesToReplace = new HashSet<>();
    for (OWLSubClassOfAxiom ax : rootOntology.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(rootOntology, dataFactory.getOWLSubClassOfAxiom(cls, toReplace)));
            description.append("Removed ");
            description.append(renderingManager.getBrowserText(toReplace.getProperty()));
            description.append(" relationship to ");
            description.append(renderingManager.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(rootOntology, dataFactory.getOWLSubClassOfAxiom(cls, toSet)));
            description.append("Added ");
            description.append(renderingManager.getBrowserText(toSet.getProperty()));
            description.append(" relationship to ");
            description.append(renderingManager.getBrowserText(toSet.getFiller()));
            description.append("    ");
        }
    }
    if (!changes.isEmpty()) {
        changeManager.applyChanges(userId, new FixedChangeListGenerator<>(changes, cls, "Edited relationship values: " + description.toString()));
    }
}
Also used : ArrayList(java.util.ArrayList) OBORelationship(edu.stanford.bmir.protege.web.shared.obo.OBORelationship) HashSet(java.util.HashSet)

Aggregations

OBORelationship (edu.stanford.bmir.protege.web.shared.obo.OBORelationship)8 OWLClassData (edu.stanford.bmir.protege.web.shared.entity.OWLClassData)5 OBOTermRelationships (edu.stanford.bmir.protege.web.shared.obo.OBOTermRelationships)4 OWLObjectPropertyData (edu.stanford.bmir.protege.web.shared.entity.OWLObjectPropertyData)2 OBOTermCrossProduct (edu.stanford.bmir.protege.web.shared.obo.OBOTermCrossProduct)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Nonnull (javax.annotation.Nonnull)2 OWLClass (org.semanticweb.owlapi.model.OWLClass)2 GetOboTermRelationshipsAction (edu.stanford.bmir.protege.web.shared.obo.GetOboTermRelationshipsAction)1 SetOboTermRelationshipsAction (edu.stanford.bmir.protege.web.shared.obo.SetOboTermRelationshipsAction)1 OWLEntity (org.semanticweb.owlapi.model.OWLEntity)1