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

The following examples show how to use org.semanticweb.owlapi.model.OWLOntology#getEquivalentClassesAxioms() . 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: CompositionalClassPredictor.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void buildSimpleDefMap() {
	simpleDefMap = new HashMap<OWLClass,Set<OWLClassExpression>>();
	OWLOntology o = getGraph().getSourceOntology();
	for (OWLClass c : o.getClassesInSignature()) {
		for (OWLEquivalentClassesAxiom eca : o.getEquivalentClassesAxioms(c)) {
			Set<OWLClassExpression> elts = new HashSet<OWLClassExpression>();
			for (OWLClassExpression x : eca.getClassExpressions()) {
				// assume one logical definitionper class - otherwise choose arbitrary
				if (x instanceof OWLObjectIntersectionOf) {
					if (getReachableOWLClasses(x, elts) && elts.size() > 0) {
						//LOG.info(c+" def= "+elts);
						simpleDefMap.put(c, elts);						
					}
				}
			}
		}
	}
}
 
Example 2
Source File: TBoxUnFoldingTool.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
UnfoldingVisitor(Set<OWLClass> unfoldClasses, OWLOntology ontology) throws NonDeterministicUnfoldException {
	this.unfoldClasses = new HashMap<OWLClass, OWLClassExpression>();
	factory = ontology.getOWLOntologyManager().getOWLDataFactory();
	
	for(OWLClass owlClass : unfoldClasses) {
		Set<OWLEquivalentClassesAxiom> eqAxioms = ontology.getEquivalentClassesAxioms(owlClass);
		if (eqAxioms != null && !eqAxioms.isEmpty()) {
			if(eqAxioms.size() > 1) {
				throw new NonDeterministicUnfoldException("Non deterministic unfold for class: "+owlClass.getIRI());
			}
			OWLEquivalentClassesAxiom eqAxiom = eqAxioms.iterator().next();
			Set<OWLClassExpression> expressions = eqAxiom.getClassExpressionsMinus(owlClass);
			if (expressions.size() == 1) {
				this.unfoldClasses.put(owlClass, expressions.iterator().next());
			}
			else if (expressions.size() > 1) {
				OWLClassExpression ce = factory.getOWLObjectIntersectionOf(expressions);
				this.unfoldClasses.put(owlClass, ce);
			}
		}
	}
	
	// TODO check that there are no cycles in the unfold expressions, otherwise this unfold will not terminate!
}
 
Example 3
Source File: OWLGraphManipulator.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Reverse all {@code OWLObjectUnionOf}s, that are operands in 
 * an {@code OWLEquivalentClassesAxiom}, into individual {@code OWLSubClassOfAxiom}s, where 
 * the classes part of the {@code OWLObjectUnionOf} become subclasses, and 
 * the original first operand of the {@code OWLEquivalentClassesAxiom} superclass. 
 * <p>
 * Note that such {@code OWLEquivalentClassesAxiom}s are not removed from the ontology, 
 * only {@code OWLSubClassOfAxiom}s are added. The axioms containing 
 * {@code OWLObjectUnionOf}s will be removed by calling {@link #removeOWLObjectUnionOfs()}, 
 * in order to give a chance to {@link #convertEquivalentClassesToSuperClasses()} 
 * to do its job before.
 * 
 * @see #performDefaultModifications()
 * @see #removeOWLObjectUnionOfs()
 * @see #convertEquivalentClassesToSuperClasses()
 */
private void reverseOWLObjectUnionOfs() {
    log.info("Reversing OWLObjectUnionOfs into OWLSubClassOfAxioms");
    for (OWLOntology ont : this.getOwlGraphWrapper().getAllOntologies()) {
        for (OWLClass cls : ont.getClassesInSignature()) {
            for (OWLEquivalentClassesAxiom eca : ont.getEquivalentClassesAxioms(cls)) {
                for (OWLClassExpression ce : eca.getClassExpressions()) {
                    if (ce instanceof OWLObjectUnionOf) {
                        for (OWLObject child : ((OWLObjectUnionOf)ce).getOperands()) {
                            //we reverse only named classes
                            if (child instanceof OWLClass) {
                                this.getOwlGraphWrapper().getManager().addAxiom(ont, 
                                        ont.getOWLOntologyManager().getOWLDataFactory().
                                            getOWLSubClassOfAxiom((OWLClass) child, cls));
                            }
                        }
                    }
                }
            }
        }
    }
    this.triggerWrapperUpdate();
    log.info("OWLObjectUnionOf reversion done.");
}
 
Example 4
Source File: OWLGraphWrapperEdges.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void cacheReverseUnionMap() {
	synchronized (edgeCacheMutex) {
	    extraSubClassOfEdges = new HashMap<OWLObject, Set<OWLGraphEdge>>();
           if (!config.isGraphReasonedAndRelaxed) {
	        for (OWLOntology o : getAllOntologies()) {
	            for (OWLClass cls : o.getClassesInSignature()) {
	                for (OWLEquivalentClassesAxiom eca : o.getEquivalentClassesAxioms(cls)) {
	                    for (OWLClassExpression ce : eca.getClassExpressions()) {
	                        if (ce instanceof OWLObjectUnionOf) {
	                            for (OWLObject child : ((OWLObjectUnionOf)ce).getOperands()) {
	                                if (!extraSubClassOfEdges.containsKey(child)) {
	                                    extraSubClassOfEdges.put(child, new OWLGraphEdgeSet());
	                                }
	                                extraSubClassOfEdges.get(child).add(
	                                        createSubClassOfEdge(child,cls,o,eca));
	                            }
	                        }
	                    }
	                }
	            }
	        }
	    }
	}
}
 
Example 5
Source File: OwlHelper.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static Set<OWLClassExpression> getEquivalentClasses(OWLClass cls, OWLOntology ont) {
	Set<OWLClassExpression> expressions;
	if (cls != null && ont != null) {
		Set<OWLEquivalentClassesAxiom> axioms = ont.getEquivalentClassesAxioms(cls);
		expressions = new HashSet<>(axioms.size());
		for(OWLEquivalentClassesAxiom ax : axioms) {
			expressions.addAll(ax.getClassExpressions());
		}
		expressions.remove(cls); // set should not contain the query cls
	}
	else {
		expressions = Collections.emptySet();
	}
	return expressions;
}
 
Example 6
Source File: SelfReferenceInDefinition.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public Collection<CheckWarning> check(OWLGraphWrapper graph, Collection<OWLObject> allOwlObjects) {
	OWLOntology ontology = graph.getSourceOntology();
	List<CheckWarning> violations = new ArrayList<CheckWarning>();
	for(OWLClass cls : ontology.getClassesInSignature()) {
		Set<OWLEquivalentClassesAxiom> equivalentClassesAxioms = ontology.getEquivalentClassesAxioms(cls);
		if (equivalentClassesAxioms != null && !equivalentClassesAxioms.isEmpty()) {
			for (OWLEquivalentClassesAxiom owlEquivalentClassesAxiom : equivalentClassesAxioms) {
				for (OWLClassExpression ex : owlEquivalentClassesAxiom.getClassExpressions()) {
					if (ex instanceof OWLClass)
						continue;
					Set<OWLClass> classesInSignature = ex.getClassesInSignature();
					if (classesInSignature != null && classesInSignature.contains(cls)) {
						String id = graph.getIdentifier(cls);
						String message = "Class "+id+" has a self reference in its logical definition: "+owlEquivalentClassesAxiom;
						CheckWarning warning = new CheckWarning("Self_Reference_In_Definition", message , isFatal(), cls.getIRI());
						violations.add(warning);
					}
				}
			}
		}
	}
	if (!violations.isEmpty()) {
		return violations;
	}
	return null;
}
 
Example 7
Source File: LinkMaker.java    From owltools with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Search for the first class with a matching equivalent class definition. 
 * 
 * @param c
 * @param genus
 * @param relation
 * @return match or null
 */
private OWLClass hasMatchingIntersection(OWLClass c, OWLClass genus, OWLObjectProperty relation) {
	for(OWLOntology o : allOntologies) {
		Set<OWLEquivalentClassesAxiom> eqAxioms = o.getEquivalentClassesAxioms(c);
		for (OWLEquivalentClassesAxiom eqAxiom : eqAxioms) {
			Set<OWLClassExpression> expressions = eqAxiom.getClassExpressionsMinus(c);
			for (OWLClassExpression expression : expressions) {
				if (expression instanceof OWLObjectIntersectionOf) {
					OWLObjectIntersectionOf intersection = (OWLObjectIntersectionOf) expression;
					OWLClass differentiaCls = null;
					boolean matchesGenus = false;
					boolean matchesRelation = false;
					Set<OWLClassExpression> operands = intersection.getOperands();
					if (operands.size() == 2) {
						for (OWLClassExpression operand : operands) {
							if (operand.isAnonymous() == false) {
								OWLClass currentGenus = operand.asOWLClass();
								if (genus.equals(currentGenus)) {
									matchesGenus = true;
								}
							}
							else if (operand instanceof OWLObjectSomeValuesFrom) {
								OWLObjectSomeValuesFrom differentia = (OWLObjectSomeValuesFrom) operand;
								if (relation.equals(differentia.getProperty())) {
									matchesRelation = true;
									OWLClassExpression filler = differentia.getFiller();
									if (!filler.isAnonymous() && !filler.isOWLNothing() && !filler.isOWLThing()) {
										differentiaCls = filler.asOWLClass();
									}
								}
							}
						}
						if (matchesGenus && matchesRelation ) {
							 return differentiaCls;
						}
					}
				}
			}
		}
	}
	return null;
}