Search in sources :

Example 1 with AnnotationShorthand

use of org.geneontology.minerva.util.AnnotationShorthand in project minerva by geneontology.

the class ModelCreator method extractDataProperties.

Map<OWLDataProperty, Set<OWLLiteral>> extractDataProperties(JsonAnnotation[] values, ModelContainer model) throws UnknownIdentifierException {
    Map<OWLDataProperty, Set<OWLLiteral>> result = new HashMap<OWLDataProperty, Set<OWLLiteral>>();
    if (values != null && values.length > 0) {
        OWLDataFactory f = model.getOWLDataFactory();
        for (JsonAnnotation jsonAnn : values) {
            if (jsonAnn.key != null && jsonAnn.value != null) {
                AnnotationShorthand shorthand = AnnotationShorthand.getShorthand(jsonAnn.key, curieHandler);
                if (shorthand == null) {
                    IRI pIRI = curieHandler.getIRI(jsonAnn.key);
                    if (dataPropertyIRIs.contains(pIRI)) {
                        OWLLiteral literal = JsonTools.createLiteral(jsonAnn, f);
                        if (literal != null) {
                            OWLDataProperty property = f.getOWLDataProperty(pIRI);
                            Set<OWLLiteral> literals = result.get(property);
                            if (literals == null) {
                                literals = new HashSet<OWLLiteral>();
                                result.put(property, literals);
                            }
                            literals.add(literal);
                        }
                    }
                }
            }
        }
    }
    return result;
}
Also used : JsonAnnotation(org.geneontology.minerva.json.JsonAnnotation) AnnotationShorthand(org.geneontology.minerva.util.AnnotationShorthand)

Example 2 with AnnotationShorthand

use of org.geneontology.minerva.util.AnnotationShorthand in project minerva by geneontology.

the class ModelCreator method extract.

Set<OWLAnnotation> extract(JsonAnnotation[] values, String userId, Set<String> providerGroups, VariableResolver batchValues, ModelContainer model) throws UnknownIdentifierException {
    Set<OWLAnnotation> result = new HashSet<OWLAnnotation>();
    OWLDataFactory f = model.getOWLDataFactory();
    if (values != null) {
        for (JsonAnnotation jsonAnn : values) {
            if (jsonAnn.key != null && jsonAnn.value != null) {
                AnnotationShorthand shorthand = AnnotationShorthand.getShorthand(jsonAnn.key, curieHandler);
                if (shorthand != null) {
                    if (AnnotationShorthand.evidence == shorthand) {
                        IRI evidenceIRI;
                        if (batchValues.notVariable(jsonAnn.value)) {
                            evidenceIRI = curieHandler.getIRI(jsonAnn.value);
                        } else {
                            evidenceIRI = batchValues.getVariableValue(jsonAnn.value).getIRI();
                        }
                        result.add(create(f, shorthand, evidenceIRI));
                    } else {
                        result.add(create(f, shorthand, JsonTools.createAnnotationValue(jsonAnn, f)));
                    }
                } else {
                    IRI pIRI = curieHandler.getIRI(jsonAnn.key);
                    if (dataPropertyIRIs.contains(pIRI) == false) {
                        OWLAnnotationValue annotationValue = JsonTools.createAnnotationValue(jsonAnn, f);
                        result.add(f.getOWLAnnotation(f.getOWLAnnotationProperty(pIRI), annotationValue));
                    }
                }
            }
        }
    }
    addGeneratedAnnotations(userId, providerGroups, result, f);
    return result;
}
Also used : JsonAnnotation(org.geneontology.minerva.json.JsonAnnotation) AnnotationShorthand(org.geneontology.minerva.util.AnnotationShorthand)

Example 3 with AnnotationShorthand

use of org.geneontology.minerva.util.AnnotationShorthand in project minerva by geneontology.

the class BeforeSaveModelValidator method validateBeforeSave.

public List<String> validateBeforeSave(ModelContainer model) throws OWLOntologyCreationException {
    // get model
    List<String> errors = new ArrayList<String>(3);
    // check that model has required meta data
    OWLOntology aboxOntology = model.getAboxOntology();
    boolean hasTitle = false;
    boolean hasContributor = false;
    // get ontology annotations
    Set<OWLAnnotation> annotations = aboxOntology.getAnnotations();
    for (OWLAnnotation annotation : annotations) {
        OWLAnnotationProperty p = annotation.getProperty();
        AnnotationShorthand legoType = AnnotationShorthand.getShorthand(p.getIRI());
        if (legoType != null) {
            // check for title
            if (AnnotationShorthand.title.equals(legoType)) {
                hasTitle = true;
            } else // check for contributor
            if (AnnotationShorthand.contributor.equals(legoType)) {
                hasContributor = true;
            }
        }
    }
    if (hasTitle == false) {
        errors.add("The model has no title. All models must have a human readable title.");
    }
    if (hasContributor == false) {
        errors.add("The model has no contributors. All models must have an association with their contributors.");
    }
    // require at least one declared instance
    Set<OWLNamedIndividual> individuals = aboxOntology.getIndividualsInSignature();
    if (individuals.isEmpty()) {
        errors.add("The model has no individuals. Empty models should not be saved.");
    }
    // avoid returning empty list
    if (errors.isEmpty()) {
        errors = null;
    }
    return errors;
}
Also used : ArrayList(java.util.ArrayList) AnnotationShorthand(org.geneontology.minerva.util.AnnotationShorthand)

Aggregations

AnnotationShorthand (org.geneontology.minerva.util.AnnotationShorthand)3 JsonAnnotation (org.geneontology.minerva.json.JsonAnnotation)2 ArrayList (java.util.ArrayList)1