org.semanticweb.owlapi.model.OWLSubClassOfAxiom Java Examples

The following examples show how to use org.semanticweb.owlapi.model.OWLSubClassOfAxiom. 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: ReasonerUtil.java    From SciGraph with Apache License 2.0 6 votes vote down vote up
void removeRedundantAxioms() {
  final List<RemoveAxiom> changes = new ArrayList<RemoveAxiom>();
  Set<OWLClass> allClasses = ont.getClassesInSignature(true);
  logger.info("Check classes for redundant super class axioms, all OWL classes count: " + allClasses.size());
  for (OWLClass cls: allClasses) {
    final Set<OWLClass> directSuperClasses = reasoner.getSuperClasses(cls, true).getFlattened();
    for (final OWLOntology importedOntology: ont.getImportsClosure()) {
      Set<OWLSubClassOfAxiom> subClassAxioms = importedOntology.getSubClassAxiomsForSubClass(cls);
      for (final OWLSubClassOfAxiom subClassAxiom : subClassAxioms) {
        subClassAxiom.getSuperClass().accept(new OWLClassExpressionVisitorAdapter(){
          @Override
          public void visit(OWLClass desc) {
            if (directSuperClasses.contains(desc) == false) {
              changes.add(new RemoveAxiom(importedOntology, subClassAxiom));
            }
          }
        });
      }
    }
  }
  logger.info("Found redundant axioms: " + changes.size());
  List<OWLOntologyChange> result = manager.applyChanges(changes);
  logger.info("Removed axioms: " + result.size());
}
 
Example #2
Source File: GraphOwlVisitor.java    From SciGraph with Apache License 2.0 6 votes vote down vote up
@Override
public Void visit(OWLSubClassOfAxiom axiom) {
  long subclass = getOrCreateNode(getIri(axiom.getSubClass()));
  long superclass = getOrCreateNode(getIri(axiom.getSuperClass()));
  long relationship =
      getOrCreateRelationship(subclass, superclass, OwlRelationships.RDFS_SUBCLASS_OF);
  for (OWLAnnotation annotation : axiom.getAnnotations()) {
    // TODO: Is there a more elegant way to process these annotations?
    String property = annotation.getProperty().getIRI().toString();
    if (annotation.getValue() instanceof OWLLiteral) {
      Optional<Object> value =
          OwlApiUtils.getTypedLiteralValue((OWLLiteral) annotation.getValue());
      if (value.isPresent()) {
        graph.addRelationshipProperty(relationship, property, value.get());
      }
    }
  }
  return null;
}
 
Example #3
Source File: NormalizedOWLQLTbox.java    From quetzal with Eclipse Public License 2.0 6 votes vote down vote up
public Set<OWLClass> getUnsatisfiableNamedClasses() {
	if (unsatisfiableClasses == null) {
		unsatisfiableClasses = new HashSet<OWLClass>();
		// unsatisfiabe named classes C are in the negative closure in the form
		// subclass( C, not(C)) 
		for (OWLSubClassOfAxiom ax: getNegativeInclInNegClosure()) {
			OWLClassExpression sub = ax.getSubClass();
			OWLClassExpression sup = ax.getSuperClass();
			if (!sub.isAnonymous()
			&& sup.getClassExpressionType().equals(ClassExpressionType.OBJECT_COMPLEMENT_OF)
			&& ((OWLObjectComplementOf) sup).getOperand().equals(sub)) {
				unsatisfiableClasses.add(sub.asOWLClass());
			}
		}
	}
	return Collections.unmodifiableSet(unsatisfiableClasses);
	//return new HashSet<OWLClass>();
}
 
Example #4
Source File: SubClassComputation.java    From quetzal with Eclipse Public License 2.0 6 votes vote down vote up
public SubClassComputation(NormalizedOWLQLTbox tbox) {
	super();
	numOfDirectSubsumptionTests =0;
	this.tbox = tbox;
	sub2ToldSubsumers = new HashMap<OWLClassExpression, Set<OWLClassExpression>>();
	Set<OWLSubClassOfAxiom> axioms = tbox.getNormalizedOntology().getAxioms(AxiomType.SUBCLASS_OF);
	int maxToldSubsumers =0;
	if (axioms!=null) {
		for (OWLSubClassOfAxiom ax: axioms) {
			OWLClassExpression sub = ax.getSubClass();
			OWLClassExpression sup = ax.getSuperClass();
			//if (!sub.isAnonymous()) 
			{
				Set<OWLClassExpression> s = sub2ToldSubsumers.get(sub);
				if (s == null) {
					s = new HashSet<OWLClassExpression>();
					sub2ToldSubsumers.put(sub, s);
				}
				s.add(sup);
				maxToldSubsumers = Math.max(s.size(), maxToldSubsumers);
			}
		}
	}
	logger.debug("Max told subsumers: {}", maxToldSubsumers);
	
}
 
Example #5
Source File: NCBIConverter.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Check to make sure that this taxon has the required properties.
 *
 * <ul>
 * <li>label exists</li>
 * <li>exactly one superClass</li>
 * </ul>
 *
 * @param ontology the current ontology
 * @param taxon the subject
 * @return true if the check succeeds, otherwise false.
 */
public static Boolean checkTaxon(OWLOntology ontology, 
		OWLClass taxon) {
	String id = getTaxonID(taxon);

	String label = getFirstLiteral(ontology, taxon,
		"rdfs:label");
	if (label == null || label.trim().length() == 0) {
		logger.error("No SCIENTIFIC NAME provided for " + id);
		return false;
	}
	Set<OWLSubClassOfAxiom> axioms = ontology.getSubClassAxiomsForSubClass(taxon);
	Set<OWLClassExpression> superClasses = new HashSet<>();
	for(OWLSubClassOfAxiom ax : axioms) {
		superClasses.add(ax.getSuperClass());
	}
	if (superClasses.size() < 1 && !id.equals("1")) {
		logger.error("No PARENT ID for " + id);
		return false;
	} else if (superClasses.size() > 1) {
		logger.error("Multiple PARENT IDs for " + id);
		return false;
	}

	return true;
}
 
Example #6
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 #7
Source File: CycleCheck.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public List<OWLClass> getAdjacent(OWLClass cls) {
	Set<OWLClass> results = new HashSet<OWLClass>();
	Set<OWLOntology> allOntologies = graph.getAllOntologies();
	for (OWLOntology owlOntology : allOntologies) {
		Set<OWLSubClassOfAxiom> axioms = owlOntology.getSubClassAxiomsForSubClass(cls);
		if (axioms != null && !axioms.isEmpty()) {
			for (OWLSubClassOfAxiom axiom : axioms) {
				OWLClassExpression expression = axiom.getSuperClass();
				if (!expression.isAnonymous()) {
					results.add(expression.asOWLClass());
				}
			}
		}
	}
	if (results.isEmpty()) {
		return Collections.emptyList();
	}
	return new ArrayList<OWLClass>(results);
}
 
Example #8
Source File: ProvenanceReasonerWrapper.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public boolean isEdgeEntailed(OWLEdge e, OWLOntology currentOntology, OWLReasoner reasoner) {
	OWLOntologyManager m = getManager();

	Set<OWLSubClassOfAxiom> scas = currentOntology.getSubClassAxiomsForSubClass(e.c);
	Set<OWLSubClassOfAxiom> rmAxioms = new HashSet<OWLSubClassOfAxiom>();
	for (OWLSubClassOfAxiom sca : scas) {
		if (sca.getSuperClass().equals(e.p)) {
			LOG.info("REMOVING: "+sca);
			rmAxioms.add(sca);
		}
	}
	boolean isEdgeAsserted = rmAxioms.size() > 0;
	if (isEdgeAsserted) {
		m.removeAxioms(currentOntology, rmAxioms);
		reasoner.flush();
	}
	boolean isEntailed;
	isEntailed = reasoner.getSuperClasses(e.c, false).containsEntity(e.p);
	if (isEdgeAsserted) {
		m.addAxioms(currentOntology, rmAxioms);
		reasoner.flush();
	}

	return isEntailed;
}
 
Example #9
Source File: RedundantInferencesTest.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
	public void test() throws Exception {
		Map<OWLClass, Set<RedundantAxiom>> redundantAxiomMap = RedundantInferences.removeRedundantSubClassAxioms(graph.getSourceOntology(), reasoner);
		assertNotNull(redundantAxiomMap);
		assertEquals(1, redundantAxiomMap.size());
		
		OWLClass test1Sub = graph.getOWLClassByIdentifier("FOO:0004");
		OWLClass test1Super = graph.getOWLClassByIdentifier("FOO:0002");
		Set<RedundantAxiom> redundantAxioms = redundantAxiomMap.get(test1Sub);
		assertEquals(1, redundantAxioms.size());
		RedundantAxiom redundantAxiom = redundantAxioms.iterator().next();
		OWLSubClassOfAxiom owlAxiom = redundantAxiom.getAxiom();
		assertTrue(AxiomAnnotationTools.isMarkedAsInferredAxiom(owlAxiom));
		assertEquals(test1Super, owlAxiom.getSuperClass());
		Set<OWLClass> moreSpecific = redundantAxiom.getMoreSpecific();
		assertEquals(1, moreSpecific.size());
		OWLClass moreSpecificClass = moreSpecific.iterator().next();
		assertEquals(graph.getOWLClassByIdentifier("FOO:0003"), moreSpecificClass);


//		graph.getManager().saveOntology(graph.getSourceOntology(), System.err);
	}
 
Example #10
Source File: CardinalityContraintsTools.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void visit(OWLSubClassOfAxiom axiom) {
	OWLClassExpression subClass = axiom.getSubClass();
	OWLClassExpression superClass = axiom.getSuperClass();
	HandlerResult modifiedSubClass = subClass.accept(handler);
	HandlerResult modifiedSuperClass = superClass.accept(handler);
	if (modifiedSubClass != null || modifiedSuperClass != null) {
		if (modifiedSubClass != null) {
			if (modifiedSubClass.remove) {
				remove(ontology, axiom);
				return;
			}
			subClass = modifiedSubClass.modified;
		}
		if (modifiedSuperClass != null) {
			if (modifiedSuperClass.remove) {
				remove(ontology, axiom);
				return;
			}
			superClass = modifiedSuperClass.modified;
		}
		remove(ontology, axiom);
		OWLSubClassOfAxiom newAxiom = factory.getOWLSubClassOfAxiom(subClass, superClass, axiom.getAnnotations());
		add(ontology, newAxiom);
	}
}
 
Example #11
Source File: RedundantInferences.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Remove the redundant and marked as inferred super class assertions for
 * each class in the ontology signature. Uses the reasoner to infer the
 * direct super classes.
 * 
 * @param ontology
 * @param reasoner
 * @return map of class to set of redundant axioms
 */
public static Map<OWLClass, Set<RedundantAxiom>> removeRedundantSubClassAxioms(OWLOntology ontology, OWLReasoner reasoner) {
	Iterable<OWLClass> classes = ontology.getClassesInSignature();
	Map<OWLClass, Set<RedundantAxiom>> axioms = findRedundantSubClassAxioms(classes, ontology, reasoner);
	if (!axioms.isEmpty()) {
		Set<OWLSubClassOfAxiom> allAxioms = new THashSet<OWLSubClassOfAxiom>();
		for(OWLClass cls : axioms.keySet()) {
			for(RedundantAxiom redundantAxiom : axioms.get(cls)) {
				allAxioms.add(redundantAxiom.getAxiom());
			}
		}
		OWLOntologyManager manager = ontology.getOWLOntologyManager();
		manager.removeAxioms(ontology, allAxioms);
		LOG.info("Removed "+axioms.size()+" redundant axioms.");
	}
	return axioms;
	
}
 
Example #12
Source File: LinkMaker.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Check that the given subClass does not already has a matching subClass axiom.
 * 
 * @param subCls
 * @param p
 * @param superCls
 * @return existing axiom or null
 */
private OWLAxiom hasLinks(OWLClass subCls, OWLObjectProperty p, OWLClass superCls) {
	for(OWLOntology o : allOntologies) {
		Set<OWLSubClassOfAxiom> subClsAxioms = o.getSubClassAxiomsForSubClass(subCls);
		for (OWLSubClassOfAxiom subClsAxiom : subClsAxioms) {
			OWLClassExpression ce = subClsAxiom.getSuperClass();
			if (ce instanceof OWLObjectSomeValuesFrom) {
				OWLObjectSomeValuesFrom someValuesFrom = (OWLObjectSomeValuesFrom) ce;
				OWLObjectPropertyExpression property = someValuesFrom.getProperty();
				if (p.equals(property)) {
					OWLClassExpression filler = someValuesFrom.getFiller();
					if (superCls.equals(filler)) {
						return subClsAxiom;
					}
				}
			}
		}
	}
	return null;
}
 
Example #13
Source File: TemplatedTransformer.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public Set<Mapping> getMappings() {
	Set<Mapping> ms = new HashSet<Mapping>();
	OWLAnnotationProperty vap = getVariableAnnotationProperty();
	for (OWLSubClassOfAxiom sca : ontology.getAxioms(AxiomType.SUBCLASS_OF, Imports.INCLUDED)) {
		Mapping m = new Mapping();
		Set<OWLAnnotation> anns = sca.getAnnotations(vap);
		for (OWLAnnotation ann : anns) {
			IRI v = (IRI) ann.getValue();
			m.vars.add(v);
		}
		if (m.vars.size() > 0) {
			m.src = sca.getSubClass();
			m.tgt = sca.getSuperClass();
			ms.add(m);
			LOG.info("MAPPING: "+m);
		}
	}
	return ms;
	
}
 
Example #14
Source File: OWLGraphWrapperEdgesAdvanced.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private Map<OWLClass, Set<OWLSubClassOfAxiom>> initNeighborAxioms() {
	Map<OWLClass, Set<OWLSubClassOfAxiom>> result = new HashMap<OWLClass, Set<OWLSubClassOfAxiom>>();
	for(OWLOntology ont : getAllOntologies()) {
		for(OWLSubClassOfAxiom ax : ont.getAxioms(AxiomType.SUBCLASS_OF)) {
			Set<OWLClass> inSignature = ax.getClassesInSignature();
			for (OWLClass cls : inSignature) {
				Set<OWLSubClassOfAxiom> neighbors = result.get(cls);
				if (neighbors == null) {
					neighbors = new HashSet<OWLSubClassOfAxiom>();
					result.put(cls, neighbors);
				}
				neighbors.add(ax);
			}
		}
	}
	
	return result;
}
 
Example #15
Source File: OWLGraphWrapperEdgesAdvanced.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
Set<OWLClass> getSvfClasses(OWLClass c, OWLObjectProperty p) {
	Set<OWLSubClassOfAxiom> axioms = new HashSet<OWLSubClassOfAxiom>();
	for(OWLOntology ont : getAllOntologies()) {
		axioms.addAll(ont.getSubClassAxiomsForSubClass(c));
	}
	Set<OWLClass> superClasses = new HashSet<OWLClass>();
	for (OWLSubClassOfAxiom axiom : axioms) {
		OWLClassExpression expr = axiom.getSuperClass();
		if (expr instanceof OWLObjectSomeValuesFrom) {
			OWLObjectSomeValuesFrom svf = (OWLObjectSomeValuesFrom) expr;
			if (p.equals(svf.getProperty())) {
				OWLClassExpression filler = svf.getFiller();
				if (filler instanceof OWLClass) {
					superClasses.add((OWLClass) filler);
				}
			}
		}
	}
	return superClasses;
}
 
Example #16
Source File: NormalizedOWLQLTbox.java    From quetzal with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * negative concept inclusion in the negative closure
 */
public Set<OWLSubClassOfAxiom> getNegativeInclInNegClosure() {
	if (negIncAxInNegClos ==null) {
		negIncAxInNegClos = new HashSet<OWLSubClassOfAxiom>();
		negObjectSubPropAxInNegClos = new HashSet<OWLDisjointObjectPropertiesAxiom>();
		negDataSubPropAxInNegClos = new HashSet<OWLDisjointDataPropertiesAxiom>();
		organizeNegativeClosure(negativeInclClosure, negIncAxInNegClos, negObjectSubPropAxInNegClos, negDataSubPropAxInNegClos);
	}
	return negIncAxInNegClos;
}
 
Example #17
Source File: AssertInferredClassExpressions.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static Set<OWLObjectSomeValuesFrom> getSuperSVFs(Set<OWLSubClassOfAxiom> axioms) {
	final Set<OWLObjectSomeValuesFrom> svfs = new HashSet<OWLObjectSomeValuesFrom>();
	for (OWLSubClassOfAxiom existing : axioms) {
		OWLClassExpression superCE = existing.getSuperClass();
		superCE.accept(new OWLClassExpressionVisitorAdapter() {
			@Override
			public void visit(OWLObjectSomeValuesFrom svf) {
				svfs.add(svf);
			}

		});
	}
	return svfs;
}
 
Example #18
Source File: SimpleOntology.java    From mobi with GNU Affero General Public License v3.0 5 votes vote down vote up
private Stream<IRI> getSubClassesFor(Set<OWLSubClassOfAxiom> axioms, OWLClass owlClass, boolean direct) {
    if (direct) {
        return axioms.stream()
                .filter(axiom -> axiom.getSuperClass().equals(owlClass))
                .map(OWLSubClassOfAxiom::getSubClass)
                .filter(subclass -> !subclass.isBottomEntity() && subclass.isOWLClass()
                        && !subclass.asOWLClass().getIRI().equals(owlClass.getIRI()))
                .map(subclass -> SimpleOntologyValues.mobiIRI(subclass.asOWLClass().getIRI()));
    } else {
        return owlReasoner.getSubClasses(owlClass, false).entities()
                .filter(subclass -> !subclass.isBottomEntity() && !subclass.getIRI().equals(owlClass.getIRI()))
                .map(subclass -> SimpleOntologyValues.mobiIRI(subclass.getIRI()));
    }
}
 
Example #19
Source File: OWLConverter.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Convenience method for asserting a subClass relation between
 * a parent and child class in an ontology.
 *
 * @param ontology the current ontology
 * @param child the child class
 * @param parent the parent class
 * @return the axiom
 */
protected static OWLSubClassOfAxiom assertSubClass(
		OWLOntology ontology, OWLClass child, OWLClass parent) {
	OWLOntologyManager manager = ontology.getOWLOntologyManager();
	OWLDataFactory dataFactory = manager.getOWLDataFactory();
	OWLSubClassOfAxiom axiom = 
		dataFactory.getOWLSubClassOfAxiom(child, parent);
	ontology.getOWLOntologyManager().addAxiom(ontology, axiom);
	return axiom;
}
 
Example #20
Source File: SubClassOfExtractor.java    From neo4j-sparql-extension with GNU General Public License v3.0 5 votes vote down vote up
private void addAxiom(List<Rule> list, OWLSubClassOfAxiom a) {
	if (!(a.getSubClass().isAnonymous() ||
	      a.getSuperClass().isAnonymous())) {
		String ce1 = getString(a.getSubClass());
		String ce2 = getString(a.getSuperClass());
		list.add(new SubClassOf(ce1, ce2));
	}
}
 
Example #21
Source File: OWLQLNormalizer.java    From quetzal with Eclipse Public License 2.0 5 votes vote down vote up
/** normalize quantified existential to the right
 * <p> normalize(subclass(B, some(R, C)))  -->
 * <ul>
 * 	<li> subclass(B, some(R', Top) </li>
 *  <li> subprop(R', R)</li>
 *  <li> normalize(subclass(some(inv(R'), Top), C)) </li>
 * </ul>
 * @param ax
 * @return
 */
private Set<OWLAxiom> toQLNormalFormRightExistential(OWLSubClassOfAxiom ax) {
	Set<OWLAxiom> ret = new HashSet<OWLAxiom>();
	OWLClassExpression subclass = ax.getSubClass();
	OWLClassExpression superclass = ax.getSuperClass();
	assert isValidOWLQLLeftConcept(subclass): subclass;
	assert superclass.getClassExpressionType().equals(ClassExpressionType.OBJECT_SOME_VALUES_FROM) : superclass;
	// 
	OWLObjectSomeValuesFrom some = (OWLObjectSomeValuesFrom) superclass;
	OWLObjectPropertyExpression r = some.getProperty();
	OWLClassExpression c = some.getFiller();
	
	OWLObjectProperty rPrime = createNewObjectProperty();
	//subclass(B, some(R', Top) 
	ret.add(fac.getOWLSubClassOfAxiom(subclass, fac.getOWLObjectSomeValuesFrom(rPrime, fac.getOWLThing())));
	//subprop(R', R)
	ret.add(fac.getOWLSubObjectPropertyOfAxiom(rPrime, r));
	//normalize(subclass(some(inv(R'), Top), C))
	OWLSubClassOfAxiom axToNormalize= fac.getOWLSubClassOfAxiom(fac.getOWLObjectSomeValuesFrom(fac.getOWLObjectInverseOf(rPrime).getSimplified(), fac.getOWLThing()), c);
	if (!c.isAnonymous()) {
		ret.add(axToNormalize);
	} else if (c.getClassExpressionType().equals(ClassExpressionType.OBJECT_SOME_VALUES_FROM)) {
		Set<OWLAxiom> tpAxioms = toQLNormalFormRightExistential(axToNormalize);
		if (tpAxioms!=null) {
			ret.addAll(tpAxioms);
		} else {
			return null;
		}
	}  else {
		return null;
	}
	return ret;
	
}
 
Example #22
Source File: OWLGraphEdge.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Returns only the {@code OWLSubClassOfAxiom}s among the {@code OWLAxiom}s 
 * returned by {@link #getAxioms()}.
 * 
 * @return A {@code Set} of the underlying {@code OWLSubClassOfAxiom}s that 
 *         produced this {@code OWLGraphEdge}.
 * @see #getAxioms()
 */
public Set<OWLSubClassOfAxiom> getSubClassOfAxioms() {
    Set<OWLSubClassOfAxiom> subs = new HashSet<OWLSubClassOfAxiom>();
    for (OWLAxiom ax: this.underlyingAxioms) {
        if (ax instanceof OWLSubClassOfAxiom) {
            subs.add((OWLSubClassOfAxiom) ax);
        }
    }
    return subs;
}
 
Example #23
Source File: NormalizedOWLQLTbox.java    From quetzal with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * negative data property inclusion axioms in the negative closure
 */
protected Set<OWLDisjointDataPropertiesAxiom> getNegativeDataSubPropAxInClosure() {
	if (negDataSubPropAxInNegClos == null) {
		negIncAxInNegClos = new HashSet<OWLSubClassOfAxiom>();
		negObjectSubPropAxInNegClos = new HashSet<OWLDisjointObjectPropertiesAxiom>();
		negDataSubPropAxInNegClos = new HashSet<OWLDisjointDataPropertiesAxiom>();
		organizeNegativeClosure(negativeInclClosure, negIncAxInNegClos, negObjectSubPropAxInNegClos, negDataSubPropAxInNegClos);
	}
	return negDataSubPropAxInNegClos ;
}
 
Example #24
Source File: OWLGraphManipulator.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Add {@code edge} to its related ontology. 
 * This method transforms the {@code OWLGraphEdge} {@code edge} 
 * into an {@code OWLSubClassOfAxiom}, then add it to the ontology   
    * and update the {@code OWLGraphWrapper} container. 
 * 
 * @param edge 		The {@code OWLGraphEdge} to be added to its related ontology. 
 * @return 			{@code true} if {@code edge} was actually added 
 * 					to the ontology. 
 */
public boolean addEdge(OWLGraphEdge edge) {
    //this.getAxiom was used here in former versions
    OWLSubClassOfAxiom newAxiom = edge.getOntology().getOWLOntologyManager().
       getOWLDataFactory().getOWLSubClassOfAxiom(
           (OWLClassExpression) this.getOwlGraphWrapper().edgeToSourceExpression(edge), 
           (OWLClassExpression) this.getOwlGraphWrapper().edgeToTargetExpression(edge));
    
    ChangeApplied status = edge.getOntology().getOWLOntologyManager().addAxiom(
            edge.getOntology(), newAxiom);
    this.triggerWrapperUpdate();
    return (status != ChangeApplied.UNSUCCESSFULLY);
}
 
Example #25
Source File: NormalizedOWLQLTbox.java    From quetzal with Eclipse Public License 2.0 5 votes vote down vote up
private static void organizeNegativeClosure(Collection<OWLAxiom> normalizedNegClosureAxioms, Collection<OWLSubClassOfAxiom> negIncAxInNegClos,
		Collection<OWLDisjointObjectPropertiesAxiom> negObjectSubPropAxInNegClos, Collection<OWLDisjointDataPropertiesAxiom> negDataSubPropAxInNegClos) {
		organizeTboxAxioms(normalizedNegClosureAxioms, negIncAxInNegClos, negObjectSubPropAxInNegClos, negDataSubPropAxInNegClos,
				new HashSet<OWLSubClassOfAxiom>(), new HashSet<OWLSubPropertyAxiom>(), 
				new HashSet<OWLObjectProperty>(), new HashSet<OWLObjectProperty>(),
				new HashMap<String, Set<OWLSubClassOfAxiom>>(), new HashMap<String, Set<OWLSubPropertyAxiom>>());
}
 
Example #26
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 #27
Source File: RestrictionVisitor.java    From BioSolr with Apache License 2.0 5 votes vote down vote up
@Override
public void visit(OWLClass ce) {
	if (!processedClasses.contains(ce)) {
		// If we are processing inherited restrictions then we
		// recursively visit named supers. Note that we need to keep
		// track of the classes that we have processed so that we don't
		// get caught out by cycles in the taxonomy
		processedClasses.add(ce);
		for (OWLOntology ont : onts) {
			for (OWLSubClassOfAxiom ax : ont.getSubClassAxiomsForSubClass(ce)) {
				ax.getSuperClass().accept(this);
			}
		}
	}
}
 
Example #28
Source File: OntologyHelper.java    From BioSolr with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieve a map of related classes for a particular class.
 * 
 * @param owlClass
 * @return a map of relation type to a list of IRIs for nodes with that
 * relationship.
 */
public Map<String, List<String>> getRestrictions(OWLClass owlClass) {
	RestrictionVisitor visitor = new RestrictionVisitor(Collections.singleton(ontology));
	for (OWLSubClassOfAxiom ax : ontology.getSubClassAxiomsForSubClass(owlClass)) {
		OWLClassExpression superCls = ax.getSuperClass();
		// Ask our superclass to accept a visit from the RestrictionVisitor
		// - if it is an existential restriction then our restriction visitor
		// will answer it - if not our visitor will ignore it
		superCls.accept(visitor);
	}

	Map<String, List<String>> restrictions = new HashMap<>();
	for (OWLObjectSomeValuesFrom val : visitor.getSomeValues()) {
		OWLClassExpression exp = val.getFiller();

		// Get the shortname of the property expression
		String shortForm = null;
		Set<OWLObjectProperty> signatureProps = val.getProperty().getObjectPropertiesInSignature();
		for (OWLObjectProperty sigProp : signatureProps) {
			Collection<String> labels = findLabels(sigProp.getIRI());
			if (labels.size() > 0) {
				shortForm = new ArrayList<String>(labels).get(0);
			}
		}

		if (shortForm != null && !exp.isAnonymous()) {
			IRI iri = exp.asOWLClass().getIRI();

			if (!restrictions.containsKey(shortForm)) {
				restrictions.put(shortForm, new ArrayList<String>());
			}
			restrictions.get(shortForm).add(iri.toString());
		}
	}

	return restrictions;
}
 
Example #29
Source File: OntologyLoader.java    From molgenis with GNU Lesser General Public License v3.0 5 votes vote down vote up
public Set<OWLClass> getChildClass(OWLClass cls) {
  Set<OWLClass> listOfClasses = new HashSet<>();
  for (OWLSubClassOfAxiom axiom : ontology.getSubClassAxiomsForSuperClass(cls)) {
    OWLClassExpression expression = axiom.getSubClass();
    if (!expression.isAnonymous()) {
      OWLClass asOWLClass = expression.asOWLClass();
      listOfClasses.add(asOWLClass);
    }
  }
  return listOfClasses;
}
 
Example #30
Source File: OWLGraphWrapperEdgeTest.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testEdgeCache() throws Exception {
	OWLGraphWrapper g = getGraph("graph/cache-test.obo");
	
	OWLOntology o = g.getSourceOntology();
	OWLOntologyManager m = o.getOWLOntologyManager();
	OWLDataFactory f = m.getOWLDataFactory();
	
	OWLClass orphan = g.getOWLClassByIdentifier("FOO:0004");
	OWLClass root = g.getOWLClassByIdentifier("FOO:0001");
	
	g.getEdgesBetween(orphan, root); //just to trigger the cache
	
	OWLSubClassOfAxiom ax = f.getOWLSubClassOfAxiom(orphan, root);
	AddAxiom addAx = new AddAxiom(o, ax);
	m.applyChange(addAx);
	
	Set<OWLGraphEdge> edges = g.getEdgesBetween(orphan, root);
	assertNotNull(edges);
	
	assertEquals(0, edges.size());
	
	g.clearCachedEdges(); // test clear cache method
	
	edges = g.getEdgesBetween(orphan, root);
	assertNotNull(edges);
	
	assertEquals(1, edges.size());
}