Search in sources :

Example 1 with OBOXRef

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

the class XRefConverter method toOBOXRef.

/**
 * Convert the specified value and description to an OBO XRef
 * @param value The value.
 * @param description The description
 * @return The corresponding OBOXRef
 */
@Nonnull
public OBOXRef toOBOXRef(@Nonnull String value, @Nonnull String description) {
    // Need to peel apart the ID
    if (value.startsWith(Obo2OWLConstants.DEFAULT_IRI_PREFIX)) {
        String localValue = value.substring(Obo2OWLConstants.DEFAULT_IRI_PREFIX.length());
        Matcher matcher = SEPARATOR_PATTERN.matcher(localValue);
        if (matcher.matches()) {
            String dbname = unescapeSpaces(matcher.group(1));
            String dbid = matcher.group(3);
            return new OBOXRef(dbname, dbid, description);
        } else {
            return new OBOXRef("", value, description);
        }
    } else {
        final int nameIdSeparatorIndex = value.indexOf(':');
        if (nameIdSeparatorIndex != -1) {
            return new OBOXRef(value.substring(0, nameIdSeparatorIndex), value.substring(nameIdSeparatorIndex + 1), description);
        }
        return new OBOXRef("", value, description);
    }
}
Also used : Matcher(java.util.regex.Matcher) OBOXRef(edu.stanford.bmir.protege.web.shared.obo.OBOXRef) Nonnull(javax.annotation.Nonnull)

Example 2 with OBOXRef

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

the class XRefEditorImpl method getValue.

@Override
public Optional<OBOXRef> getValue() {
    String databaseName = getDatabaseName();
    if (databaseName.isEmpty()) {
        return Optional.empty();
    }
    String databaseId = getDatabaseId();
    if (databaseId.isEmpty()) {
        return Optional.empty();
    }
    String description = getDescription();
    return Optional.of(new OBOXRef(databaseName, databaseId, description));
}
Also used : OBOXRef(edu.stanford.bmir.protege.web.shared.obo.OBOXRef)

Example 3 with OBOXRef

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

the class TermDefinitionManager method setTermDefinition.

public void setTermDefinition(@Nonnull UserId userId, @Nonnull OWLEntity term, @Nonnull OBOTermDefinition definition) {
    List<OBOXRef> xRefs = definition.getXRefs();
    Set<OWLAnnotation> xrefAnnotations = xRefs.stream().filter(x -> !x.isEmpty()).map(xRefConverter::toAnnotation).collect(Collectors.toSet());
    IRI subject = term.getIRI();
    final IRI defIRI = getIRI(OBOFormatConstants.OboFormatTag.TAG_DEF);
    OWLAnnotationProperty defAnnotationProperty = df.getOWLAnnotationProperty(defIRI);
    OWLLiteral defLiteral = df.getOWLLiteral(definition.getDefinition());
    OWLAnnotationAssertionAxiom definitionAssertion = df.getOWLAnnotationAssertionAxiom(defAnnotationProperty, subject, defLiteral, xrefAnnotations);
    List<OWLOntologyChange> changes = new ArrayList<>();
    for (OWLAnnotationAssertionAxiom existingAx : rootOntology.getAnnotationAssertionAxioms(subject)) {
        if (existingAx.getProperty().getIRI().equals(defIRI)) {
            changes.add(new RemoveAxiom(rootOntology, existingAx));
            Set<OWLAnnotation> nonXRefAnnotations = getAxiomAnnotationsExcludingXRefs(existingAx);
            OWLAxiom fullyAnnotatedDefinitionAssertion = definitionAssertion.getAnnotatedAxiom(nonXRefAnnotations);
            changes.add(new AddAxiom(rootOntology, fullyAnnotatedDefinitionAssertion));
        }
    }
    if (changes.isEmpty()) {
        // New
        changes.add(new AddAxiom(rootOntology, definitionAssertion));
    }
    changeManager.applyChanges(userId, new FixedChangeListGenerator<>(changes, term, "Edited the term definition for " + renderingManager.getRendering(term).getBrowserText()));
}
Also used : OboUtil.getIRI(edu.stanford.bmir.protege.web.server.obo.OboUtil.getIRI) ArrayList(java.util.ArrayList) OBOXRef(edu.stanford.bmir.protege.web.shared.obo.OBOXRef)

Example 4 with OBOXRef

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

the class OBOTermSynonymEditorImpl method getValue.

@Override
public Optional<OBOTermSynonym> getValue() {
    final String synonymName = getSynonymName();
    if (synonymName.isEmpty()) {
        return Optional.empty();
    }
    final List<OBOXRef> xrefs = xrefListField.getValue().orElse(Collections.emptyList());
    return Optional.of(new OBOTermSynonym(xrefs, synonymName, getSynonymScope()));
}
Also used : OBOXRef(edu.stanford.bmir.protege.web.shared.obo.OBOXRef) OBOTermSynonym(edu.stanford.bmir.protege.web.shared.obo.OBOTermSynonym)

Aggregations

OBOXRef (edu.stanford.bmir.protege.web.shared.obo.OBOXRef)4 OboUtil.getIRI (edu.stanford.bmir.protege.web.server.obo.OboUtil.getIRI)1 OBOTermSynonym (edu.stanford.bmir.protege.web.shared.obo.OBOTermSynonym)1 ArrayList (java.util.ArrayList)1 Matcher (java.util.regex.Matcher)1 Nonnull (javax.annotation.Nonnull)1