org.semanticweb.owlapi.model.OWLObjectUnionOf Java Examples

The following examples show how to use org.semanticweb.owlapi.model.OWLObjectUnionOf. 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: SimEngine.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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;
	}
}
 
Example #2
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 #3
Source File: CardinalityContraintsTools.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@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;
}
 
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: DanglingReferenceCheck.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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);
		}
	}
}
 
Example #6
Source File: TBoxUnFoldingTool.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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;
}
 
Example #7
Source File: OWLGraphManipulator.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * 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");
}
 
Example #8
Source File: GraphOwlVisitor.java    From SciGraph with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #9
Source File: AbstractElkObjectConverter.java    From elk-reasoner with Apache License 2.0 4 votes vote down vote up
@Override
public OWLObjectUnionOf visit(ElkObjectUnionOf expression) {
	return owlFactory_.getOWLObjectUnionOf(
			toClassExpressionSet(expression.getClassExpressions()));
}
 
Example #10
Source File: OwlClassExpressionConverterVisitor.java    From elk-reasoner with Apache License 2.0 4 votes vote down vote up
@Override
public ElkObjectUnionOf visit(OWLObjectUnionOf owlObjectUnionOf) {
	return CONVERTER.convert(owlObjectUnionOf);
}
 
Example #11
Source File: OwlConverter.java    From elk-reasoner with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("static-method")
public ElkObjectUnionOf convert(OWLObjectUnionOf owlObjectUnionOf) {
	return new ElkObjectUnionOfWrap<OWLObjectUnionOf>(owlObjectUnionOf);
}
 
Example #12
Source File: ManchesterOWLSyntaxObjectHTMLRenderer.java    From robot with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Given an OWLClassExpression, determine the particular type of OWLClassExpression that it is,
 * and then call the appropriate visit() function for it.
 */
public void visit(OWLClassExpression ce) throws ClassNotFoundException {
  if (ce instanceof OWLClass) {
    visit((OWLClass) ce);
  } else if (ce instanceof OWLObjectSomeValuesFrom) {
    visit((OWLObjectSomeValuesFrom) ce);
  } else if (ce instanceof OWLObjectAllValuesFrom) {
    visit((OWLObjectAllValuesFrom) ce);
  } else if (ce instanceof OWLObjectMinCardinality) {
    visit((OWLObjectMinCardinality) ce);
  } else if (ce instanceof OWLObjectMaxCardinality) {
    visit((OWLObjectMaxCardinality) ce);
  } else if (ce instanceof OWLObjectExactCardinality) {
    visit((OWLObjectExactCardinality) ce);
  } else if (ce instanceof OWLObjectHasValue) {
    visit((OWLObjectHasValue) ce);
  } else if (ce instanceof OWLObjectHasSelf) {
    visit((OWLObjectHasSelf) ce);
  } else if (ce instanceof OWLDataSomeValuesFrom) {
    visit((OWLDataSomeValuesFrom) ce);
  } else if (ce instanceof OWLDataAllValuesFrom) {
    visit((OWLDataAllValuesFrom) ce);
  } else if (ce instanceof OWLDataMinCardinality) {
    visit((OWLDataMinCardinality) ce);
  } else if (ce instanceof OWLDataMaxCardinality) {
    visit((OWLDataMaxCardinality) ce);
  } else if (ce instanceof OWLDataExactCardinality) {
    visit((OWLDataExactCardinality) ce);
  } else if (ce instanceof OWLDataHasValue) {
    visit((OWLDataHasValue) ce);
  } else if (ce instanceof OWLObjectIntersectionOf) {
    visit((OWLObjectIntersectionOf) ce);
  } else if (ce instanceof OWLObjectUnionOf) {
    visit((OWLObjectUnionOf) ce);
  } else if (ce instanceof OWLObjectComplementOf) {
    visit((OWLObjectComplementOf) ce);
  } else if (ce instanceof OWLObjectOneOf) {
    visit((OWLObjectOneOf) ce);
  } else {
    logger.error(
        "Could not visit class expression: {} of type: {}",
        ce.toString(),
        ce.getClass().toString());
  }
}
 
Example #13
Source File: OWLGraphManipulatorTest.java    From owltools with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Regression test for the default operations performed at instantiation 
 * of the {@code OWLGraphManipulator}, following problems with OWLIntersectionOfs 
 * nested in OWLObjectSomeValuesFrom. 
 * Note that this test used a different test ontology than the one loaded by 
 * {@link #loadTestOntology()} before each test. 
 */
@Test
public void regressionTestAxiomRelaxation() throws OWLOntologyCreationException, 
    OBOFormatParserException, IOException {
    
    log.debug("Loading ontology for testing axiom relaxation at instantiation...");
    ParserWrapper parserWrapper = new ParserWrapper();
    OWLOntology ont = parserWrapper.parse(
            this.getClass().getResource("/graph/relaxAxiomsTest.owl").getFile());
    log.debug("Done loading the ontology.");
    
    log.debug("Loading the ontology into OWLGraphManipulator, testing default operations...");
    this.graphManipulator = new OWLGraphManipulator(new OWLGraphWrapper(ont));
    log.debug("Default operations done.");      
    
    //test that are no ECAs left
    assertEquals("Some EquivalentClassesAxioms were not removed", 0, 
            ont.getAxiomCount(AxiomType.EQUIVALENT_CLASSES));
    //test that there is no more OWLSubClassOfAxioms with OWLObjectIntersectionOf or 
    //OWLObjectUnionOf as sub or superclass
    for (OWLSubClassOfAxiom ax: ont.getAxioms(AxiomType.SUBCLASS_OF)) {
        for (OWLClassExpression ce: ax.getNestedClassExpressions()) {
            if (ce instanceof OWLObjectIntersectionOf || ce instanceof OWLObjectUnionOf) {
                throw new AssertionError("An OWLObjectIntersectionOf or " +
                        "OWLObjectUnionOf was not removed: " + ax);
            }
        }
    }
    //test that they were replaced as expected
    OWLDataFactory factory = ont.getOWLOntologyManager().getOWLDataFactory();
    OWLObjectProperty partOf = this.graphManipulator.getOwlGraphWrapper().
        getOWLObjectPropertyByIdentifier("BFO:0000050");
    OWLGraphWrapper wrapper = this.graphManipulator.getOwlGraphWrapper();
    
    Set<OWLAxiom> expectedAxioms = new HashSet<OWLAxiom>();
    expectedAxioms.add(factory.getOWLSubClassOfAxiom(
            wrapper.getOWLClass("http://purl.obolibrary.org/obo/CL_1000321"), 
            factory.getOWLObjectSomeValuesFrom(partOf, 
                    wrapper.getOWLClass("http://purl.obolibrary.org/obo/UBERON_0000483"))));
    expectedAxioms.add(factory.getOWLSubClassOfAxiom(
            wrapper.getOWLClass("http://purl.obolibrary.org/obo/CL_1000321"), 
            factory.getOWLObjectSomeValuesFrom(partOf, 
                    wrapper.getOWLClass("http://purl.obolibrary.org/obo/UBERON_0001983"))));
    //other existing axioms
    expectedAxioms.add(factory.getOWLSubClassOfAxiom(
            wrapper.getOWLClass("http://purl.obolibrary.org/obo/CL_1000321"), 
            wrapper.getOWLClass("http://purl.obolibrary.org/obo/CL_1000320")));
    expectedAxioms.add(factory.getOWLSubClassOfAxiom(
            wrapper.getOWLClass("http://purl.obolibrary.org/obo/CL_1000321"), 
            wrapper.getOWLClass("http://purl.obolibrary.org/obo/CL_0000160")));
    assertEquals("Axioms from import ontology incorrectly merged", 
            expectedAxioms, 
            ont.getAxioms(wrapper.getOWLClass("http://purl.obolibrary.org/obo/CL_1000321"), Imports.EXCLUDED));
}