Java Code Examples for org.semanticweb.owlapi.model.OWLAnnotation#getProperty()

The following examples show how to use org.semanticweb.owlapi.model.OWLAnnotation#getProperty() . 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: ModelAnnotationSolrDocumentLoader.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private Map<String,String> renderAnnotations(Set<OWLAnnotation> annotations) {
	Map<String,String> result = null;
	if (annotations != null && !annotations.isEmpty()) {
		for (OWLAnnotation annotation : annotations) {
			OWLAnnotationProperty prop = annotation.getProperty();
			String literal = getLiteralValue(annotation.getValue());
			if (literal != null) {
				if (result == null) {
					result = new HashMap<String, String>();
				}
				result.put(prop.toStringID(), literal);
			}
		}
	}
	return result;
}
 
Example 2
Source File: Mooncat.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void removeDirectives() {
	// TODO decide: move the set of directives into a constant/static collection?
	
	Set<IRI> directivesIRIs = new HashSet<IRI>();
	directivesIRIs.add(Obo2OWLVocabulary.IRI_OIO_LogicalDefinitionViewRelation.getIRI());
	directivesIRIs.add(Obo2OWLVocabulary.IRI_OIO_treatXrefsAsEquivalent.getIRI());
	directivesIRIs.add(Obo2OWLVocabulary.IRI_OIO_treatXrefsAsGenusDifferentia.getIRI());
	directivesIRIs.add(Obo2OWLVocabulary.IRI_OIO_treatXrefsAsHasSubClass.getIRI());
	directivesIRIs.add(Obo2OWLVocabulary.IRI_OIO_treatXrefsAsIsA.getIRI());
	directivesIRIs.add(Obo2OWLVocabulary.IRI_OIO_treatXrefsAsRelationship.getIRI());
	directivesIRIs.add(Obo2OWLVocabulary.IRI_OIO_treatXrefsAsReverseGenusDifferentia.getIRI());
	
	OWLOntology o = graph.getSourceOntology();
	for(OWLAnnotation ann : o.getAnnotations()) {
		final OWLAnnotationProperty property = ann.getProperty();
		if (directivesIRIs.contains(property.getIRI())) {
			manager.applyChange(new RemoveOntologyAnnotation(o, ann));
		}
	}
}
 
Example 3
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 4
Source File: OWLGraphWrapperExtended.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private String getOntologyAnnotationValue(OWLOntology o, OboFormatTag tag) {
	IRI dateTagIRI = Obo2Owl.trTagToIRI(tag.getTag());
	Set<OWLAnnotation> annotations = o.getAnnotations();
	for (OWLAnnotation annotation : annotations) {
		OWLAnnotationProperty property = annotation.getProperty();
		if(dateTagIRI.equals(property.getIRI())) {
			OWLAnnotationValue value = annotation.getValue();
			if (value != null) {
				if (value instanceof IRI) {
					return ((IRI) value).toString();
				}
				else if (value instanceof OWLLiteral) {
					return ((OWLLiteral) value).getLiteral();
				}
			}
		}
	}
	return null;
}
 
Example 5
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 6
Source File: OWLGraphWrapperExtended.java    From owltools with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public IRI getIRIByIdentifier(String id, boolean isAutoResolve) {
	if (isAutoResolve) {
		OWLObject obj = this.getObjectByAltId(id);
		if (obj != null) {
			return ((OWLNamedObject) obj).getIRI();
		}
	}

	// special magic for finding IRIs from a non-standard identifier
	// This is the case for relations (OWLObject properties) with a short hand
	// or for relations with a non identifiers with-out a colon, e.g. negative_regulation
	// we first collect all candidate matching properties in candIRISet.
	Set<IRI> candIRISet = Sets.newHashSet();
	if (!id.contains(":")) {
		final OWLAnnotationProperty shortHand = getDataFactory().getOWLAnnotationProperty(Obo2OWLVocabulary.IRI_OIO_shorthand.getIRI());
		final OWLAnnotationProperty oboIdInOwl = getDataFactory().getOWLAnnotationProperty(Obo2Owl.trTagToIRI(OboFormatTag.TAG_ID.getTag()));
		for (OWLOntology o : getAllOntologies()) {
			for(OWLObjectProperty p : o.getObjectPropertiesInSignature()) {
				// check for short hand or obo ID in owl
				Set<OWLAnnotation> annotations = OwlHelper.getAnnotations(p, o);
				if (annotations != null) {
					for (OWLAnnotation owlAnnotation : annotations) {
						OWLAnnotationProperty property = owlAnnotation.getProperty();
						if ((shortHand != null && shortHand.equals(property)) 
								|| (oboIdInOwl != null && oboIdInOwl.equals(property)))
						{
							OWLAnnotationValue value = owlAnnotation.getValue();
							if (value != null && value instanceof OWLLiteral) {
								OWLLiteral literal = (OWLLiteral) value;
								String shortHandLabel = literal.getLiteral();
								if (id.equals(shortHandLabel)) {
									candIRISet.add(p.getIRI());
								}
							}
						}
					}
				}
			}
		}
	}

	// In the case where we find multiple candidate IRIs, we give priorities for IRIs from BFO or RO ontologies.
	IRI returnIRI = null;
	for (IRI iri: candIRISet) {
		String iriStr = iri.toString();
		if (iriStr.contains("BFO") || iriStr.contains("RO")) {
			returnIRI = iri;
		}
	}

	// If we were not able to find RO/BFO candidate IRIs for id
	if (returnIRI == null) {
		// We return it only if we have only one candidate. 
		if (candIRISet.size() == 1)
			return new ArrayList<IRI>(candIRISet).get(0);
		// This is the unexpected case. Multiple non-RO/BPO properties are mapped to given id and it's not clear what to return.
		else if (candIRISet.size() > 1)
			throw new RuntimeException("Multiple candidate IRIs are found for id: " +  id + ". None of them are from BFO or RO.");
	}
	// If we were able to find the property from RO/BFO, just return it. 
	else {
		return returnIRI;
	}

	// otherwise use the obo2owl method
	Obo2Owl b = new Obo2Owl(getManager()); // re-use manager, creating a new one can be expensive as this is a highly used code path
	b.setObodoc(new OBODoc());
	return b.oboIdToIRI(id);
}
 
Example 7
Source File: GraphOwlVisitorTestBase.java    From SciGraph with Apache License 2.0 4 votes vote down vote up
@Before
public void setup() throws Exception {
  if (builtGraph) {
    // TODO: UGH - need a better pattern for this
    return;
  }
  graph = createInstance();

  String uri = Resources.getResource("ontologies/family.owl").toURI().toString();
  manager.loadOntologyFromOntologyDocument(IRI.create(uri));

  List<MappedProperty> propertyMap = new ArrayList<>();
  MappedProperty age = mock(MappedProperty.class);
  when(age.getName()).thenReturn("isAged");
  when(age.getProperties()).thenReturn(newArrayList(ROOT + "/hasAge"));
  propertyMap.add(age);
  MappedProperty versionInfo = mock(MappedProperty.class);
  when(versionInfo.getName()).thenReturn("versionInfo");
  when(versionInfo.getProperties()).thenReturn(newArrayList(OWL + "versionInfo"));
  propertyMap.add(versionInfo);
  OWLOntologyWalker walker = new OWLOntologyWalker(manager.getOntologies());
  GraphOwlVisitor visitor = new GraphOwlVisitor(walker, graph, propertyMap);
  walker.walkStructure(visitor);
  
  for (OWLOntology ontology : manager.getOntologies()){
    String ontologyIri = OwlApiUtils.getIri(ontology);
    for (OWLAnnotation annotation : ontology.getAnnotations()) { // Get annotations on ontology iri
      OWLAnnotationSubject ontologySubject = IRI.create(ontologyIri);
      OWLAnnotationAssertionAxiom object = 
          new OWLAnnotationAssertionAxiomImpl(ontologySubject,
              annotation.getProperty(), annotation.getValue(),
              new ArrayList<OWLAnnotation>());
      visitor.visit(object);
    }
  }
  graph.shutdown();
  graphDb = new TestGraphDatabaseFactory().newEmbeddedDatabase(new File(path));
  tx = graphDb.beginTx();
  nodeIndex = graphDb.index().getNodeAutoIndexer().getAutoIndex();
  builtGraph = true;
}
 
Example 8
Source File: AbstractOWLOntologyLoader.java    From BioSolr with Apache License 2.0 4 votes vote down vote up
protected void evaluateAllAnnotationsValues(OWLEntity owlEntity) {

        IRI owlEntityIRI = owlEntity.getIRI();
        Set<String> synonyms = new HashSet<>();
        Set<String> definitions = new HashSet<>();
        Set<String> slims = new HashSet<>();

        // loop through other annotations in the imports closure
        for (OWLOntology ontology1 : getManager().getOntologies()) {
            for (OWLAnnotation annotation : owlEntity.getAnnotations(ontology1)) {
                OWLAnnotationProperty property = annotation.getProperty();
                IRI propertyIRI = property.getIRI();

                if (getLabelIRI().equals(propertyIRI)) {
                    addClassLabel(owlEntityIRI, evaluateLabelAnnotationValue(owlEntity, annotation.getValue()).get());
                }
                else if (getSynonymIRIs().contains(propertyIRI)) {
                    synonyms.add(getOWLAnnotationValueAsString(annotation.getValue()).get());
                }
                else if (getDefinitionIRIs().contains(propertyIRI)) {
                    definitions.add(getOWLAnnotationValueAsString(annotation.getValue()).get());
                }
                else if (propertyIRI.equals(Namespaces.OBOINOWL.createIRI("subset_property"))) {
                    slims.add(getOWLAnnotationValueAsString(annotation.getValue()).get());
                }
                else if (propertyIRI.equals(Namespaces.OWL.createIRI("deprecated"))) {
                    addObsoleteTerms(owlEntityIRI);
                }
                else {
                    if (getOWLAnnotationValueAsString(annotation.getValue()).isPresent()) {
                        // initialise maps if first time
                        if (!termAnnotations.containsKey(owlEntityIRI)) {
                            HashMap<IRI, Collection<String>> newMap = new HashMap<>();
                            newMap.put(propertyIRI, new HashSet<>());
                            termAnnotations.put(owlEntityIRI, newMap);
                        }

                        if (!termAnnotations.get(owlEntityIRI).containsKey(propertyIRI)) {
                            termAnnotations.get(owlEntityIRI).put(propertyIRI, new HashSet<>());
                        }

                        termAnnotations.get(owlEntityIRI).get(propertyIRI).add(getOWLAnnotationValueAsString(annotation.getValue()).get());
                    }
                }

            }
        }

        if (synonyms.size() > 0) {
            addSynonyms(owlEntityIRI, synonyms);
        }
        if (definitions.size() >0) {
            addDefinitions(owlEntityIRI, definitions);
        }
        if (slims.size() >0) {
            addSlims(owlEntityIRI, slims);
        }
    }