Java Code Examples for org.semanticweb.owlapi.model.OWLAxiom#getAnnotations()

The following examples show how to use org.semanticweb.owlapi.model.OWLAxiom#getAnnotations() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AxiomAnnotationTools.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Retrieve the literal values for the axiom annotations with the given
 * annotation property IRI.
 * 
 * @param iri
 * @param axiom
 * @return literal values or null
 */
public static List<String> getAxiomAnnotationValues(IRI iri, OWLAxiom axiom) {
	List<String> result = null;
	for(OWLAnnotation annotation : axiom.getAnnotations()) {
		OWLAnnotationProperty property = annotation.getProperty();
		if (property.getIRI().equals(iri)) {
			OWLAnnotationValue value = annotation.getValue();
			if (value instanceof OWLLiteral) {
				String literal = ((OWLLiteral) value).getLiteral();
				if (result == null) {
					result = Collections.singletonList(literal);
				}
				else if (result.size() == 1) {
					result = new ArrayList<String>(result);
					result.add(literal);
				}
				else {
					result.add(literal);
				}
			}
		}
	}
	return result;
}
 
Example 2
Source File: AxiomAnnotationTools.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Append xref annotations onto an existing axiom
 * 
 * @param axiom
 * @param xrefs
 * @param ontology
 * @return
 */
public static OWLAxiom appendXrefAnnotations(OWLAxiom axiom, Set<String> xrefs, OWLOntology ontology) {
    // filter existing
    Set<OWLAnnotation> newAnnotations = new HashSet<OWLAnnotation>(axiom.getAnnotations());
       final OWLOntologyManager manager = ontology.getOWLOntologyManager();
    final OWLDataFactory factory = manager.getOWLDataFactory();

    for (String x : xrefs) {
        OWLAnnotationProperty p = factory.getOWLAnnotationProperty(IRI.create("http://www.geneontology.org/formats/oboInOwl#hasDbXref"));
        OWLLiteral v = factory.getOWLLiteral(x);
        newAnnotations.add(factory.getOWLAnnotation(p, v));
    }
    final OWLAxiom newAxiom = changeAxiomAnnotations(axiom, newAnnotations, ontology);
    return newAxiom;
}
 
Example 3
Source File: AxiomAnnotationTools.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Remove axiom annotations, which do not comply with the OBO-Basic level,
 * i.e. trailing qualifier values in OBO.<br>
 * <b>Side effect</b>: This removes the old axiom and adds the new axiom to
 * the given ontology. The method also returns the new axiom to enable
 * chaining.
 * 
 * @param axiom
 * @param ontology
 * @return axiom
 */
public static OWLAxiom reduceAxiomAnnotationsToOboBasic(OWLAxiom axiom, OWLOntology ontology) {
	Set<OWLAnnotation> annotations = axiom.getAnnotations();
	if (annotations != null && !annotations.isEmpty()) {
		boolean changed = false;
		Set<OWLAnnotation> newAnnotations = new HashSet<OWLAnnotation>();
		for (OWLAnnotation owlAnnotation : annotations) {
			OWLAnnotationProperty p = owlAnnotation.getProperty();
			IRI iri = p.getIRI();
			/*
			 * if the property IRI is not in a predefined annotation property in 
			 * Obo2Owl assume that it's not OBO-Basic
			 */
			if (Obo2Owl.ANNOTATIONPROPERTYMAP.containsValue(iri) == false) {
				// remove axiom annotation
				changed = true;
			}
			else {
				newAnnotations.add(owlAnnotation);
			}
		}
		if (changed) {
			// only update the axiom if the annotations have been changed
			OWLAxiom newAxiom = AxiomAnnotationTools.changeAxiomAnnotations(axiom, newAnnotations, ontology);
			return newAxiom;
		}
	}
	return axiom;
}
 
Example 4
Source File: LinkMaker.java    From owltools with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Start search for matches of the given patterns. Annotate new axioms with
 * the given source annotation. Furthermore create a new axiom for existing
 * annotations, if they do not have a matching source annotation.<br>
 * <br>
 * This method does not modify the ontology, it only returns the axioms. 
 * 
 * @param patterns
 * @param sourceAnnotation
 * @return result
 */
public LinkMakerResult makeLinks(List<LinkPattern> patterns, OWLAnnotation sourceAnnotation, boolean updateExisting) {
	final Set<OWLAxiom> resultAxioms = new HashSet<OWLAxiom>();
	final Set<OWLAxiom> existingAxioms = new HashSet<OWLAxiom>();
	final Set<OWLAxiom> modified = new HashSet<OWLAxiom>();
	for (LinkPattern linkPattern : patterns) {
		for (OWLClass currentSubClass : getRelevantClasses(linkPattern.subGenus)) {
			OWLClass differentiaCls = hasMatchingIntersection(currentSubClass, linkPattern.subGenus, linkPattern.differentiaRelation);
			if (differentiaCls != null) {
				// found a matching class, now search for the corresponding one.
				for(OWLClass currentSuperClass : getRelevantClasses(linkPattern.superGenus)) {
					OWLClass potentialMatch = hasMatchingIntersection(currentSuperClass, linkPattern.superGenus, linkPattern.differentiaRelation);
					if (differentiaCls.equals(potentialMatch)) {
						// the class has the required xp
						// now check that the link does not already exist
						OWLAxiom existing = hasLinks(currentSubClass, linkPattern.newRelation, currentSuperClass);
						OWLObjectSomeValuesFrom someValuesFrom = f.getOWLObjectSomeValuesFrom(linkPattern.newRelation, currentSuperClass);
						if (existing == null) {
							OWLSubClassOfAxiom a = f.getOWLSubClassOfAxiom(currentSubClass, someValuesFrom, Collections.singleton(sourceAnnotation));
							resultAxioms.add(a);
						}
						else {
							if (updateExisting) {
								existingAxioms.add(existing);
								Set<OWLAnnotation> existingAnnotations = existing.getAnnotations();
								if (existingAnnotations.contains(sourceAnnotation)) {
									modified.add(existing);
								}
								else {
									Set<OWLAnnotation> mergedAnnotations = new HashSet<OWLAnnotation>();
									mergedAnnotations.add(sourceAnnotation);
									mergedAnnotations.addAll(existingAnnotations);
									OWLSubClassOfAxiom mod = f.getOWLSubClassOfAxiom(currentSubClass, someValuesFrom, mergedAnnotations);
									modified.add(mod);
								}
							}
						}
					}
				}
			}
		}
	}
	return new LinkMakerResult(resultAxioms, existingAxioms, modified);
}
 
Example 5
Source File: LegoMetadata.java    From owltools with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * @param node
 * @param axiom
 */
public static void extractMetadata(LegoMetadata node, OWLAxiom axiom) {
	// extract meta data from annotations
	Set<OWLAnnotation> annotations = axiom.getAnnotations();
	for (OWLAnnotation annotation : annotations) {
		String propertyId = annotation.getProperty().getIRI().toString();
		OWLAnnotationValue annValue = annotation.getValue();
		String value = annValue.accept(LiteralValueVisitor.INSTANCE);
		if (value != null) {
			if ("http://geneontology.org/lego/evidence".equals(propertyId)) {
				Set<String> evidence = node.getEvidence();
				if (evidence == null) {
					evidence = new HashSet<String>();
					node.setEvidence(evidence);
				}
				evidence.add(value);
			}
			else if ("http://purl.org/dc/elements/1.1/date".equals(propertyId)) {
				Set<String> dates = node.getDates();
				if (dates == null) {
					dates = new HashSet<String>();
					node.setDates(dates);
				}
				dates.add(value);
			}
			else if ("http://purl.org/dc/elements/1.1/source".equals(propertyId)) {
				Set<String> sources = node.getSources();
				if (sources == null) {
					sources = new HashSet<String>();
					node.setSources(sources);
				}
				sources.add(value);
			}
			else if ("http://purl.org/dc/elements/1.1/contributor".equals(propertyId)) {
					Set<String> contributors = node.getContributors();
					if (contributors == null) {
						contributors = new HashSet<String>();
						node.setContributors(contributors);
					}
					contributors.add(value);
			}
		}
	}
}
 
Example 6
Source File: AxiomAnnotationTools.java    From owltools with BSD 3-Clause "New" or "Revised" License 3 votes vote down vote up
/**
 * Append annotations to an existing axiom
 * 
 * @param axiom
 * @param annotations
 * @param ontology
 * @return
 */
public static OWLAxiom appendAxiomAnnotations(OWLAxiom axiom, Set<OWLAnnotation> annotations, OWLOntology ontology) {
       // filter existing
       Set<OWLAnnotation> newAnnotations = new HashSet<OWLAnnotation>(axiom.getAnnotations());
       newAnnotations.addAll(annotations);
       final OWLAxiom newAxiom = changeAxiomAnnotations(axiom, newAnnotations, ontology);
       return newAxiom;
   }