public OWLObject createUnionExpression(OWLObject a, OWLObject b, OWLObject c) { Set<OWLGraphEdge> edgesA = graph.getEdgesBetween(a, c); Set<OWLGraphEdge> edgesB = graph.getEdgesBetween(b, c); if (edgesA.equals(edgesB)) { return edgeSetToExpression(edgesA); } else { OWLClassExpression xa = edgeSetToExpression(edgesA); OWLClassExpression xb = edgeSetToExpression(edgesA); HashSet<OWLClassExpression> xl = new HashSet<OWLClassExpression>(); xl.add(xa); xl.add(xb); if (xl.size() == 1) return xl.iterator().next(); OWLObjectUnionOf xu = graph.getDataFactory().getOWLObjectUnionOf(xl); return xu; } }
/** * 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 HandlerResult visit(OWLObjectUnionOf unionOf) { Set<OWLClassExpression> newOperands = new HashSet<OWLClassExpression>(); boolean changed = false; for (OWLClassExpression ce : unionOf.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.getOWLObjectUnionOf(newOperands)); } return null; }
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)); } } } } } } } } }
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); } } }
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 void visit(OWLObjectUnionOf union) { Set<OWLClassExpression> ops = union.getOperands(); for (OWLClassExpression op : ops) { /* * ArrayList<OWLClassExpression> l = new * ArrayList<OWLClassExpression>(); new * NormalizatorClassExpressionVisitor(op, l); list.addAll(l); */ try { list.addAll(getListOfConjunctions(op)); } catch (UnusedClassExpressionException e) { errorCnt++; } } }
@Override public void addToOntology() { OWLClass c1 = featurePool.getExclusiveClass(":ObjectUnionOf_RL_Class1"); OWLClass c2 = featurePool.getExclusiveClass(":ObjectUnionOf_RL_Class2"); OWLClass c3 = featurePool.getExclusiveClass(":ObjectUnionOf_RL_Class3"); OWLObjectUnionOf unionOf = factory.getOWLObjectUnionOf(c1, c2, c3); OWLClass unionClass = featurePool.getExclusiveClass(":ObjectUnionOf_RL"); addAxiomToOntology(factory.getOWLSubClassOfAxiom(unionOf, unionClass)); }
@Override public void addToOntology() { OWLClass c1 = featurePool.getExclusiveClass(":ObjectUnionOf_Class1"); OWLClass c2 = featurePool.getExclusiveClass(":ObjectUnionOf_Class2"); OWLClass c3 = featurePool.getExclusiveClass(":ObjectUnionOf_Class3"); OWLObjectUnionOf unionOf = factory.getOWLObjectUnionOf(c1, c2, c3); OWLClass unionClass = featurePool.getExclusiveClass(":ObjectUnionOf"); addAxiomToOntology(factory.getOWLSubClassOfAxiom(unionClass, unionOf)); }
/** * 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()); } }
public OWLClassExpression visit(OWLObjectUnionOf d) { Set<OWLClassExpression> newDisjuncts=new HashSet<OWLClassExpression>(); for (OWLClassExpression description : d.getOperands()) { OWLClassExpression descriptionNNF=getNNF(description); newDisjuncts.add(descriptionNNF); } return m_factory.getOWLObjectUnionOf(newDisjuncts); }
public OWLClassExpression visit(OWLObjectUnionOf d) { Set<OWLClassExpression> newDisjuncts=new HashSet<OWLClassExpression>(); for (OWLClassExpression description : d.getOperands()) { OWLClassExpression descriptionSimplified=getSimplified(description); if (descriptionSimplified.isOWLThing()) return m_factory.getOWLThing(); else if (descriptionSimplified.isOWLNothing()) continue; else if (descriptionSimplified instanceof OWLObjectUnionOf) newDisjuncts.addAll(((OWLObjectUnionOf)descriptionSimplified).getOperands()); else newDisjuncts.add(descriptionSimplified); } return m_factory.getOWLObjectUnionOf(newDisjuncts); }
@Override public OWLObjectUnionOf visit(OWLObjectUnionOf ce) { if (LOG.isDebugEnabled()) { LOG.debug("Unfolding union_of: "+ce); } Set<OWLClassExpression> operands = ce.getOperands(); if (operands != null && !operands.isEmpty()) { Set<OWLClassExpression> unfolded = unfoldExpressions(operands); if (unfolded != null) { return factory.getOWLObjectUnionOf(unfolded); } } return null; }
/** * 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"); }
public void visit(OWLObjectUnionOf arg0) { boolean isFirst=true; for (OWLClassExpression operand : arg0.getOperands()) { if (!isFirst) writer.write(" or "); operand.accept(this); isFirst=false; } }
@Override public Void visit(OWLObjectUnionOf desc) { long subject = getOrCreateNode(getIri(desc), OwlLabels.OWL_UNION_OF, OwlLabels.OWL_ANONYMOUS); for (OWLClassExpression expression : desc.getOperands()) { long object = getOrCreateNode(getIri(expression)); getOrCreateRelationship(subject, object, OwlRelationships.OPERAND); } return null; }
@Override public OWLClassExpression visit(OWLObjectUnionOf ce) { List<OWLClassExpression> operands = ce.getOperandsAsList(); //replace operands by the short form for (int i = 0; i < operands.size(); i++) { operands.set(i, operands.get(i).accept(this)); } Set<OWLClassExpression> newOperands = new HashSet<>(operands); if(newOperands.size() == 1){ return newOperands.iterator().next().accept(this); } for (int i = 0; i < operands.size(); i++) { OWLClassExpression op1 = operands.get(i); for (int j = i + 1; j < operands.size(); j++) { OWLClassExpression op2 = operands.get(j); //remove operand if it is a subclass if(isSubClassOf(op2, op1)){ newOperands.remove(op2); } else if(isSubClassOf(op1, op2)){ newOperands.remove(op1); } else if(isSubClassOf(op1, df.getOWLObjectComplementOf(op2)) || isSubClassOf(op2, df.getOWLObjectComplementOf(op1))) { // check for C or not C return df.getOWLThing(); } } } if(newOperands.size() == 1){ return newOperands.iterator().next().accept(this); } return df.getOWLObjectUnionOf(newOperands); }
@Override public OWLClassExpression visit(OWLObjectUnionOf ce) { Set<OWLClassExpression> ops = new HashSet<>(); for (OWLClassExpression op : ce.getOperands()) { ops.add(op.accept(this)); } if (negated) { // Flip to an intersection return dataFactory.getOWLObjectIntersectionOf(ops); } else { return dataFactory.getOWLObjectUnionOf(ops); } }
@Override public Set<OWLClassExpression> visit(OWLObjectUnionOf ce) { Set<OWLClassExpression> result = new HashSet<>(); result.add(ce); for (OWLClassExpression op : ce.getOperands()) { result.addAll(op.accept(this)); } return result; }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (!super.equals(obj)) { return false; } return obj instanceof OWLObjectUnionOf; }
@Override public Model destroy(Model subModel) { Model result = ModelFactory.createDefaultModel(); List<String> classNames = new ArrayList<>(); if (baseClasses.size() == 0) { classNames = getClasses(subModel); } else { classNames = baseClasses; } List<String> mergeSourceClassUris = new ArrayList<>(); for(int i = 0 ; i < classNames.size() ; i += mergeCount){ String mergeTargetClassUri = new String(); mergeSourceClassUris.removeAll(mergeSourceClassUris); for(int j = 0 ; j < mergeCount && i+j < classNames.size() ; j++){ mergeSourceClassUris.add(j,classNames.get(i+j)); mergeTargetClassUri = mergeTargetClassUri.concat(classNames.get(i+j)); mergeTargetClassUri = (j+1 == mergeCount)? mergeTargetClassUri : mergeTargetClassUri.concat("_MERGE_"); } modifiedClassesURIs.add(mergeTargetClassUri); for(String sourceClassUri : mergeSourceClassUris){ Model sourceClassModel = getClassInstancesModel(sourceClassUri); sourceClassModel = renameClass(sourceClassModel, sourceClassUri, mergeTargetClassUri); result.add(sourceClassModel); //generate optimal solution List<OWLClassExpression> children = new ArrayList<>(); for (String uri : mergeSourceClassUris) { children.add(owlDataFactory.getOWLClass(IRI.create(uri))); } OWLObjectUnionOf optimalSolution = owlDataFactory.getOWLObjectUnionOf(new TreeSet<> (children)); optimalSolutions.put(owlDataFactory.getOWLClass(IRI.create(mergeTargetClassUri)), optimalSolution); } } return result; }
/** * Returns the concept for an ObjectUnionOf. This is just used to borrow * relationships and never actually creates an anonymous concept. * * @param expr the expr * @param ontology the ontology * @param level the level * @return the concept for union * @throws Exception the exception */ private Concept getConceptForUnionOf(OWLObjectUnionOf expr, OWLOntology ontology, int level) throws Exception { String uuid = TerminologyUtility.getUuid(expr.toString()).toString(); if (idMap.containsKey(uuid)) { return getConcept(idMap.get(uuid)); } Concept concept = new ConceptJpa(); setCommonFields(concept); concept.setWorkflowStatus(WorkflowStatus.PUBLISHED); concept.setAnonymous(true); concept.setTerminologyId(uuid); concept.setName(expr.toString()); concept.setUsesRelationshipIntersection(false); concept.setUsesRelationshipUnion(true); // Handle nested class expressions if (expr.getOperands().size() > 1) { // Iterate through expressions and either add a parent relationship // or add relationships from the concept itself. No new anonymous // concepts are directly created here. for (final OWLClassExpression expr2 : expr.getOperands()) { final Concept concept2 = getConceptForOwlClassExpression(expr2, ontology, level + 1); // If it's a restriction, borrow its relationships if (expr2 instanceof OWLObjectIntersectionOf) { // make an anonymous concept out of this and a relationship to it. // Add if anonymous and doesn't exist yet if (concept2.isAnonymous() && !idMap.containsKey(concept2.getTerminologyId())) { addAnonymousConcept(concept2); exprMap.put(concept2.getTerminologyId(), expr); } ConceptRelationship rel = getSubClassOfRelationship(concept, concept2); rel.setRelationshipType("other"); rel.setAdditionalRelationshipType(""); concept.getRelationships().add(rel); } // otherwise, unknown type else { throw new Exception("Unexpected operand expression type - " + expr2); } } return concept; } // ASSUMPTION: union has at least two sub-expressions else { throw new Exception( "Unexpected number of union nested class expressions - " + expr); } }
public void visit(OWLObjectUnionOf arg0) { notSupported(arg0); }
public void visit(OWLObjectUnionOf object) { for (OWLClassExpression description : object.getOperands()) description.accept(this); }
public OWLClassExpression visit(OWLObjectUnionOf object) { throw new IllegalStateException("OR should be broken down at the outermost level"); }
public Boolean visit(OWLObjectUnionOf object) { for (OWLClassExpression desc : object.getOperands()) if (desc.accept(this)) return Boolean.TRUE; return Boolean.FALSE; }
public OWLClassExpression visit(OWLObjectUnionOf d) { Set<OWLClassExpression> newConjuncts=new HashSet<OWLClassExpression>(); for (OWLClassExpression description : d.getOperands()) newConjuncts.add(getComplementNNF(description)); return m_factory.getOWLObjectIntersectionOf(newConjuncts); }
public void visit(OWLObjectUnionOf object) { throw new IllegalStateException("Internal error: invalid normal form."); }
@Override public OWLObjectUnionOf visit(ElkObjectUnionOf expression) { return owlFactory_.getOWLObjectUnionOf( toClassExpressionSet(expression.getClassExpressions())); }
@Override public ElkObjectUnionOf visit(OWLObjectUnionOf owlObjectUnionOf) { return CONVERTER.convert(owlObjectUnionOf); }
@SuppressWarnings("static-method") public ElkObjectUnionOf convert(OWLObjectUnionOf owlObjectUnionOf) { return new ElkObjectUnionOfWrap<OWLObjectUnionOf>(owlObjectUnionOf); }