Java Code Examples for org.semanticweb.owlapi.model.OWLClassAssertionAxiom#getClassExpression()

The following examples show how to use org.semanticweb.owlapi.model.OWLClassAssertionAxiom#getClassExpression() . 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: Sim2CommandRunner.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@CLIMethod("--remove-dangling-annotations")
public void removeDangningAnnotations(Opts opts) throws Exception {
	OWLOntology ont = g.getSourceOntology();
	int n = 0;
	Set<OWLAxiom> rmAxioms = new HashSet<OWLAxiom>();
	for (OWLNamedIndividual i : ont.getIndividualsInSignature()) {
		for (OWLClassAssertionAxiom ca : ont.getClassAssertionAxioms(i)) {
			OWLClassExpression cx = ca.getClassExpression();
			if (cx instanceof OWLClass) {
				OWLClass c = (OWLClass) cx;
				String label = g.getLabel(c);
				if (label == null)
					rmAxioms.add(ca);
				else
					n++;
			}
		}
	}
	LOG.info("Removing " + rmAxioms.size() + " axioms");
	ont.getOWLOntologyManager().removeAxioms(ont, rmAxioms);
	LOG.info("Remaining: " + n + " axioms");
}
 
Example 2
Source File: PhenoSimHQEPreProcessor.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
protected void makeHasPhenotypeInstancesDirect() {
	// x Type has_phenotype some C ==> x Type C
	LOG.info("x Type has_phenotype some C ==> x Type C");
	OWLObjectProperty hasPhenotype = getOWLObjectPropertyViaOBOSuffix(HAS_PHENOTYPE);
	Set<OWLAxiom> rmAxioms = new HashSet<OWLAxiom>();
	Set<OWLAxiom> newAxioms = new HashSet<OWLAxiom>();
	for (OWLClassAssertionAxiom caa : outputOntology.getAxioms(AxiomType.CLASS_ASSERTION)) {
		OWLClassExpression ex = caa.getClassExpression();
		OWLIndividual i = caa.getIndividual();
		if (ex instanceof OWLObjectSomeValuesFrom) {
			OWLObjectSomeValuesFrom svf = (OWLObjectSomeValuesFrom)ex;
			if (svf.getProperty().equals(hasPhenotype)) {
				rmAxioms.add(caa);
				newAxioms.add(getOWLDataFactory().getOWLClassAssertionAxiom(svf.getFiller(), i));
			}

		}
	}
	LOG.info("making instances direct: +"+newAxioms.size()+ " -"+rmAxioms.size());
	addAxiomsToOutput(newAxioms, false);
	removeAxiomsFromOutput(rmAxioms, false);
}
 
Example 3
Source File: ModelAnnotationSolrDocumentLoader.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private OWLClass findFirstType(OWLNamedIndividual relevant) {
	Set<OWLClassAssertionAxiom> axioms = model.getClassAssertionAxioms(relevant);
	for (OWLClassAssertionAxiom axiom : axioms) {
		OWLClassExpression ce = axiom.getClassExpression();
		if (ce.isAnonymous() == false) {
			return ce.asOWLClass();
		}
	}
	return null;
}
 
Example 4
Source File: ABoxUtils.java    From owltools with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public static void mapClassAssertionsUp(OWLOntology ont, OWLReasoner reasoner, Set<OWLClass> targetClasses, Set<OWLClass> inputClasses) {
	Set<OWLAxiom> rmAxioms = new HashSet<OWLAxiom>();
	Set<OWLAxiom> newAxioms = new HashSet<OWLAxiom>();
	Map<OWLClass, Set<OWLClass>> cmap = new HashMap<OWLClass, Set<OWLClass>>();
	LOG.info("Target classes: "+targetClasses.size());
	int n=0;
	for (OWLClassAssertionAxiom ca : ont.getAxioms(AxiomType.CLASS_ASSERTION)) {
		if (ca.getClassExpression().isAnonymous())
			continue;
		OWLClass c = (OWLClass) ca.getClassExpression();
		n++;
		if (inputClasses == null || inputClasses.contains(c)) {
			if (targetClasses.contains(c))
				continue;
			Set<OWLClass> supers;
			if (cmap.containsKey(c)) {
				supers = cmap.get(c);
			}
			else {
				supers = reasoner.getSuperClasses(c, false).getFlattened();
				supers.addAll(reasoner.getEquivalentClasses(c).getEntities());
				LOG.info(c+" has #supers: "+supers.size());
				LOG.info(c + " ===> "+supers);
				supers.retainAll(targetClasses);
				LOG.info(c+" has #supersInTargetSet: "+supers.size());
				supers = getNonRedundant(supers, reasoner);
				//LOG.info(c+" has #NRsupers: "+supers.size());
				//LOG.info(c + " ===> "+supers);
				cmap.put(c, supers);
				if (supers.size() > 0) {
					LOG.info(c + " ===> "+supers);
				}
			}
			rmAxioms.add(ca);
			OWLIndividual individual = ca.getIndividual();
			for (OWLClass sc : supers) {
				newAxioms.add(ont.getOWLOntologyManager().getOWLDataFactory().getOWLClassAssertionAxiom(sc, individual));
			}
		}
	}
	LOG.info("named class assertions (start): "+n);
	LOG.info("rm:"+rmAxioms.size());
	LOG.info("new:"+newAxioms.size());
	ont.getOWLOntologyManager().removeAxioms(ont, rmAxioms);
	ont.getOWLOntologyManager().addAxioms(ont, newAxioms);
}