Java Code Examples for org.semanticweb.owlapi.model.OWLClass#isBottomEntity()

The following examples show how to use org.semanticweb.owlapi.model.OWLClass#isBottomEntity() . 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: ClassDifferentiaLearner.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public List<InferredClassDefinition> findDifferentia(OWLClass child, OWLClass parent, OWLClass diffClassRoot) throws UnknownOWLClassException, MathException {

		List<InferredClassDefinition> results = new Vector<InferredClassDefinition>();
		LOG.info("Finding: "+child+" against "+parent);
		for (OWLClass differentiaClass : sim.getReasoner()
				.getSubClasses(diffClassRoot, false).getFlattened()) {
			//LOG.info("  Testing: "+enrichedClass);
			if (differentiaClass.isBottomEntity()) {
				continue;
			}
			if (sim.getNumElementsForAttribute(differentiaClass) == 0) {
				LOG.info("Skipping: "+differentiaClass);
				continue;
			}
			InferredClassDefinition r = calculateGenusDifferentiaEnrichment(child, parent,
					differentiaClass);
			if (r != null)
				results.add(r);
		}
		Collections.sort(results);
		return results;
	}
 
Example 2
Source File: OWLGraphManipulator.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Filter from the ontologies all {@code OWLClass}es 
 * present in {@code classesToKeep},  
 * and then update the {@code OWLGraphWrapper} container. 
 * 
 * @param classesToKeep 	a {@code Set} of {@code OWLClass}s 
 * 							that are classes to be kept in the ontology. 
 * @return                  A {@code Set} of {@code OWLClass}es representing the classes 
 *                          actually removed as a result. 
 */
public Set<OWLClass> filterClasses(Set<OWLClass> classesToKeep) {
	//now remove all classes not included in classesToKeep
    Set<OWLClass> classesRemoved = new HashSet<OWLClass>();
	for (OWLOntology o : this.getOwlGraphWrapper().getAllOntologies()) {
		for (OWLClass iterateClass: o.getClassesInSignature()) {
		    log.info(iterateClass);
		    //don't delete OBO alt IDs nor owl:Nothing and owl:Thing
		    if (this.getOwlGraphWrapper().isOboAltId(iterateClass) || 
		            iterateClass.isTopEntity() || iterateClass.isBottomEntity()) {
		        continue;
		    }
   if (!classesToKeep.contains(iterateClass) && 
           this.removeClass(iterateClass)) {
             classesRemoved.add(iterateClass);
   }
		}
	}
	return classesRemoved;
}
 
Example 3
Source File: GOReciprocalAnnotationRule.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public GOReciprocalAnnotationRule(OWLGraphWrapper graph, TraversingEcoMapper eco) {
	this.graph = graph;
	evidences = eco.getAllValidEvidenceIds("IPI",  true);
	
	OWLClass proteinBindingCls = graph.getOWLClassByIdentifier(PROTEIN_BINDING_GO_ID);
	if (proteinBindingCls == null) {
		throw new RuntimeException("No class found for identifier: "+PROTEIN_BINDING_GO_ID);
	}
	ElkReasonerFactory factory = new ElkReasonerFactory();
	OWLReasoner reasoner = null;
	try {
		reasoner = factory.createReasoner(graph.getSourceOntology());
		proteinBindingClasses = new HashSet<OWLClass>();
		proteinBindingClasses.add(proteinBindingCls);
		Set<OWLClass> subClasses = reasoner.getSubClasses(proteinBindingCls, false).getFlattened();
		for (OWLClass cls : subClasses) {
			if (!cls.isBottomEntity() && !cls.isTopEntity()) {
				proteinBindingClasses.add(cls);
			}
		}
	}
	finally {
		if (reasoner != null) {
			reasoner.dispose();
		}
	}
}
 
Example 4
Source File: GoIEPRestrictionsRule.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public GoIEPRestrictionsRule(OWLGraphWrapper graph, TraversingEcoMapper eco) {
	this.message = MESSAGE;
	this.violationType = ViolationType.Warning;
	
	evidences = eco.getAllValidEvidenceIds("IEP", true);
	
	classSubSet = new HashSet<String>();
	
	OWLClass rootClass = graph.getOWLClassByIdentifier("GO:0008150");
	OWLReasonerFactory factory = new ElkReasonerFactory();
	OWLReasoner reasoner = factory.createReasoner(graph.getSourceOntology());
	try {
		NodeSet<OWLClass> nodeSet = reasoner.getSubClasses(rootClass, false);
		for(OWLClass cls : nodeSet.getFlattened()) {
			if (cls.isBottomEntity() || cls.isTopEntity()) {
				continue;
			}
			String oboId = graph.getIdentifier(cls);
			if (oboId != null) {
				classSubSet.add(oboId);
			}
		}
	}
	finally {
		reasoner.dispose();
	}
}
 
Example 5
Source File: GoMultipleTaxonRule.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public GoMultipleTaxonRule(OWLGraphWrapper graph) {
	this.graph = graph;
	multiOrganismClasses = new HashSet<OWLClass>();
	
	OWLClass mop = graph.getOWLClassByIdentifier(GO_ID_MULTI_ORGANISM_PROCESS);
	if (mop == null) {
		throw new RuntimeException("Could not find class for 'multi-organism process' id: "+GO_ID_MULTI_ORGANISM_PROCESS);
	}
	multiOrganismClasses.add(mop);
	ElkReasonerFactory factory = new ElkReasonerFactory();
	OWLReasoner reasoner = null;
	try {
		reasoner = factory.createReasoner(graph.getSourceOntology());
		Set<OWLClass> subClasses = reasoner.getSubClasses(mop, false).getFlattened();
		for (OWLClass owlClass : subClasses) {
			if (owlClass.isBottomEntity() || owlClass.isTopEntity()) {
				continue;
			}
			multiOrganismClasses.add(owlClass);
		}
		
	}
	finally {
		if (reasoner != null) {
			reasoner.dispose();
		}
	}
}
 
Example 6
Source File: GoIPICatalyticActivityRestrictionsRule.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public GoIPICatalyticActivityRestrictionsRule(OWLGraphWrapper graph, TraversingEcoMapper eco) {
	this.message = MESSAGE;
	this.violationType = ViolationType.Warning;
	
	evidences = eco.getAllValidEvidenceIds("IPI", true);
	
	classSubSet = new HashSet<String>();
	
	OWLClass rootClass = graph.getOWLClassByIdentifier("GO:0003824"); // catalytic activity
	OWLReasonerFactory factory = new ElkReasonerFactory();
	OWLReasoner reasoner = factory.createReasoner(graph.getSourceOntology());
	try {
		NodeSet<OWLClass> nodeSet = reasoner.getSubClasses(rootClass, false);
		for(OWLClass cls : nodeSet.getFlattened()) {
			if (cls.isBottomEntity() || cls.isTopEntity()) {
				continue;
			}
			String oboId = graph.getIdentifier(cls);
			if (oboId != null) {
				classSubSet.add(oboId);
			}
		}
	}
	finally {
		reasoner.dispose();
	}
}
 
Example 7
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 queryObject
 * @param ontology
 * @param reasonerFactory
 * @return set of {@link OWLClass} which 
 */
static Set<OWLClass> executeQuery(OWLClassExpression queryObject, OWLOntology ontology, 
		OWLReasonerFactory reasonerFactory) 
{
	Set<OWLClass> subset = new HashSet<OWLClass>();
	
	LOG.info("Create reasoner for query ontology.");
	// Create an instance of an OWL API reasoner
	OWLReasoner reasoner = reasonerFactory.createReasoner(ontology);
	try {
		LOG.info("Start evaluation for DL query subclass of: "+queryObject);
		NodeSet<OWLClass> node = reasoner.getSubClasses(queryObject, false);
		if (node != null) {
			Set<OWLClass> classes = node.getFlattened();
			for (OWLClass owlClass : classes) {
				if (!owlClass.isBottomEntity() && !owlClass.isTopEntity()) {
					subset.add(owlClass);
				}
			}
			LOG.info("Number of found classes for dl query subclass of: "+classes.size());
		}
		return subset;
	}
	finally {
		reasoner.dispose();
	}
}
 
Example 8
Source File: SpeciesMergeUtil.java    From owltools with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void merge() throws UnmergeableOntologyException {

		ont = graph.getSourceOntology();
		mgr = ont.getOWLOntologyManager();
		fac = mgr.getOWLDataFactory();

		createMap(); // build ecmap

		// assume that all classes under consideration are in the direct
		// ontology (which imports generic)
		for (OWLClass c : ssClasses) {
			if (c.isBottomEntity())
				continue;
			if (!reasoner.isSatisfiable(c)) {
				throw new UnmergeableOntologyException("unsatisfiable class: "+c);
			}
			LOG.info("ssClass = " + c);

			// Do not preserve GCIs for upper-level classes
			// TODO - make this configurable
			//			if (ecmap.containsKey(c)) {
			//				if (isSkippable(ecmap.get(c))) {
			//					LOG.info("Skipping: "+c);
			//					continue;
			//				}
			//			}

			Set<OWLAxiom> axioms = new HashSet<OWLAxiom>();
			Set<OWLAxiom> newAxioms = new HashSet<OWLAxiom>();
			axioms.addAll(ont.getAxioms(c, Imports.EXCLUDED));
			axioms.addAll(ont.getAnnotationAssertionAxioms(c.getIRI()));
			for (OWLClass p : reasoner.getSuperClasses(c, true).getFlattened()) {
				axioms.add(fac.getOWLSubClassOfAxiom(c, p));
			}

			// rewrite axioms
			for (OWLAxiom axiom : axioms) {
				//LOG.info("  axiom: " + axiom);
				OWLAxiom newAxiom;
				if (axiom instanceof OWLSubClassOfAxiom)
					newAxiom = tr((OWLSubClassOfAxiom) axiom);
				else if (axiom instanceof OWLEquivalentClassesAxiom)
					newAxiom = tr((OWLEquivalentClassesAxiom) axiom);
				else if (axiom instanceof OWLAnnotationAssertionAxiom)
					newAxiom = tr(c, (OWLAnnotationAssertionAxiom) axiom);
				else
					newAxiom = null;

				if (newAxiom != null && ecmap.containsKey(c)) {
					// avoid axioms like: (ubr:brain and part_of some fly) SubClassOf multi-tissue-structure
					//  only keep rewritten axioms if they refer exclusively to high-value classes.
					//  however, non-unfolded classes will keep their axioms
					for (OWLClass sc : newAxiom.getClassesInSignature()) {
						if (isSkippable(sc)) {
							newAxiom = null;
							break;
						}
					}
				}
				if (newAxiom == null)
					continue;

				if (newAxiom != null) {
					// ignore if axiom contains root class (e.g. fly anatomical structure)
					if (!newAxiom.getClassesInSignature().contains(
							rootSpeciesSpecificClass))
						newAxioms.add(newAxiom);
				} else {
					// failed to rewrite axiom - will not be added to set
				}

			}

			mgr.removeAxioms(ont, axioms);
			mgr.addAxioms(ont, newAxioms);
		}
	}
 
Example 9
Source File: GCIUtil.java    From owltools with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Generates trivial SVF axioms from existing GCIs
 * 
 * <pre>
 * For each GCI of the form CX SubClassOf R some DX
 *  for each C that is an inferred direct subclass of or equivalent to CX
 *     for each D that is an inferred direct superclass of or equivalent to DX
 *       add an axiom C SubClassOf R some D
 * </pre>
 * @param ontology
 * @param reasoner
 * @return axioms
 */
public static Set<OWLSubClassOfAxiom> getSubClassOfSomeValuesFromAxioms(OWLOntology ontology,
		OWLReasoner reasoner) {

	Set<OWLSubClassOfAxiom> axioms = new HashSet<OWLSubClassOfAxiom>();
	OWLDataFactory df = ontology.getOWLOntologyManager().getOWLDataFactory();
	for (OWLSubClassOfAxiom ax : ontology.getAxioms(AxiomType.SUBCLASS_OF)) {
		OWLClassExpression c = ax.getSubClass();
		if (ax.getSuperClass() instanceof OWLObjectSomeValuesFrom) {
			OWLObjectSomeValuesFrom svf = (OWLObjectSomeValuesFrom)ax.getSuperClass();
			OWLObjectPropertyExpression p = svf.getProperty();
			OWLClassExpression filler = svf.getFiller();
			if (filler.isAnonymous() || c.isAnonymous()) {
				if (c.isBottomEntity())
					continue;
				if (filler.isTopEntity())
					continue;
				
				Set<OWLClass> childSet = reasoner.getEquivalentClasses(c).getEntities();
				if (childSet.size() == 0) {
					childSet = reasoner.getSubClasses(c, true).getFlattened();
				}
				for (OWLClass childClass : childSet) {
					if (childClass.isBottomEntity())
						continue;
					Set<OWLClass> childClassSuperClasses = 
							reasoner.getSuperClasses(childClass, false).getFlattened();
					childClassSuperClasses.addAll(reasoner.getEquivalentClasses(childClass).getEntities());
					Set<OWLClass> parentSet = reasoner.getEquivalentClasses(filler).getEntities();
					if (parentSet.size() == 0) {
						parentSet = reasoner.getSuperClasses(filler, true).getFlattened();
					}
					// TODO: remove additional redundancy (R some X) SubClassOf (R some Y)
					// Elk cannot test arbitrary entailments
						for (OWLClass parentClass : parentSet) {
						if (parentClass.isTopEntity())
							continue;
						
						// do not assert C SubClassOf part-of some D, if C SubClassOf D is entailed
						if (childClassSuperClasses.contains(parentClass))
							continue;
						axioms.add(df.getOWLSubClassOfAxiom(childClass, 
								df.getOWLObjectSomeValuesFrom(p, parentClass)));
					}
				}
			}

		}
	}
	LOG.info("Inferred SVFs: "+axioms.size());
	return axioms;
}
 
Example 10
Source File: InferredParentRenderer.java    From owltools with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private void render(OWLClass c, OWLClass filler) {
	if (c.isBottomEntity())
		return;
	if (c.isTopEntity())
		return;
	OWLClassExpression cx = c;
	if (filler != null) {
		OWLObjectSomeValuesFrom svf = graph.getDataFactory().getOWLObjectSomeValuesFrom(gciProperty, filler);
		cx = graph.getDataFactory().getOWLObjectIntersectionOf(c, svf);
	}
	if (!reasoner.isSatisfiable(cx)) {
		LOG.info("Ignore unsat: "+cx+" // base= "+c);
		return;
	}
	print(getId(c));
	sep();
	print(graph.getLabel(c));
	if (gciFillers.size() > 0) {
		if (filler != null) {
			sep();
			print(getId(filler));
			sep();
			print(graph.getLabel(filler));
		}
		else {
			sep();
			print("-");
			sep();
			print("-");				
		}
	}
	for (OWLObjectProperty p : properties) {
		Set<OWLClass> parents = reasoner.getSuperClassesOver(cx, p, true);
		List<OWLClass> lparents = new ArrayList<OWLClass>(parents);
		List<String> l1 = new ArrayList<String>();
		List<String> l2 = new ArrayList<String>();
		for (OWLClass pc : lparents) {
			l1.add(getId(pc));
			l2.add(graph.getLabel(pc));
		}

		sep();
		print(join(l1, "|"));
		sep();
		print(join(l2, "|"));
	}
	print("\n");
}