/** * OWLDisjointAxiom(A,B,C) * @param reasoner * @param ontology * @param cls * @return */ public static OWLClassNodeSet getExplicitOWLDisjointnessAxioms(OWLReasoner reasoner, OWLOntology ontology, OWLClass cls){ OWLClassNodeSet nodeSet = new OWLClassNodeSet(); for (OWLDisjointClassesAxiom ax : ontology.getDisjointClassesAxioms(cls)) { for (OWLClassExpression op : ax.getClassExpressions()) { if (!op.isAnonymous() && !op.equals(cls)) { //Op must be differnt to ce nodeSet.addNode(reasoner.getEquivalentClasses(op)); } } } return nodeSet; }
public NodeSet<OWLClass> getDisjointClasses(OWLClassExpression ce) { ensurePrepared(); OWLClassNodeSet nodeSet = new OWLClassNodeSet(); if (!ce.isAnonymous()) { for (OWLOntology ontology : getRootOntology().getImportsClosure()) { for (OWLDisjointClassesAxiom ax : ontology.getDisjointClassesAxioms(ce.asOWLClass())) { for (OWLClassExpression op : ax.getClassExpressions()) { if (!op.isAnonymous()) { nodeSet.addNode(getEquivalentClasses(op)); } } } } } return nodeSet; }
@Override public void visit(OWLDisjointClassesAxiom axiom) { List<OWLClassExpression> disjointClasses = axiom.getClassExpressionsAsList(); for(int i = 0; i < disjointClasses.size(); i++){ sparql += "{"; OWLClassExpression ce = disjointClasses.remove(i); sparql += expressionConverter.asGroupGraphPattern(ce, subjectVar); for (OWLClassExpression ce2 : disjointClasses) { sparql += notExists(expressionConverter.asGroupGraphPattern(ce2, subjectVar)); } disjointClasses.add(i, ce); sparql += "}"; if(i < disjointClasses.size()-1){ sparql += " UNION "; } } }
private Axiom transformOWLDisjointClassesAxiom(OWLDisjointClassesAxiom a) { try { List<OWLClassExpression> exps = a.getClassExpressionsAsList(); List<Concept> concepts = new ArrayList<Concept>(); for (OWLClassExpression exp : exps) { concepts.add(getConcept(exp)); } Concept[] conjs = new Concept[concepts.size()]; int i = 0; for (; i < concepts.size(); i++) { conjs[i] = concepts.get(i); } return new ConceptInclusion(new Conjunction(conjs), NamedConcept.BOTTOM_CONCEPT); } catch(UnsupportedOperationException e) { problems.add(e.getMessage()); return null; } }
/** * Adds a given attribute to the attributes of this context, updates the 'local' set of objects. * @param attribute the attribute to be added * @return <code>true</code> if the <code>attribute</code> is successfully added * @throws IllegalAttributeException if the given attribute is already in the set of * attributes */ @Override public boolean addAttribute(OWLClass attribute) { boolean added = getAttributes().add(attribute); if (!added) { throw new IllegalAttributeException("Attribute " + attribute + " has already been added"); } try { for (OWLNamedIndividual individual : getReasoner().getInstances(attribute, false).getFlattened()) { IndividualObject o = createIndividualObject(individual); o.getDescription().addAttribute(attribute); addObject(o); } // the CEL reasoner is being used // add new concept name for the complement of the added attribute OWLClass complementOfAttribute = ELIndividualObject.getComplement(getOntology(), attribute); // make them disjoint Set<OWLClass> disjoint = new HashSet<OWLClass>(); disjoint.add(attribute); disjoint.add(complementOfAttribute); OWLDisjointClassesAxiom disjointnessAxiom = getFactory().getOWLDisjointClassesAxiom(disjoint); // create a new AddAxiom object AddAxiom addAxiom = new AddAxiom(getOntology(),disjointnessAxiom); getManager().applyChange(addAxiom); reClassifyOntology(); //TODO // updateObjectDescriptions should be overridden for EL contexts updateObjectDescriptions(Constants.AFTER_MODIFICATION); } catch (OWLOntologyChangeException e) { e.printStackTrace(); System.exit(-1); } return added; }
public void visit(OWLDisjointClassesAxiom axiom) { if (axiom.getClassExpressions().size()<=1) { throw new IllegalArgumentException("Error: Parsed "+axiom.toString()+". A DisjointClasses axiom in OWL 2 DL must have at least two classes as parameters. "); } OWLClassExpression[] descriptions=new OWLClassExpression[axiom.getClassExpressions().size()]; axiom.getClassExpressions().toArray(descriptions); for (int i=0;i<descriptions.length;i++) descriptions[i]=m_expressionManager.getComplementNNF(descriptions[i]); for (int i=0;i<descriptions.length;i++) for (int j=i+1;j<descriptions.length;j++) m_classExpressionInclusionsAsDisjunctions.add(new OWLClassExpression[] { descriptions[i],descriptions[j] }); }
public Boolean visit(OWLDisjointClassesAxiom axiom) { int n=axiom.getClassExpressions().size(); OWLClassExpression[] classes=axiom.getClassExpressions().toArray(new OWLClassExpression[n]); for (int i=0;i<n-1;i++) { for (int j=i+1;j<n;j++) { OWLClassExpression notj=factory.getOWLObjectComplementOf(classes[j]); if (!reasoner.isSubClassOf(classes[i],notj)) return Boolean.FALSE; } } return Boolean.TRUE; }
@Override public T visit(OWLDisjointClassesAxiom axiom) { throw new IllegalArgumentException( OWLDisjointClassesAxiom.class.getSimpleName() + " cannot be converted to " + getTargetClass().getSimpleName()); }
/** * 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 } } } }
/** * Smth like: * A subClassOf B * A subClassOf C * C disjoint with B * ... */ public void testUnsatisfiabilityDueToConflictingAxioms1() { OWLDataFactory factory = OWLManager.getOWLDataFactory(); OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); OWLClassExpression classA = factory.getOWLClass(IRI.create(String.format("%s#%s", PREFIX, "A"))); OWLClassExpression classB = factory.getOWLClass(IRI.create(String.format("%s#%s", PREFIX, "B"))); OWLClassExpression classC = factory.getOWLClass(IRI.create(String.format("%s#%s", PREFIX, "C"))); OWLNamedIndividual indiv = factory.getOWLNamedIndividual(IRI.create(String.format("%s#%s", PREFIX, "a"))); OWLIndividualAxiom fact1 = factory.getOWLClassAssertionAxiom(classA, indiv); OWLSubClassOfAxiom axmAsubB = factory.getOWLSubClassOfAxiom(classA, classB); OWLSubClassOfAxiom axmAsubC = factory.getOWLSubClassOfAxiom(classA, classC); OWLDisjointClassesAxiom axmBdisC = factory.getOWLDisjointClassesAxiom(classB, classC); try { OWLOntology ontology = manager.createOntology(); manager.addAxiom(ontology, fact1); manager.addAxiom(ontology, axmAsubB); manager.addAxiom(ontology, axmAsubC); manager.addAxiom(ontology, axmBdisC); Wolpertinger wolpertinger = new Wolpertinger(ontology); assertFalse(wolpertinger.isConsistent()); } catch (OWLOntologyCreationException e) { e.printStackTrace(); fail(); } }
@Override public Set<ComplexIntegerAxiom> visit(OWLDisjointClassesAxiom axiom) throws TranslationException { Objects.requireNonNull(axiom); Set<OWLClassExpression> classExpressionSet = axiom.getClassExpressions(); Set<IntegerClassExpression> classIdSet = new HashSet<>(); classExpressionSet.forEach(classExpression -> classIdSet.add(translateClassExpression(classExpression))); ComplexIntegerAxiom ret = getAxiomFactory().createDisjointClassesAxiom(classIdSet, translateAnnotations(axiom.getAnnotations())); return Collections.singleton(ret); }
@Override public Void visit(OWLDisjointClassesAxiom axiom) { List<Long> nodes = transform(axiom.getClassExpressionsAsList(), new Function<OWLClassExpression, Long>() { @Override public Long apply(OWLClassExpression individual) { return getOrCreateNode(getIri(individual)); } }); getOrCreateRelationshipPairwise(nodes, OwlRelationships.OWL_DISJOINT_WITH); return null; }
@Test public void doesNotReason_whenOntologyIsInconsistent() throws Exception{ OWLClass c0 = dataFactory.getOWLClass(IRI.generateDocumentIRI()); OWLClass c1 = dataFactory.getOWLClass(IRI.generateDocumentIRI()); OWLDisjointClassesAxiom disjoint = dataFactory.getOWLDisjointClassesAxiom(c0, c1); OWLIndividual i1 = dataFactory.getOWLNamedIndividual(IRI.generateDocumentIRI()); OWLClassAssertionAxiom a1 = dataFactory.getOWLClassAssertionAxiom(c0, i1); OWLClassAssertionAxiom a2 = dataFactory.getOWLClassAssertionAxiom(c1, i1); manager.addAxioms(ont, newHashSet(disjoint, a1, a2)); util.flush(); assertThat(util.shouldReason(), is(false)); }
@Override public OWLAxiom visit(OWLDisjointClassesAxiom axiom) { Set<OWLClassExpression> ops = new HashSet<>(); for (OWLClassExpression op : axiom.getClassExpressions()) { ops.add(op.accept(this)); } return dataFactory.getOWLDisjointClassesAxiom(ops); }
@Override public Set<OWLClassExpression> visit(OWLDisjointClassesAxiom axiom) { Set<OWLClassExpression> result = new HashSet<>(); for (OWLClassExpression ce : axiom.getClassExpressions()) { result.addAll(ce.accept(this)); } return result; }
@Override public void visit(@Nonnull OWLDisjointClassesAxiom axiom) { for (OWLClassExpression desc : axiom.getClassExpressions()) { desc.accept(this); } processAxiomAnnotations(axiom); }
/** * Given a set of axioms, remove unary disjointness axioms * @param set Set of axioms to analyse * @return Set of axioms without unary disjointness axioms */ private Set<OWLAxiom> normalize(Set<OWLAxiom> set) { Set<OWLAxiom> toRemove = new HashSet<OWLAxiom>(); for(OWLAxiom ax : set) { if(ax.isOfType(AxiomType.DISJOINT_CLASSES)) { OWLDisjointClassesAxiom dis = (OWLDisjointClassesAxiom)ax; if(dis.getClassesInSignature().size() < 2) toRemove.add(ax); } } set.removeAll(toRemove); return set; }
/** * Remove unary disjointness axioms from the given ontology * @param ont OWL ontology */ private void removeUnaryDisjointnessAxioms(OWLOntology ont) { List<RemoveAxiom> toRemove = new ArrayList<RemoveAxiom>(); for(OWLAxiom ax : ont.getAxioms(AxiomType.DISJOINT_CLASSES)) { OWLDisjointClassesAxiom dis = (OWLDisjointClassesAxiom)ax; if(dis.getClassesInSignature().size() < 2) toRemove.add(new RemoveAxiom(ont, ax)); } ont.getOWLOntologyManager().applyChanges(toRemove); }
public void visit(OWLDisjointClassesAxiom axiom) { notSupported(axiom); }
public void visit(OWLDisjointClassesAxiom axiom) { }
@Override public OWLDisjointClassesAxiom visit(ElkDisjointClassesAxiom axiom) { return owlFactory_.getOWLDisjointClassesAxiom( toClassExpressionSet(axiom.getClassExpressions())); }
@Override public ElkClassAxiom visit(OWLDisjointClassesAxiom owlDisjointClasses) { return CONVERTER.convert(owlDisjointClasses); }
@SuppressWarnings("static-method") public ElkDisjointClassesAxiom convert( OWLDisjointClassesAxiom owlDisjointClassesAxiom) { return new ElkDisjointClassesAxiomWrap<OWLDisjointClassesAxiom>( owlDisjointClassesAxiom); }
@Override public ElkAxiom visit(OWLDisjointClassesAxiom owlDisjointClasses) { return CONVERTER.convert(owlDisjointClasses); }
@Override public void visit(OWLDisjointClassesAxiom axiom) { defaultVisit(axiom); }
@Override public OWLAxiom visit(OWLDisjointClassesAxiom axiom) { return factory.getOWLDisjointClassesAxiom(axiom.getClassExpressions(), annotations); }
@Override public void visit(OWLDisjointClassesAxiom axiom) { }
private OWLOntology createSimpleGraphColoring() { OWLOntology ontoColoring = null; OWLDataFactory factory = OWLManager.getOWLDataFactory(); OWLOntologyManager manager = OWLManager.createOWLOntologyManager(); OWLObjectPropertyExpression edgeProp = factory.getOWLObjectProperty(IRI.create(String.format("%s#%s", PREFIX, "edge"))); OWLClassExpression classNode = factory.getOWLClass(IRI.create(String.format("%s#%s", PREFIX, "Node"))); OWLClassExpression classBlue = factory.getOWLClass(IRI.create(String.format("%s#%s", PREFIX, "Blue"))); OWLClassExpression classRed = factory.getOWLClass(IRI.create(String.format("%s#%s", PREFIX, "Red"))); OWLClassExpression classGreen = factory.getOWLClass(IRI.create(String.format("%s#%s", PREFIX, "Green"))); OWLNamedIndividual indNode1 = factory.getOWLNamedIndividual(IRI.create(String.format("%s#%s", PREFIX, "node1"))); OWLNamedIndividual indNode2 = factory.getOWLNamedIndividual(IRI.create(String.format("%s#%s", PREFIX, "node2"))); OWLNamedIndividual indNode3 = factory.getOWLNamedIndividual(IRI.create(String.format("%s#%s", PREFIX, "node3"))); OWLNamedIndividual indNode4 = factory.getOWLNamedIndividual(IRI.create(String.format("%s#%s", PREFIX, "node4"))); // now the facts // nodes OWLIndividualAxiom axmNodeInst4 =factory.getOWLClassAssertionAxiom(classNode, indNode4); OWLIndividualAxiom axmNodeInst3 =factory.getOWLClassAssertionAxiom(classNode, indNode3); OWLIndividualAxiom axmNodeInst2 =factory.getOWLClassAssertionAxiom(classNode, indNode2); OWLIndividualAxiom axmNodeInst1 =factory.getOWLClassAssertionAxiom(classNode, indNode1); // 1 // | \ // | 3 - 4 // | / // 2 // OWLIndividualAxiom axmEdge12 = factory.getOWLObjectPropertyAssertionAxiom(edgeProp, indNode1, indNode2); OWLIndividualAxiom axmEdge13 = factory.getOWLObjectPropertyAssertionAxiom(edgeProp, indNode1, indNode3); OWLIndividualAxiom axmEdge23 = factory.getOWLObjectPropertyAssertionAxiom(edgeProp, indNode2, indNode3); OWLIndividualAxiom axmEdge34 = factory.getOWLObjectPropertyAssertionAxiom(edgeProp, indNode3, indNode4); // symmetry of edge property OWLObjectPropertyAxiom axmEdgeSym = factory.getOWLSymmetricObjectPropertyAxiom(edgeProp); // axioms OWLObjectUnionOf exprColorUnion = factory.getOWLObjectUnionOf(classBlue, classRed, classGreen); OWLSubClassOfAxiom axmNodeColorings = factory.getOWLSubClassOfAxiom(classNode, exprColorUnion); // coloring constraints OWLSubClassOfAxiom axmRedConstraint = factory.getOWLSubClassOfAxiom(classRed, factory.getOWLObjectAllValuesFrom(edgeProp, factory.getOWLObjectUnionOf(classGreen, classBlue))); OWLSubClassOfAxiom axmBlueConstraint = factory.getOWLSubClassOfAxiom(classBlue, factory.getOWLObjectAllValuesFrom(edgeProp, factory.getOWLObjectUnionOf(classGreen, classRed))); OWLSubClassOfAxiom axmGreenConstraint = factory.getOWLSubClassOfAxiom(classGreen, factory.getOWLObjectAllValuesFrom(edgeProp, factory.getOWLObjectUnionOf(classRed, classBlue))); OWLDisjointClassesAxiom axmDisColors = factory.getOWLDisjointClassesAxiom(classRed, classBlue, classGreen); try { ontoColoring = manager.createOntology(); manager.addAxiom(ontoColoring, axmNodeInst1); manager.addAxiom(ontoColoring, axmNodeInst2); manager.addAxiom(ontoColoring, axmNodeInst3); manager.addAxiom(ontoColoring, axmNodeInst4); manager.addAxiom(ontoColoring, axmEdge12); manager.addAxiom(ontoColoring, axmEdge13); manager.addAxiom(ontoColoring, axmEdge23); manager.addAxiom(ontoColoring, axmEdge34); manager.addAxiom(ontoColoring, axmEdgeSym); manager.addAxiom(ontoColoring, axmNodeColorings); manager.addAxiom(ontoColoring, axmRedConstraint); manager.addAxiom(ontoColoring, axmBlueConstraint); manager.addAxiom(ontoColoring, axmGreenConstraint); manager.addAxiom(ontoColoring, axmDisColors); } catch (OWLOntologyCreationException e) { e.printStackTrace(); } return ontoColoring; }
@Override public Boolean visit(OWLDisjointClassesAxiom axiom) { return true; }
@Override public Boolean visit(OWLDisjointClassesAxiom axiom) { return false; }
@Override public Boolean visit(OWLDisjointClassesAxiom axiom) { Objects.requireNonNull(axiom); return add(this.df.getOWLDisjointClassesAxiom(axiom.getClassExpressions(), reg(axiom.getAnnotations()))); }
@Override public Boolean visit(OWLDisjointClassesAxiom axiom) { Objects.requireNonNull(axiom); return add(this.df.getOWLDisjointClassesAxiom(axiom.getClassExpressions(), annot())); }
@Override public void visit(OWLDisjointClassesAxiom axiom) { ignoreOwlAxiom("DisjointClass", axiom); }
@Override public O visit(OWLDisjointClassesAxiom axiom) { return doDefault(axiom); }
@Override public void visit(OWLDisjointClassesAxiom axiom) { type = AXIOM_TYPE_INDEX_BASE + axiom.getAxiomType().getIndex(); }
@Override public void visit(OWLDisjointClassesAxiom axiom) { hashCode = primes[8]; hashCode = hashCode * MULT + axiom.getClassExpressions().hashCode(); hashCode = hashCode * MULT + axiom.getAnnotations().hashCode(); }