Java Code Examples for org.semanticweb.owlapi.reasoner.Node#getEntities()

The following examples show how to use org.semanticweb.owlapi.reasoner.Node#getEntities() . 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: ReduceOperation.java    From robot with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private static void findNonRedundant(
    Node<OWLClass> node,
    OWLReasoner reasoner,
    Map<OWLClass, Map<OWLClass, Set<OWLSubClassOfAxiom>>> assertions,
    Set<OWLSubClassOfAxiom> nonredundant,
    Set<Node<OWLClass>> alreadySeen) {
  if (!alreadySeen.contains(node)) {
    NodeSet<OWLClass> subclasses = reasoner.getSubClasses(node.getRepresentativeElement(), true);
    for (OWLClass superclass : node.getEntities()) {
      for (OWLClass subclass : subclasses.getFlattened()) {
        if (assertions.containsKey(superclass)) {
          Map<OWLClass, Set<OWLSubClassOfAxiom>> subclassAxiomsBySubclass =
              assertions.get(superclass);
          if (subclassAxiomsBySubclass.containsKey(subclass)) {
            nonredundant.addAll(subclassAxiomsBySubclass.get(subclass));
          }
        }
      }
    }
    alreadySeen.add(node);
    for (Node<OWLClass> subclassNode : subclasses.getNodes()) {
      findNonRedundant(subclassNode, reasoner, assertions, nonredundant, alreadySeen);
    }
  }
}
 
Example 2
Source File: OWLHandler.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void getLowestCommonSubsumersCommand() throws IOException, OWLOntologyCreationException, OWLOntologyStorageException, UnknownOWLClassException {
	if (isHelp()) {
		info("Returns LCSs using sim2");
		return;
	}
	headerOWL();
	OwlSim sos = getOWLSim();

	Set<OWLObject> objs = this.resolveEntityList();
	if (objs.size() == 2) {
		Iterator<OWLObject> oit = objs.iterator();
		OWLClass a = (OWLClass) oit.next();
		OWLClass b = (OWLClass) oit.next();
		Set<Node<OWLClass>> lcsNodes = sos.getNamedCommonSubsumers(a, b);
		for (Node<OWLClass> n : lcsNodes) {
			for (OWLClass c : n.getEntities()) {
				output(c);
			}
		}
	}
	else {
		// TODO - throw
	}
}
 
Example 3
Source File: OldSimpleOwlSim.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void precomputeAttributeElementCount() {
	if (attributeElementCount != null)
		return;
	attributeElementCount = new HashMap<OWLClass, Integer>();
	for (OWLEntity e : this.getAllElements()) {
		LOG.info("Adding 1 to all attributes of "+e);
		for (OWLClass dc : getAttributesForElement(e)) {
			for (Node<OWLClass> n : this.getNamedReflexiveSubsumers(dc)) {
				for (OWLClass c : n.getEntities()) {
					if (!attributeElementCount.containsKey(c))
						attributeElementCount.put(c, 1);
					else
						attributeElementCount.put(c, attributeElementCount.get(c)+1);
				}
			}

		}
	}
}
 
Example 4
Source File: SimpleOwlSim.java    From owltools with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Mapping between an attribute (e.g. phenotype class) and the number of
 * instances it classifies
 */
protected void precomputeAttributeElementCount() {
	if (attributeElementCount != null) return;
	attributeElementCount = new HashMap<OWLClass, Integer>();
	// some high level attributes will classify all or most of the ABox;
	// this way may be faster...
	for (OWLNamedIndividual e : this.getAllElements()) {
		LOG.info("Incrementing count all attributes of " + e);
		LOG.info(" DIRECT ATTS: " + getAttributesForElement(e).size());
		for (Node<OWLClass> n : this.getInferredAttributes(e)) {
			for (OWLClass c : n.getEntities()) {
				if (!attributeElementCount.containsKey(c))
					attributeElementCount.put(c, 1);
				else
					attributeElementCount.put(c, attributeElementCount.get(c) + 1);
			}
		}
	}
	LOG.info("Finished precomputing attribute element count");
}
 
Example 5
Source File: FastOwlSim.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private OWLClass getIndexedClass(Node<OWLClass> n) throws UnknownOWLClassException {
	if (representativeClassMap == null)
		representativeClassMap = new HashMap<Node<OWLClass>, OWLClass>();
	else if (representativeClassMap.containsKey(n))
		return representativeClassMap.get(n);
	for (OWLClass c : n.getEntities()) {
		if (classIndex.containsKey(c)) {
			representativeClassMap.put(n,c);
			return c;				
		}
	}
	throw new UnknownOWLClassException(getDeterministicRepresentative(n));
}
 
Example 6
Source File: OntologyHelper.java    From BioSolr with Apache License 2.0 5 votes vote down vote up
private Collection<String> getUrisFromNodeSet(NodeSet<OWLClass> nodeSet) {
	Set<String> uris = new HashSet<>();

	for (Node<OWLClass> node : nodeSet) {
		for (OWLClass expr : node.getEntities()) {
			if (isClassSatisfiable(expr)) {
				uris.add(expr.getIRI().toURI().toString());
			}
		}
	}

	return uris;
}
 
Example 7
Source File: InferenceBuilder.java    From owltools with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public ConsistencyReport performConsistencyChecks(){

		if(graph == null){
			return new ConsistencyReport("The ontology is not set.");
		}

		OWLOntology ont = graph.getSourceOntology();
		reasoner = getReasoner(ont);
		long t1 = System.currentTimeMillis();

		logInfo("Consistency check started............");
		boolean consistent = reasoner.isConsistent();

		logInfo("Is the ontology consistent ....................." + consistent + ", " + (System.currentTimeMillis()-t1)/100);

		List<String> errors = new ArrayList<String>();
		Set<OWLEntity> unsatisfiable = new HashSet<OWLEntity>();
		if(!consistent){
			errors.add("The ontology '" + graph.getOntologyId() + " ' is not consistent");
		}

		// We can easily get a list of unsatisfiable classes.  (A class is unsatisfiable if it
		// can't possibly have any instances).  Note that the getunsatisfiableClasses method
		// is really just a convenience method for obtaining the classes that are equivalent
		// to owl:Nothing.
		OWLClass nothing = graph.getDataFactory().getOWLNothing();
		Node<OWLClass> unsatisfiableClasses = reasoner.getUnsatisfiableClasses();
		if (unsatisfiableClasses.getSize() > 0) {
			for(OWLClass cls : unsatisfiableClasses.getEntities()) {
				logInfo("unsat: "+cls.getIRI());
				if (cls.equals(nothing)) {
					// nothing to see here, move along
					continue;
				}
				StringBuilder sb = new StringBuilder();
				sb.append("Unsatisfiable: ").append(graph.getIdentifier(cls));
				String lbl = graph.getLabel(cls);
				if (lbl != null) {
					sb.append(" '").append(lbl).append("'");
				}
				errors.add(sb.toString());
				unsatisfiable.add(cls);
			}
		}


		return new ConsistencyReport(errors, unsatisfiable);

	}