Java Code Examples for org.semanticweb.owlapi.model.OWLOntology#getObjectPropertiesInSignature()

The following examples show how to use org.semanticweb.owlapi.model.OWLOntology#getObjectPropertiesInSignature() . 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: TaxonomyImpl.java    From quetzal with Eclipse Public License 2.0 6 votes vote down vote up
public static  TaxonomyBuilder<OWLPropertyExpression> buildObjectPropertyHierarchy(NormalizedOWLQLTbox tbox, Collection<? extends OWLPropertyExpression> additionalPropertyExpressions) {
	OWLOntology ont = tbox.getNormalizedOntology();
	OWLDataFactory fac = ont.getOWLOntologyManager().getOWLDataFactory();
	Set< OWLPropertyExpression> props;
	if (additionalPropertyExpressions!=null) {
		props = new HashSet<OWLPropertyExpression>(additionalPropertyExpressions);
		props.addAll(ont.getObjectPropertiesInSignature());
	} else {
		props = new HashSet<OWLPropertyExpression>( ont.getObjectPropertiesInSignature());
	}
	SubPropertyComputation subcomp = new SubPropertyComputation(tbox);
	TaxonomyBuilder<OWLPropertyExpression> taxoBuilder = new TaxonomyBuilder<OWLPropertyExpression>(
			props, 
			fac.getOWLTopObjectProperty(),
			fac.getOWLBottomObjectProperty(),
			subcomp);
	taxoBuilder.build();
	logger.debug("Number of direct subsumption tests performed: {}", subcomp.numOfDirectSubsumptionTests);
	long size = props.size(); 
	logger.debug("Worst Case number of direct subsumption tests performed: {}^2 = {}",size, size*size);
	return taxoBuilder;
}
 
Example 2
Source File: OWLGraphWrapperEdges.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void excludeAllWith(OWLAnnotationProperty ap, OWLOntology o) {
	for (OWLObjectProperty p : o.getObjectPropertiesInSignature(Imports.INCLUDED)) {
		Set<OWLAnnotation> anns = OwlHelper.getAnnotations(p, ap, o);
		for (OWLAnnotation ann : anns) {
			if (ann.getValue() instanceof OWLLiteral) {
				OWLLiteral v = (OWLLiteral) ann.getValue();
				if (v.parseBoolean()) {
					excludeProperty(p);
				}
			}

		}
	}
}
 
Example 3
Source File: OWLGraphWrapperEdges.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void includeAllWith(OWLAnnotationProperty ap, OWLOntology o) {
	for (OWLObjectProperty p : o.getObjectPropertiesInSignature(Imports.INCLUDED)) {
		Set<OWLAnnotation> anns = OwlHelper.getAnnotations(p, ap, o);
		for (OWLAnnotation ann : anns) {
			if (ann.getValue() instanceof OWLLiteral) {
				OWLLiteral v = (OWLLiteral) ann.getValue();
				if (v.parseBoolean()) {
					includeProperty(p);
				}
			}

		}
	}
}
 
Example 4
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);
}