Java Code Examples for org.semanticweb.owlapi.reasoner.NodeSet#getFlattened()

The following examples show how to use org.semanticweb.owlapi.reasoner.NodeSet#getFlattened() . 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: QueryingWithNamedClasses.java    From elk-reasoner with Apache License 2.0 6 votes vote down vote up
public Set<OWLClass> getSubClasses(String expression) {
	// Convert the class expression (string) into an OWL class expression,
	// which is used to retrieved the named class.
	// In principle, this allows for parsing arbitrary class expressions in
	// OWL, not just named classes (for which a simple
	// OWLDataFactory.getOWLClass(..) would do. However, Elk currently
	// doesn't yet implement getSubClasses for class expressions.
	// It will be supported in a future release.
	OWLClassExpression classExpression = parseClassExpression(expression
			.trim());
	// The flag "true" means that we want to retrieve only the direct
	// subclasses. The flag set in "false" should retrieve the descendant
	// classes.
	NodeSet<OWLClass> subClasses = reasoner.getSubClasses(classExpression,
			true);
	// IMPORTANT: This method will stop the reasoning process and free the
	// Elk threads/workers.
	reasoner.dispose();

	return subClasses.getFlattened();
}
 
Example 2
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 3
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 4
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 5
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 6
Source File: LegoTools.java    From owltools with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private OWLClassExpression getType(OWLNamedIndividual individual) {
	NodeSet<OWLClass> types = reasoner.getTypes(individual, true);
	if (types.isEmpty() || types.isBottomSingleton() || types.isTopSingleton()) {
		return null;
	}
	Set<OWLClass> set = types.getFlattened();
	
	if (set.size() == 1) {
		return set.iterator().next();
	}
	OWLDataFactory fac = graph.getManager().getOWLDataFactory();
	OWLObjectIntersectionOf intersectionOf = fac.getOWLObjectIntersectionOf(set);
	return intersectionOf;
	
}