@Override public Set<OWLEquivalentClassesAxiom> next() { compute(); if (!hasNext) { throw new NoSuchElementException(); } isComputed = false; Set<OWLAxiom> axioms = uelModel.renderUnifier(unifier); return axioms.stream().map(axiom -> { if (axiom instanceof OWLEquivalentClassesAxiom) return (OWLEquivalentClassesAxiom) axiom; throw new IllegalStateException("Expected OWLEquivalentClassesAxiom"); }).collect(Collectors.toSet()); }
/** * Check that there is an axiom, which use a class (in its signature) that * has a ancestor in the root term set. * * @param axioms set to check * @param rootTerms set root of terms * @return boolean */ private boolean hasFilterClass(Set<OWLClassAxiom> axioms, Set<OWLClass> rootTerms) { if (axioms != null && !axioms.isEmpty()) { for (OWLClassAxiom ax : axioms) { if (ax instanceof OWLEquivalentClassesAxiom) { Set<OWLClass> signature = ax.getClassesInSignature(); for (OWLClass sigCls : signature) { NodeSet<OWLClass> superClasses = reasoner.getSuperClasses(sigCls, false); for(OWLClass root : rootTerms) { if (superClasses.containsEntity(root)) { return true; } } } } } } return false; }
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); } } } } } }
private OWLClass expressionToClass(OWLClassExpression x) { if (x instanceof OWLClass) return (OWLClass)x; if (this.expressionToClassMap.containsKey(x)) return this.expressionToClassMap.get(x); OWLClass c = owlDataFactory.getOWLClass(IRI.create("http://owlsim.org#"+idNum)); idNum++; OWLEquivalentClassesAxiom eca = owlDataFactory.getOWLEquivalentClassesAxiom(c, x); owlOntologyManager.addAxiom(sourceOntology, eca); expressionToClassMap.put(x, c); // fully fold tbox (AND and SOME only) if (x instanceof OWLObjectIntersectionOf) { for (OWLClassExpression y : ((OWLObjectIntersectionOf)x).getOperands()) { expressionToClass(y); } } else if (x instanceof OWLObjectSomeValuesFrom) { expressionToClass(((OWLObjectSomeValuesFrom)x).getFiller()); } return c; }
public Set<OWLClass> materializeClassExpressionsReferencedBy(OWLObjectProperty p) { Set<OWLClassExpression> xs = new HashSet<OWLClassExpression>(); for (OWLAxiom ax : outputOntology.getReferencingAxioms(p, Imports.INCLUDED)) { if (ax instanceof OWLSubClassOfAxiom) { xs.addAll(getClassExpressionReferencedBy(p, ((OWLSubClassOfAxiom)ax).getSuperClass())); } else if (ax instanceof OWLClassAssertionAxiom) { xs.addAll(getClassExpressionReferencedBy(p, ((OWLClassAssertionAxiom)ax).getClassExpression())); } else if (ax instanceof OWLEquivalentClassesAxiom) { for (OWLClassExpression x : ((OWLEquivalentClassesAxiom)ax).getClassExpressions()) { xs.addAll(getClassExpressionReferencedBy(p,x)); } } } return materializeClassExpressions(xs); }
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! }
OWLEquivalentClassesAxiom unfoldAxiom(OWLEquivalentClassesAxiom ax, OWLClass owlClass) { Set<OWLClassExpression> existing = ax.getClassExpressionsMinus(owlClass); OWLClassExpression ce; if (existing == null || existing.isEmpty()) { return null; } else if (existing.size() == 1) { ce = existing.iterator().next(); } else { ce = factory.getOWLObjectIntersectionOf(existing); } if(LOG.isDebugEnabled()) { LOG.debug("Unfolding axiom: "+ax); } OWLClassExpression unfolded = ce.accept(this); if (unfolded != null) { return factory.getOWLEquivalentClassesAxiom(owlClass, unfolded); } return null; }
/** * 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."); }
@Override public void visit(OWLEquivalentClassesAxiom axiom) { Set<OWLClassExpression> newExpressions = new HashSet<OWLClassExpression>(); boolean changed = false; for (OWLClassExpression ce : axiom.getClassExpressions()) { HandlerResult result = ce.accept(handler); if (result != null) { if (result.remove) { // skip handling and immediately remove and return remove(ontology, axiom); return; } changed = true; newExpressions.add(result.modified); } else { newExpressions.add(ce); } } if (changed) { remove(ontology, axiom); OWLEquivalentClassesAxiom newAxiom = factory.getOWLEquivalentClassesAxiom(newExpressions, axiom.getAnnotations()); add(ontology, newAxiom); } }
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)); } } } } } } } } }
/** * Given a list of equivalent classes axiom, remove all axioms which use a * class from the ignore set. Maps the class to it's identifier via the * given graph. * * @param all * @param ignores * @param graph * @return filtered list */ private List<OWLEquivalentClassesAxiom> filterEquivalentNamedClassPairs( List<OWLEquivalentClassesAxiom> all, Set<String> ignores, OWLGraphWrapper graph) { List<OWLEquivalentClassesAxiom> filtered = new ArrayList<OWLEquivalentClassesAxiom>(all.size()); for (OWLEquivalentClassesAxiom axiom : all) { Set<OWLClass> namedClasses = axiom.getNamedClasses(); boolean add = true; for (OWLClass owlClass : namedClasses) { String id = graph.getIdentifier(owlClass); if (ignores.contains(id)) { add = false; break; } } if (add) { filtered.add(axiom); } } return filtered; }
private void handleIntersection(List<CheckWarning> warnings, Set<OWLOntology> allOntologies, OWLEquivalentClassesAxiom axiom, OWLObjectIntersectionOf intersection, OWLPrettyPrinter pp) { for(OWLClassExpression operand : intersection.getOperandsAsList()) { OWLClass operandCls = null; if (!operand.isAnonymous()) { operandCls = operand.asOWLClass(); } else if (operand instanceof OWLObjectSomeValuesFrom) { OWLObjectSomeValuesFrom ristriction = (OWLObjectSomeValuesFrom) operand; OWLClassExpression filler = ristriction.getFiller(); if (!filler.isAnonymous()) { operandCls = filler.asOWLClass(); } } else { // not translatable to OBO handleGeneric(warnings, allOntologies, axiom, operand, pp); } if (operandCls != null && isDangling(operandCls, allOntologies)) { final IRI iri = operandCls.getIRI(); String message = "Dangling reference "+iri+" in INTERSECTION_OF axiom: "+pp.render(axiom); warnings.add(new CheckWarning(getID(), message , isFatal(), iri, OboFormatTag.TAG_INTERSECTION_OF.getTag())); } } }
private void handleUnionOf(List<CheckWarning> warnings, Set<OWLOntology> allOntologies, OWLEquivalentClassesAxiom axiom, OWLObjectUnionOf union, OWLPrettyPrinter pp) { List<OWLClassExpression> operands = union.getOperandsAsList(); for(OWLClassExpression operand : operands) { if (!operand.isAnonymous()) { OWLClass operandCls = operand.asOWLClass(); if (isDangling(operandCls, allOntologies)) { final IRI iri = operandCls.getIRI(); String message = "Dangling reference "+iri+" in UNION_OF axiom: "+pp.render(axiom); warnings.add(new CheckWarning(getID(), message , isFatal(), iri, OboFormatTag.TAG_UNION_OF.getTag())); } } else { // not translatable to OBO handleGeneric(warnings, allOntologies, axiom, operand, pp); } } }
/** * Check whether a given change is a new or retired description * @param effAdds true if checking additions, false if checking removals * @param man OWL ontology manager * @param ax OWL axiom to be checked * @param newTerms Set of new terms used in this axiom * @param eval Syntactic locality evaluator * @return New or Retired Description-type change, or null if not one * @throws OWLOntologyCreationException Ontology creation exception */ private CategorisedChange checkNewOrRetiredDescription(boolean effAdds, OWLOntologyManager man, OWLAxiom ax, Set<OWLEntity> newTerms, SyntacticLocalityEvaluator eval) throws OWLOntologyCreationException { CategorisedChange change = null; if(!newTerms.isEmpty()) { boolean atomicLhs = true; if(ax instanceof OWLSubClassOfAxiom) { OWLClassExpression c = ((OWLSubClassOfAxiom)ax).getSubClass(); if(c.isAnonymous() || !newTerms.contains(c)) atomicLhs = false; } else if(ax instanceof OWLEquivalentClassesAxiom) atomicLhs = false; if(atomicLhs && !(eval.isLocal(ax, newTerms))) { if(effAdds) change = new CategorisedEffectualAddition(ax, EffectualAdditionCategory.NEWDESCRIPTION, new HashSet<OWLAxiom>(), newTerms); else change = new CategorisedEffectualRemoval(ax, EffectualRemovalCategory.RETIREDDESCRIPTION, new HashSet<OWLAxiom>(), newTerms); } } return change; }
private List<Axiom> transformOWLEquivalentClassesAxiom( OWLEquivalentClassesAxiom a) { List<Axiom> axioms = new ArrayList<Axiom>(); List<OWLClassExpression> exps = a.getClassExpressionsAsList(); int size = exps.size(); for (int i = 0; i < size - 1; i++) { try { OWLClassExpression e1 = exps.get(i); Concept concept1 = getConcept(e1); for (int j = i; j < size; j++) { OWLClassExpression e2 = exps.get(j); if (e1 == e2) continue; Concept concept2 = getConcept(e2); axioms.add(new ConceptInclusion(concept1, concept2)); axioms.add(new ConceptInclusion(concept2, concept1)); } } catch(UnsupportedOperationException e) { problems.add(e.getMessage()); } } return axioms; }
@Override public void registerQuery(OBEPQuery q) { for (OWLEquivalentClassesAxiom eventDef : q.getEventDefinitions()) { manager.addAxiom(ontology, eventDef); eventDef.namedClasses().forEach(def -> eventDefinitions.add(def.getIRI().toString())); } reasoner.flush(); }
public Iterator<Set<OWLEquivalentClassesAxiom>> modifyOntologyAndSolve(OWLOntology positiveProblem, OWLOntology negativeProblem, Set<OWLClass> variables, String algorithmName) { UelModel uelModel = new UelModel(new BasicOntologyProvider(ontologyManager)); uelModel.setupGoal(ontologies, positiveProblem, negativeProblem, owlThingAlias, true); return modifyOntologyAndSolve(uelModel, variables, algorithmName); }
public Iterator<Set<OWLEquivalentClassesAxiom>> modifyOntologyAndSolve(Set<OWLSubClassOfAxiom> subsumptions, Set<OWLEquivalentClassesAxiom> equations, Set<OWLSubClassOfAxiom> dissubsumptions, Set<OWLEquivalentClassesAxiom> disequations, Set<OWLClass> variables, String algorithmName) { UelModel uelModel = new UelModel(new BasicOntologyProvider(ontologyManager)); uelModel.setupGoal(ontologies, subsumptions, equations, dissubsumptions, disequations, owlThingAlias, true); return modifyOntologyAndSolve(uelModel, variables, algorithmName); }
private Iterator<Set<OWLEquivalentClassesAxiom>> modifyOntologyAndSolve(UelModel uelModel, Set<OWLClass> variables, String algorithmName) { uelModel.makeClassesUserVariables(variables); if (markUndefAsVariables) { uelModel.makeAllUndefClassesUserVariables(); } if (verbose) { // output unification problem Goal goal = uelModel.getGoal(); AtomManager atomManager = goal.getAtomManager(); System.out.println("Final number of atoms: " + atomManager.size()); System.out.println("Final number of constants: " + atomManager.getConstants().size()); System.out.println("Final number of variables: " + atomManager.getVariables().size()); System.out.println("Final number of user variables: " + atomManager.getUserVariables().size()); System.out.println("Final number of equations: " + goal.getEquations().size()); System.out.println("Final number of disequations: " + goal.getDisequations().size()); System.out.println("Final number of subsumptions: " + goal.getSubsumptions().size()); System.out.println("Final number of dissubsumptions: " + goal.getDissubsumptions().size()); System.out.println("(Dis-)Unification problem:"); System.out.println(uelModel.printGoal()); } uelModel.initializeUnificationAlgorithm(algorithmName); return new UnifierIterator(uelModel); }
private OWLClassExpression loadDefinition(OWLClass cls) { Set<OWLClassExpression> possibleDefinitions = new HashSet<>(); for (OWLOntology ontology : ontologies) { for (OWLEquivalentClassesAxiom definingAxiom : ontology.getEquivalentClassesAxioms(cls)) { possibleDefinitions.addAll(definingAxiom.getClassExpressionsMinus(cls)); } } if (possibleDefinitions.size() < 1) { return null; } if (possibleDefinitions.size() > 1) { throw new RuntimeException("Multiple candidate definitions found for class: " + cls); } return possibleDefinitions.iterator().next(); }
public void addPositiveAxioms(Set<? extends OWLAxiom> axioms) { for (OWLAxiom axiom : axioms) { if (axiom.isOfType(AxiomType.EQUIVALENT_CLASSES)) { addEquation((OWLEquivalentClassesAxiom) axiom); } else if (axiom.isOfType(AxiomType.SUBCLASS_OF)) { addSubsumption((OWLSubClassOfAxiom) axiom); } else { throw new RuntimeException("Unsupported axiom type: " + axiom); } } }
public void addNegativeAxioms(Set<? extends OWLAxiom> axioms) { for (OWLAxiom axiom : axioms) { if (axiom.isOfType(AxiomType.EQUIVALENT_CLASSES)) { addDisequation((OWLEquivalentClassesAxiom) axiom); } else if (axiom.isOfType(AxiomType.SUBCLASS_OF)) { addDissubsumption((OWLSubClassOfAxiom) axiom); } else { throw new RuntimeException("Unsupported axiom type: " + axiom); } } }
/** * Initializes the unification goal with the given ontologies and axioms. * * @param bgOntologies * a set of background ontologies with definitions * @param subsumptions * the goal subsumptions, as OWLSubClassOfAxioms * @param equations * the goal equations, as binary OWLEquivalentClassesAxioms * @param dissubsumptions * the goal dissubsumptions, as OWLSubClassOfAxioms * @param disequations * the goal disequations, as binary OWLEquivalentClassesAxioms * @param owlThingAlias * (optional) an alias for owl:Thing, e.g., 'SNOMED CT Concept' * @param resetShortFormCache * reset short form cache */ public void setupGoal(Set<OWLOntology> bgOntologies, Set<OWLSubClassOfAxiom> subsumptions, Set<OWLEquivalentClassesAxiom> equations, Set<OWLSubClassOfAxiom> dissubsumptions, Set<OWLEquivalentClassesAxiom> disequations, OWLClass owlThingAlias, boolean resetShortFormCache) { algorithm = null; unifierList = new ArrayList<>(); currentUnifierIndex = -1; allUnifiersFound = false; atomManager = new AtomManagerImpl(); if (resetShortFormCache) { resetShortFormCache(); } OWLClass top = (owlThingAlias != null) ? owlThingAlias : OWLManager.getOWLDataFactory().getOWLThing(); goal = new UelOntologyGoal(atomManager, new UelOntology(atomManager, bgOntologies, top)); goal.addPositiveAxioms(subsumptions); goal.addPositiveAxioms(equations); goal.addNegativeAxioms(dissubsumptions); goal.addNegativeAxioms(disequations); // define top as the empty conjunction OWLDataFactory factory = OWLManager.getOWLDataFactory(); goal.addEquation(factory.getOWLEquivalentClassesAxiom(top, factory.getOWLObjectIntersectionOf())); Integer topId = atomManager.createConceptName(top.toStringID()); atomManager.makeDefinitionVariable(topId); goal.disposeOntology(); if (resetShortFormCache) { cacheShortForms(); } }
public Collection<OWLClass> getChildren(OWLClass parent) { Collection<OWLClass> result = new HashSet<OWLClass>(); for (OWLOntology ont : getRootOntology().getImportsClosure()) { for (OWLAxiom ax : ont.getReferencingAxioms(parent)) { if (ax instanceof OWLSubClassOfAxiom) { OWLSubClassOfAxiom sca = (OWLSubClassOfAxiom) ax; if (!sca.getSubClass().isAnonymous()) { Set<OWLClassExpression> conjuncts = sca.getSuperClass().asConjunctSet(); if (conjuncts.contains(parent)) { result.add(sca.getSubClass().asOWLClass()); } } } else if (ax instanceof OWLEquivalentClassesAxiom) { OWLEquivalentClassesAxiom eca = (OWLEquivalentClassesAxiom) ax; for (OWLClassExpression ce : eca.getClassExpressions()) { if (ce.containsConjunct(parent)) { for (OWLClassExpression sub : eca.getClassExpressions()) { if (!sub.isAnonymous() && !sub.equals(ce)) { result.add(sub.asOWLClass()); } } } } } } } return result; }
@Override public T visit(OWLEquivalentClassesAxiom axiom) { throw new IllegalArgumentException( OWLEquivalentClassesAxiom.class.getSimpleName() + " cannot be converted to " + getTargetClass().getSimpleName()); }
/** * Check that there is an axiom, which use a class (in its signature) that * has a ancestor in the root term set. * * @param axioms set to check * @param rootTerms set root of terms * @return boolean */ private boolean hasFilterClass(OWLEquivalentClassesAxiom axiom, Set<OWLClass> rootTerms) { if (axiom != null) { Set<OWLClass> signature = axiom.getClassesInSignature(); for (OWLClass sigCls : signature) { NodeSet<OWLClass> superClasses = reasoner.getSuperClasses(sigCls, false); for(OWLClass root : rootTerms) { if (superClasses.containsEntity(root)) { return true; } } } } return false; }
/** * Execute the DL query on the given ontology graph. Uses the factory to create * the {@link OWLReasoner} for an internal query ontology. * * @param dlQuery * @param graph * @param reasonerFactory * @return set of {@link OWLClass} which * @throws OWLParserException * @throws OWLOntologyCreationException */ public static Set<OWLClass> executeDLQuery(String dlQuery, OWLGraphWrapper graph, OWLReasonerFactory reasonerFactory) throws OWLParserException, OWLOntologyCreationException { // create parser and parse DL query string ManchesterSyntaxTool parser = null; OWLClassExpression ce; try { parser = new ManchesterSyntaxTool(graph.getSourceOntology(), graph.getSupportOntologySet()); ce = parser.parseManchesterExpression(dlQuery); } finally { // always dispose parser to avoid a memory leak if (parser != null) { parser.dispose(); } } // create query ontology OWLOntologyManager m = OWLManager.createOWLOntologyManager(); OWLOntology queryOntology = m.createOntology(IRI.generateDocumentIRI(), graph.getAllOntologies()); OWLDataFactory f = m.getOWLDataFactory(); OWLClass qc = f.getOWLClass(IRI.create("http://owltools.org/Q")); OWLEquivalentClassesAxiom ax = f.getOWLEquivalentClassesAxiom(ce, qc); m.addAxiom(queryOntology, ax); Set<OWLClass> subset = executeQuery(ce, queryOntology, reasonerFactory); if(subset.isEmpty()) { LOG.warn("No classes found for query subclass of:"+dlQuery); } return subset; }
/** * For every pair X DisjointWith Y, generate an axiom * A and Y = Nothing * * (may become deprecated after Elk supports disjoints) * * @param ont * @param manager * @param dataFactory */ public static void translateDisjointsToEquivalents(OWLOntology ont, OWLOntologyManager manager, OWLDataFactory dataFactory) { for (OWLDisjointClassesAxiom dca : ont.getAxioms(AxiomType.DISJOINT_CLASSES, Imports.INCLUDED)) { for (OWLClassExpression ce1 : dca.getClassExpressions()) { for (OWLClassExpression ce2 : dca.getClassExpressions()) { if (ce1.compareTo(ce2) <= 0) continue; OWLEquivalentClassesAxiom eca = dataFactory.getOWLEquivalentClassesAxiom(dataFactory.getOWLNothing(), dataFactory.getOWLObjectIntersectionOf(ce1, ce2)); manager.addAxiom(ont, eca); // TODO - remove if requested } } } }
public OWLAxiom tr(OWLEquivalentClassesAxiom ax) { Set<OWLClassExpression> xs = new HashSet<OWLClassExpression>(); for (OWLClassExpression x : ax.getClassExpressions()) { OWLClassExpression tx = trx(x, true); if (tx == null) return null; xs.add(tx); } return fac.getOWLEquivalentClassesAxiom(xs); }
/** * Unfold the equivalence axiom of the {@link OWLClass} for the given id. * * @param id OBO-style id * @return unfolded equivalence axiom or null * @throws NonDeterministicUnfoldException */ public OWLEquivalentClassesAxiom unfold(String id) throws NonDeterministicUnfoldException { OWLClass owlClass = graph.getOWLClassByIdentifier(id); if (owlClass == null) { return null; } return unfold(owlClass); }
/** * Unfold the equivalence axiom of the {@link OWLClass} * * @param owlClass * @return unfolded equivalence axiom or null * @throws NonDeterministicUnfoldException */ public OWLEquivalentClassesAxiom unfold(OWLClass owlClass) throws NonDeterministicUnfoldException { Set<OWLEquivalentClassesAxiom> axioms = ontology.getEquivalentClassesAxioms(owlClass); if (axioms == null || axioms.isEmpty()) { return null; } if (axioms.size() > 1) { throw new NonDeterministicUnfoldException("Non deterministic unfold for class: "+owlClass.getIRI()); } final OWLEquivalentClassesAxiom axiom = axioms.iterator().next(); OWLEquivalentClassesAxiom unfolded = visitor.unfoldAxiom(axiom, owlClass); return unfolded; }
/** * Unfold the equivalence axiom of the {@link OWLClass} * * @param owlClass * @return string representation for the unfolded class equivalence axiom or null * @throws NonDeterministicUnfoldException */ public String unfoldToString(OWLClass owlClass) throws NonDeterministicUnfoldException { OWLEquivalentClassesAxiom unfolded = unfold(owlClass); if (unfolded != null) { OWLPrettyPrinter pp = new OWLPrettyPrinter(graph); return pp.render(unfolded); } return null; }
public Set<OWLOntologyChange> tr(OWLAxiom inAxiom, Mapping m) { Set<OWLOntologyChange> chgs = new HashSet<OWLOntologyChange>(); boolean isModified = false; OWLAxiom newAxiom = null; if (inAxiom instanceof OWLEquivalentClassesAxiom) { OWLEquivalentClassesAxiom aa = (OWLEquivalentClassesAxiom)inAxiom; Set<OWLClassExpression> xs = new HashSet<OWLClassExpression>(); for (OWLClassExpression x : aa.getClassExpressions()) { OWLClassExpression x2 = replace(x, m); if (x2 == null) { xs.add(x); } else { isModified = true; xs.add(x2); LOG.info(" TR : "+x+ " ---> "+x2); } } if (isModified) { newAxiom = getOWLDataFactory().getOWLEquivalentClassesAxiom(xs); } } if (isModified) { if (m.isReplace) { chgs.add(new RemoveAxiom(ontology, inAxiom)); } chgs.add(new AddAxiom(ontology, newAxiom)); } return chgs; }
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; }
private OWLClass materializeExpression(OWLClassExpression ce) { UUID uuid = UUID.randomUUID(); OWLClass qc = dataFactory.getOWLClass(IRI.create("http://owltools.org/Q/"+uuid.toString())); manager.removeAxioms(ontology, ontology.getAxioms(qc)); OWLEquivalentClassesAxiom ax = dataFactory.getOWLEquivalentClassesAxiom(ce, qc); manager.addAxiom(ontology, ax); LOG.info("Materialized: "+ax); if (wrappedReasoner != null) getWrappedReasoner().flush(); return qc; }
/** * Remove any {@code OWLEquivalentClassesAxiom} containing an {@code OWLObjectUnionOf} * as class expression, and any {@code OWLSubClassOfAxiom} whose superclass is an * {@code OWLObjectUnionOf}. * * @see #performDefaultModifications() * @see #reverseOWLObjectUnionOfs() */ private void removeOWLObjectUnionOfs() { log.info("Removing OWLEquivalentClassesAxiom or OWLSubClassOfAxiom containig OWLObjectUnionOf..."); for (OWLOntology ont : this.getOwlGraphWrapper().getAllOntologies()) { for (OWLAxiom ax: ont.getAxioms()) { boolean toRemove = false; if (ax instanceof OWLSubClassOfAxiom) { if (((OWLSubClassOfAxiom) ax).getSuperClass() instanceof OWLObjectUnionOf) { toRemove = true; } } else if (ax instanceof OWLEquivalentClassesAxiom) { for (OWLClassExpression ce : ((OWLEquivalentClassesAxiom) ax).getClassExpressions()) { if (ce instanceof OWLObjectUnionOf) { toRemove = true; break; } } } if (toRemove) { ont.getOWLOntologyManager().removeAxiom(ont, ax); } } } this.triggerWrapperUpdate(); log.info("Done removing OWLObjectUnionOfs"); }
private void createEquivModule(String ontologyId, List<OWLEquivalentClassesAxiom> equivalentNamedClassPairs) throws OWLOntologyCreationException, IOException, OWLOntologyStorageException { Set<OWLEntity> signature = new HashSet<OWLEntity>(); for(OWLEquivalentClassesAxiom ax : equivalentNamedClassPairs) { signature.addAll(ax.getClassesInSignature()); } final String moduleName = "equivalent-classes"; createModule(ontologyId, moduleName, signature); }
private void handleEquivalentTo(List<CheckWarning> warnings, Set<OWLOntology> allOntologies, OWLEquivalentClassesAxiom axiom, OWLClass cls, OWLPrettyPrinter pp) { if (isDangling(cls, allOntologies)) { final IRI iri = cls.getIRI(); String message = "Dangling reference "+iri+" in EQUIVALENT_TO axiom: "+pp.render(axiom); warnings.add(new CheckWarning(getID(), message , isFatal(), iri, OboFormatTag.TAG_EQUIVALENT_TO.getTag())); } }
private void handleGeneric(List<CheckWarning> warnings, Set<OWLOntology> allOntologies, OWLEquivalentClassesAxiom axiom, OWLClassExpression ce, OWLPrettyPrinter pp) { Set<OWLClass> classes = ce.getClassesInSignature(); for (OWLClass cls : classes) { if (isDangling(cls, allOntologies)) { final IRI iri = cls.getIRI(); String message = "Dangling reference "+iri+" in axiom: "+pp.render(axiom); warnings.add(new CheckWarning(getID(), message , isFatal(), iri, null)); } } }
@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; }