org.semanticweb.owlapi.model.OWLEquivalentClassesAxiom Java Examples

The following examples show how to use org.semanticweb.owlapi.model.OWLEquivalentClassesAxiom. 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: AbstractSimPreProcessor.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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);
}
 
Example #2
Source File: TBoxUnFoldingTool.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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!
}
 
Example #3
Source File: TBoxUnFoldingTool.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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;
}
 
Example #4
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 #5
Source File: CardinalityContraintsTools.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@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);
	}
}
 
Example #6
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 #7
Source File: OldSimpleOwlSim.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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;
}
 
Example #8
Source File: CompositionalClassPredictor.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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);						
					}
				}
			}
		}
	}
}
 
Example #9
Source File: OboOntologyReleaseRunner.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * 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;
}
 
Example #10
Source File: DanglingReferenceCheck.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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()));
		}
	}
}
 
Example #11
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 #12
Source File: OboOntologyReleaseRunner.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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);
}
 
Example #13
Source File: DanglingReferenceCheck.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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()));
	}
}
 
Example #14
Source File: GraphOwlVisitor.java    From SciGraph with Apache License 2.0 5 votes vote down vote up
@Override
public Void visit(OWLEquivalentClassesAxiom axiom) {
  logger.fine(axiom.toString());
  List<Long> nodes =
      transform(axiom.getClassExpressionsAsList(), new Function<OWLClassExpression, Long>() {

        @Override
        public Long apply(OWLClassExpression expr) {
          return getOrCreateNode(getIri(expr));
        }
      });

  getOrCreateRelationshipPairwise(nodes, OwlRelationships.OWL_EQUIVALENT_CLASS);
  return null;
}
 
Example #15
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 #16
Source File: DanglingReferenceCheck.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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));
		}
	}
}
 
Example #17
Source File: LazyExpressionMaterializingReasoner.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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;
}
 
Example #18
Source File: OwlHelper.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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;
}
 
Example #19
Source File: TemplatedTransformer.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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;
	
}
 
Example #20
Source File: TBoxUnFoldingTool.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * 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;
}
 
Example #21
Source File: SelfReferenceInDefinition.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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;
}
 
Example #22
Source File: AssertInferenceTool.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static void createEquivModule(List<OWLEquivalentClassesAxiom> equivalentNamedClassPairs, OWLOntology ont)
		throws OWLOntologyCreationException, IOException, OWLOntologyStorageException
{
	Set<OWLEntity> signature = new HashSet<OWLEntity>();
	for(OWLEquivalentClassesAxiom axiom : equivalentNamedClassPairs) {
		signature.addAll(axiom.getSignature());
	}
	final String moduleName = "equivalent-classes";
	createModule(moduleName, signature, ont);
}
 
Example #23
Source File: TBoxUnFoldingTool.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * 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;
}
 
Example #24
Source File: AbstractOwlAxiomConverterVisitor.java    From elk-reasoner with Apache License 2.0 5 votes vote down vote up
@Override
public T visit(OWLEquivalentClassesAxiom axiom) {
	throw new IllegalArgumentException(
			OWLEquivalentClassesAxiom.class.getSimpleName()
					+ " cannot be converted to "
					+ getTargetClass().getSimpleName());
}
 
Example #25
Source File: DLQueryTool.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * 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;
}
 
Example #26
Source File: Mooncat.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * 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
			}
		}
	}
}
 
Example #27
Source File: SpeciesMergeUtil.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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);
}
 
Example #28
Source File: TBoxUnFoldingTool.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * 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);
}
 
Example #29
Source File: InferenceBuilder.java    From owltools with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public List<OWLEquivalentClassesAxiom> getEquivalentNamedClassPairs() {
	return equivalentNamedClassPairs;
}
 
Example #30
Source File: AxiomAnnotationTools.java    From owltools with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public OWLAxiom visit(OWLEquivalentClassesAxiom axiom) {
	return factory.getOWLEquivalentClassesAxiom(axiom.getClassExpressions(), annotations);
}