/** * A ^ B -> bottom * @param reasoner * @param ontology * @param cls * @author Shuo Zhang * @return */ public static OWLClassNodeSet getExplicitDLDisjointnessAxioms(OWLReasoner reasoner, OWLOntology ontology, OWLClass cls){ OWLClassNodeSet nodeSet = new OWLClassNodeSet(); OWLClassExpression subExp; Set<OWLClassExpression> set; for (OWLSubClassOfAxiom sax : ontology.getSubClassAxiomsForSuperClass(OWLManager.getOWLDataFactory().getOWLNothing())) { subExp = sax.getSubClass(); if (subExp instanceof OWLObjectIntersectionOf) { set = subExp.asConjunctSet(); if (set.contains(cls) && set.size() == 2) { for (OWLClassExpression op : set) { if (!op.equals(cls) && !op.isAnonymous()) { nodeSet.addNode(reasoner.getEquivalentClasses(op)); break; } } } } } return nodeSet; }
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); } } } } } }
/** * generates a LCS expression and makes it a class if it is a class expression * * @param a * @param b * @return named class representing LCS */ public OWLClass getLowestCommonSubsumerClass(OWLClassExpression a, OWLClassExpression b) { OWLClassExpressionPair pair = new OWLClassExpressionPair(a,b); if (lcsCache.containsKey(pair)) { return lcsCache.get(pair); } OWLClassExpression x = getLowestCommonSubsumer(a,b); OWLClass lcs; if (lcsExpressionToClass.containsKey(x)) { lcs = lcsExpressionToClass.get(x); } if (x instanceof OWLClass) lcs = (OWLClass)x; else if (x instanceof OWLObjectIntersectionOf) lcs = makeClass((OWLObjectIntersectionOf) x); else lcs = null; lcsCache.put(pair, lcs); return lcs; }
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; }
/** * generates a LCS expression and makes it a class if it is a class expression * * @param a * @param b * @param leafClasses * @return named class representing LCS */ public OWLClass getLowestCommonSubsumerClass(OWLClassExpression a, OWLClassExpression b, Set<OWLClass> leafClasses) { OWLClassExpressionPair pair = new OWLClassExpressionPair(a,b); if (lcsCache.containsKey(pair)) { return lcsCache.get(pair); } OWLClassExpression x = getLowestCommonSubsumer(a,b,leafClasses); OWLClass lcs; /* if (lcsExpressionToClass.containsKey(x)) { lcs = lcsExpressionToClass.get(x); } */ if (x instanceof OWLClass) lcs = (OWLClass)x; else if (x instanceof OWLObjectIntersectionOf) lcs = makeClass((OWLObjectIntersectionOf) x); else lcs = null; lcsCache.put(pair, lcs); //LOG.info("LCS of "+a+" + "+b+" = "+lcs); return lcs; }
private void gatherProperties(OWLClassExpression x) { if (x instanceof OWLClass) { return; } else if (x instanceof OWLObjectIntersectionOf) { for (OWLClassExpression y : ((OWLObjectIntersectionOf)x).getOperands()) { gatherProperties(y); } } else if (x instanceof OWLObjectSomeValuesFrom) { OWLObjectSomeValuesFrom svf = (OWLObjectSomeValuesFrom)x; gatherProperties(svf.getProperty()); gatherProperties(svf.getFiller()); } else { // } }
public Expression makeExpression(OWLClassExpression x) { if (x.isAnonymous()) { if (x instanceof OWLObjectIntersectionOf) { return makeIntersectionOf((OWLObjectIntersectionOf)x); } else if (x instanceof OWLObjectSomeValuesFrom) { return makeSomeValuesFrom((OWLObjectSomeValuesFrom)x); } else { return null; } } else { return makeClassStub(x); } }
@Override public HandlerResult visit(OWLObjectIntersectionOf intersectionOf) { Set<OWLClassExpression> newOperands = new HashSet<OWLClassExpression>(); boolean changed = false; for (OWLClassExpression ce : intersectionOf.getOperands()) { HandlerResult handlerResult = ce.accept(this); if (handlerResult != null) { if (handlerResult.remove) { return HandlerResult.remove(); } changed = true; newOperands.add(handlerResult.modified); } else { newOperands.add(ce); } } if (changed) { if (newOperands.size() == 1) { return HandlerResult.modified(newOperands.iterator().next()); } return HandlerResult.modified(factory.getOWLObjectIntersectionOf(newOperands)); } return null; }
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())); } } }
public String getNextPossibleSymptom() { OWLClass disease = model.getClass("Disease"); OWLObjectUnionOf allDiseases = model.getDataFactory().getOWLObjectUnionOf(model.getSubOfExpression(disease)); OWLObjectIntersectionOf intersectionOfSelected = getIntersectionOfSelected(); OWLObjectUnionOf unionOfSubSelected = model.getDataFactory().getOWLObjectUnionOf(model.getSubOfExpression(intersectionOfSelected)); OWLObjectIntersectionOf possibleDiseasesIntersection = model.getDataFactory().getOWLObjectIntersectionOf(allDiseases, unionOfSubSelected); Set<OWLClass> possibleDiseases = model.getSubOfExpression(possibleDiseasesIntersection); possibleDiseases.addAll(model.getEquivalentOfExpression(possibleDiseasesIntersection)); possibleDiseases.remove(model.getDataFactory().getOWLNothing()); Set<OWLClass> possibleSymptoms = new TreeSet<OWLClass>(); Iterator<OWLClass> possibleDiseasesIterator = possibleDiseases.iterator(); while (possibleDiseasesIterator.hasNext()) { OWLClass next = possibleDiseasesIterator.next(); possibleSymptoms.addAll(model.getSuperOfExpression(next)); } possibleSymptoms.remove(model.getDataFactory().getOWLThing()); possibleSymptoms.remove(model.getClass("Disease")); possibleSymptoms.removeAll(selectedSymptoms); possibleSymptoms.removeAll(notSelectedSymptoms); System.out.println(possibleDiseases); if(possibleSymptoms.size()!=0 && possibleDiseases.size()>1) return (new SimpleShortFormProvider().getShortForm((OWLClass)possibleSymptoms.toArray()[0])).substring(7); else return null; }
public String getPossibleDisease(){ OWLClass disease = model.getClass("Disease"); OWLObjectUnionOf allDiseases = model.getDataFactory().getOWLObjectUnionOf(model.getSubOfExpression(disease)); OWLObjectIntersectionOf intersectionOfSelected = getIntersectionOfSelected(); OWLObjectUnionOf unionOfSubSelected = model.getDataFactory().getOWLObjectUnionOf(model.getSubOfExpression(intersectionOfSelected)); OWLObjectIntersectionOf possibleDiseasesIntersection = model.getDataFactory().getOWLObjectIntersectionOf(allDiseases, unionOfSubSelected); Set<OWLClass> possibleDiseases = model.getSubOfExpression(possibleDiseasesIntersection); possibleDiseases.addAll(model.getEquivalentOfExpression(possibleDiseasesIntersection)); possibleDiseases.remove(model.getDataFactory().getOWLNothing()); String value=""; if(possibleDiseases.size()!=0) { Iterator<OWLClass> it = possibleDiseases.iterator(); while (it.hasNext()) { value+="\n"+new SimpleShortFormProvider().getShortForm(it.next()); } }else value+="\nCould not found"; return value; }
public static String formatClassExpression(OWLClassExpression ce, OWLOntology ont) { if (ce instanceof OWLClass) { return getLabel(ce.asOWLClass(), ont); } else if (ce instanceof OWLObjectIntersectionOf) { OWLObjectIntersectionOf oi = (OWLObjectIntersectionOf) ce; List<OWLClassExpression> ops = oi.getOperandsAsList(); StringBuilder sb = new StringBuilder(); sb.append(formatClassExpression(ops.get(0), ont)); for (int i = 1; i < ops.size(); i++) { sb.append(" \u2229 "); sb.append(formatClassExpression(ops.get(i), ont)); } return sb.toString(); } else if (ce instanceof OWLObjectSomeValuesFrom) { OWLObjectSomeValuesFrom osv = (OWLObjectSomeValuesFrom) ce; OWLObjectPropertyExpression ope = osv.getProperty(); String role = (!ope.isAnonymous()) ? getLabel( ope.asOWLObjectProperty(), ont) : ope.toString(); return "\u2203" + role + ".(" + formatClassExpression(osv.getFiller(), ont) + ")"; } else { return ce.toString(); } }
@Override public void addToOntology() { OWLClass c1 = featurePool.getExclusiveClass(":ObjectIntersectionOf_QL_Class1"); OWLClass c2 = featurePool.getExclusiveClass(":ObjectIntersectionOf_QL_Class2"); OWLObjectIntersectionOf spork = factory.getOWLObjectIntersectionOf(c1, c2); OWLClass owlClass = featurePool.getExclusiveClass(":ObjectIntersectionOf_QL"); addAxiomToOntology(factory.getOWLSubClassOfAxiom(owlClass, spork)); }
@Override public void addToOntology() { OWLClass c1 = featurePool.getExclusiveClass(":ObjectIntersectionOf_Class1"); OWLClass c2 = featurePool.getExclusiveClass(":ObjectIntersectionOf_Class2"); OWLObjectIntersectionOf spork = factory.getOWLObjectIntersectionOf(c1, c2); OWLClass owlClass = featurePool.getExclusiveClass(":ObjectIntersectionOf"); OWLAxiom axiom = factory.getOWLEquivalentClassesAxiom(owlClass, spork); addAxiomToOntology(axiom); }
private Set<Integer> flattenClassExpression(OWLClassExpression expression, Set<Definition> newDefinitions, Set<Integer> newNames) { if (expression instanceof OWLClass) { return flattenClass((OWLClass) expression, newNames); } if (expression instanceof OWLObjectIntersectionOf) { return flattenConjunction((OWLObjectIntersectionOf) expression, newDefinitions, newNames); } if (expression instanceof OWLObjectSomeValuesFrom) { return flattenExistentialRestriction((OWLObjectSomeValuesFrom) expression, newDefinitions, newNames); } throw new RuntimeException("Unsupported class expression: " + expression); }
private Set<Integer> flattenConjunction(OWLObjectIntersectionOf conjunction, Set<Definition> newDefinitions, Set<Integer> newNames) { Set<Integer> atomIds = new HashSet<>(); for (OWLClassExpression operand : conjunction.getOperands()) { atomIds.addAll(flattenClassExpression(operand, newDefinitions, newNames)); } return atomIds; }
/** * Load owl class. * * @param expr the owl class * @param ontology the ontology * @param level the level * @return the concept * @throws Exception the exception */ private Concept getConceptForOwlClassExpression(OWLClassExpression expr, OWLOntology ontology, int level) throws Exception { // Log it if (expr instanceof OWLClass) { OwlUtility.logOwlClass((OWLClass) expr, ontology, level); } else { OwlUtility.logOwlClassExpression(expr, ontology, level); } // Handle direct OWLClass if (expr instanceof OWLClass) { return getConceptForOwlClass((OWLClass) expr, ontology, level); } // Handle ObjectIntersectionOf else if (expr instanceof OWLObjectIntersectionOf) { return getConceptForIntersectionOf((OWLObjectIntersectionOf) expr, ontology, level); } // Handle ObjectUnionOf else if (expr instanceof OWLObjectUnionOf) { return getConceptForUnionOf((OWLObjectUnionOf) expr, ontology, level); } // Handle ObjectSomeValuesFrom else if (expr instanceof OWLObjectSomeValuesFrom) { return getConceptForSomeValuesFrom((OWLObjectSomeValuesFrom) expr, ontology, level); } else { throw new Exception("Unexpected class expression type - " + expr.getClassExpressionType()); } }
private boolean negativeBranch(Set<ConceptType> conceptTypes, List<OWLClass> atoms, OWLReasoner reasoner, int conceptTypeNumber, ConceptType partialConceptType, int atomIndex, boolean satNeeded) { boolean result = false; OWLClass nextAtom = atoms.get( atomIndex ); OWLObjectIntersectionOf exprCopy = partialConceptType.getConjunctiveExpr(); //Conjunction with a negative literal if (!partialConceptType.containsPositive( nextAtom )) { partialConceptType.addNegative( nextAtom ); result = generate( conceptTypes, atoms, reasoner, conceptTypeNumber, partialConceptType, atomIndex + 1, satNeeded); partialConceptType.removeNegative( nextAtom ); partialConceptType.setConjunctiveExpr( exprCopy ); } return result; }
private boolean positiveBranch( Set<ConceptType> conceptTypes, List<OWLClass> atoms, OWLReasoner reasoner, int conceptTypeNumber, ConceptType partialConceptType, int atomIndex, boolean satNeeded) { boolean result = false; OWLClass nextAtom = atoms.get( atomIndex ); OWLObjectIntersectionOf exprCopy = partialConceptType.getConjunctiveExpr(); // Conjunction with a positive literal if (!partialConceptType.containsNegative( nextAtom )) { partialConceptType.addPositive( nextAtom ); result = generate( conceptTypes, atoms, reasoner, conceptTypeNumber, partialConceptType, atomIndex + 1, satNeeded); partialConceptType.removePositive( nextAtom ); partialConceptType.setConjunctiveExpr( exprCopy ); } return result; }
public OWLClassExpression visit(OWLObjectIntersectionOf object) { OWLClassExpression definition=getDefinitionFor(object,m_alreadyExists); if (!m_alreadyExists[0]) for (OWLClassExpression description : object.getOperands()) m_newInclusions.add(new OWLClassExpression[] { negative(definition),description }); return definition; }
public OWLClassExpression visit(OWLObjectIntersectionOf d) { Set<OWLClassExpression> newConjuncts=new HashSet<OWLClassExpression>(); for (OWLClassExpression description : d.getOperands()) { OWLClassExpression descriptionNNF=getNNF(description); newConjuncts.add(descriptionNNF); } return m_factory.getOWLObjectIntersectionOf(newConjuncts); }
public OWLClassExpression visit(OWLObjectIntersectionOf d) { Set<OWLClassExpression> newConjuncts=new HashSet<OWLClassExpression>(); for (OWLClassExpression description : d.getOperands()) { OWLClassExpression descriptionSimplified=getSimplified(description); if (descriptionSimplified.isOWLThing()) continue; else if (descriptionSimplified.isOWLNothing()) return m_factory.getOWLNothing(); else if (descriptionSimplified instanceof OWLObjectIntersectionOf) newConjuncts.addAll(((OWLObjectIntersectionOf)descriptionSimplified).getOperands()); else newConjuncts.add(descriptionSimplified); } return m_factory.getOWLObjectIntersectionOf(newConjuncts); }
private boolean getReachableOWLClasses(OWLClassExpression c, Set<OWLClassExpression> elts) { if (c instanceof OWLObjectIntersectionOf) { for (OWLClassExpression x : ((OWLObjectIntersectionOf)c).getOperands()) { if (x instanceof OWLClass) { elts.add((OWLClass) x); } else if (x instanceof OWLObjectSomeValuesFrom) { OWLObjectPropertyExpression p = ((OWLObjectSomeValuesFrom)x).getProperty(); String pLabel = getGraph().getLabel(p); if (pLabel != null && pLabel.contains("regulates")) { // fairly hacky: // fail on this for now - no inference for regulates //elts.add(x); return false; } else { OWLClassExpression filler = ((OWLObjectSomeValuesFrom)x).getFiller(); if (!getReachableOWLClasses( filler, elts)) { return false; } } } else { return false; } } return true; } else if (c instanceof OWLClass) { elts.add((OWLClass) c); return true; } return false; }
public OWLClassExpression edgeSetToExpression(Set<OWLGraphEdge> edges) { Set<OWLClassExpression> xs = new HashSet<OWLClassExpression>(); for (OWLGraphEdge e : edges) { OWLObject x = graph.edgeToTargetExpression(e); xs.add((OWLClassExpression)x); } if (xs.size() == 1) return xs.iterator().next(); OWLObjectIntersectionOf ix = graph.getDataFactory().getOWLObjectIntersectionOf(xs); return ix; }
public String generateLabel(OWLClassExpression x) { StringBuffer sb = new StringBuffer(); if (x instanceof OWLObjectSomeValuesFrom) { OWLObjectSomeValuesFrom svf = (OWLObjectSomeValuesFrom) x; OWLObjectPropertyExpression p = svf.getProperty(); if (propertyToFormatMap.containsKey(p)) { return String.format(propertyToFormatMap.get(p), generateLabel(svf.getFiller())); } else { String pStr = p.toString(); if (p instanceof OWLEntity) { pStr = getAnyLabel((OWLEntity)p); } return pStr + " some "+generateLabel(svf.getFiller()); } } else if (x instanceof OWLObjectIntersectionOf) { OWLObjectIntersectionOf oio = (OWLObjectIntersectionOf) x; for (OWLClassExpression op : oio.getOperands()) { if (sb.length() > 0) { sb.append(" and "); } sb.append(generateLabel(op)); } return sb.toString(); } else if (x instanceof OWLClass) { return this.getAnyLabel((OWLClass) x); } return x.toString(); }
@Override public OWLObjectIntersectionOf visit(OWLObjectIntersectionOf ce) { if (LOG.isDebugEnabled()) { LOG.debug("Unfolding intersection_of: "+ce); } Set<OWLClassExpression> operands = ce.getOperands(); if (operands != null && !operands.isEmpty()) { Set<OWLClassExpression> unfolded = unfoldExpressions(operands); if (unfolded != null) { return factory.getOWLObjectIntersectionOf(unfolded); } } return null; }
@Override public ExpressionLD makeIntersectionOf(OWLObjectIntersectionOf x) { Set<ExpressionLD> ops = new HashSet<ExpressionLD>(); for (OWLClassExpression op : x.getOperands()) { ops.add(makeExpression(op)); } return new IntersectionOfLD(ops); }
private OWLClassExpression replaceVariables(OWLClassExpression inx, BindingSet bset) { if (inx instanceof OWLNamedObject) { IRI y = replaceIRI(((OWLNamedObject)inx).getIRI(), bset); if (inx instanceof OWLClass) { return getOWLDataFactory().getOWLClass(y); } } else if (inx instanceof OWLObjectSomeValuesFrom) { OWLObjectSomeValuesFrom svf = (OWLObjectSomeValuesFrom)inx; return getOWLDataFactory().getOWLObjectSomeValuesFrom( replaceVariables(svf.getProperty(),bset), replaceVariables(svf.getFiller(),bset)); } else if (inx instanceof OWLObjectIntersectionOf) { Set<OWLClassExpression> es = new HashSet<OWLClassExpression>(); for (OWLClassExpression e : ((OWLObjectIntersectionOf)inx).getOperands()) { es.add(replaceVariables(e, bset)); } return getOWLDataFactory().getOWLObjectIntersectionOf(es); } else { } return null; }
@Test public void testIntersectionsReturnedInClosure() throws Exception { OWLGraphWrapper g = getOntologyWrapper(); g.config.isGraphReasonedAndRelaxed = false; OWLObject obj = g.getOWLObject("http://example.org#o1"); boolean ok = false; for (OWLGraphEdge e : g.getOutgoingEdgesClosureReflexive(obj)) { if (RENDER_ONTOLOGY_FLAG) { System.out.println(e); } if (e.getTarget() instanceof OWLObjectIntersectionOf) ok = true; } assertTrue(ok); }
private OWLClassExpression getType(OWLNamedIndividual individual) { NodeSet<OWLClass> types = reasoner.getTypes(individual, true); if (types.isEmpty() || types.isBottomSingleton() || types.isTopSingleton()) { return null; } Set<OWLClass> set = types.getFlattened(); if (set.size() == 1) { return set.iterator().next(); } OWLDataFactory fac = graph.getManager().getOWLDataFactory(); OWLObjectIntersectionOf intersectionOf = fac.getOWLObjectIntersectionOf(set); return intersectionOf; }
public static OWLClassExpression searchCellularLocation(OWLClassExpression cls, OWLGraphWrapper graph, Set<OWLObjectProperty> occurs_in) { Queue<OWLClass> queue = new Queue<OWLClass>(); if (cls instanceof OWLClass) { queue.add((OWLClass) cls); } else if (cls instanceof OWLObjectIntersectionOf) { OWLObjectIntersectionOf intersectionOf = (OWLObjectIntersectionOf) cls; for (OWLClassExpression ce : intersectionOf.getOperands()) { if (ce instanceof OWLClass) { queue.add((OWLClass) ce); } } } return searchCellularLocation(queue, graph, occurs_in); }
public void visit(OWLObjectIntersectionOf arg0) { boolean isFirst=true; for (OWLClassExpression operand : arg0.getOperands()) { if (!isFirst) writer.write(" and "); operand.accept(this); isFirst = false; } }
@Override public IntegerClassExpression visit(OWLObjectIntersectionOf ce) { Objects.requireNonNull(ce); Set<OWLClassExpression> operands = ce.getOperands(); Set<IntegerClassExpression> classExpressionList = new HashSet<>(); operands.forEach(elem -> { classExpressionList.add(elem.accept(this)); }); return getDataTypeFactory().createObjectIntersectionOf(classExpressionList); }