org.semanticweb.owlapi.reasoner.NodeSet Java Examples
The following examples show how to use
org.semanticweb.owlapi.reasoner.NodeSet.
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: OwlApiClassExpressionSubClassesQueryTest.java From elk-reasoner with Apache License 2.0 | 6 votes |
public OwlApiClassExpressionSubClassesQueryTest( final QueryTestManifest<OWLClassExpression, RelatedEntitiesTestOutput<OWLClass>> manifest) { super(manifest, new OwlApiReasoningTestDelegate<RelatedEntitiesTestOutput<OWLClass>>( manifest) { @Override public RelatedEntitiesTestOutput<OWLClass> getActualOutput() throws Exception { final NodeSet<OWLClass> subNodes = getReasoner() .getSubClasses(manifest.getInput().getQuery(), true); return new OwlApiRelatedEntitiesTestOutput<OWLClass>( subNodes); } @Override public Class<? extends Exception> getInterruptionExceptionClass() { return ReasonerInterruptedException.class; } }); }
Example #2
Source File: SimpleOntology.java From mobi with GNU Affero General Public License v3.0 | 6 votes |
@Override public Set<ObjectProperty> getAllClassObjectProperties(IRI iri) { org.semanticweb.owlapi.model.IRI classIRI = SimpleOntologyValues.owlapiIRI(iri); if (owlOntology.containsClassInSignature(classIRI)) { OWLClass owlClass = owlManager.getOWLDataFactory().getOWLClass(classIRI); Node<OWLClass> equivalentClasses = owlReasoner.getEquivalentClasses(owlClass); NodeSet<OWLClass> superClasses = owlReasoner.getSuperClasses(owlClass); return owlOntology.objectPropertiesInSignature(Imports.INCLUDED) .filter(property -> { Set<OWLObjectPropertyDomainAxiom> domains = owlOntology.axioms( OWLObjectPropertyDomainAxiom.class, OWLObjectPropertyExpression.class, property, Imports.INCLUDED, Navigation.IN_SUB_POSITION).collect(Collectors.toSet()); return hasClassAsDomain(domains.stream(), classIRI, equivalentClasses, superClasses) || hasNoDomain(domains.stream()); }) .map(SimpleOntologyValues::mobiObjectProperty) .collect(Collectors.toSet()); } throw new IllegalArgumentException("Class not found in ontology"); }
Example #3
Source File: SimpleOntology.java From mobi with GNU Affero General Public License v3.0 | 6 votes |
@Override public Set<DataProperty> getAllClassDataProperties(IRI iri) { org.semanticweb.owlapi.model.IRI classIRI = SimpleOntologyValues.owlapiIRI(iri); if (owlOntology.containsClassInSignature(classIRI)) { OWLClass owlClass = owlManager.getOWLDataFactory().getOWLClass(classIRI); Node<OWLClass> equivalentClasses = owlReasoner.getEquivalentClasses(owlClass); NodeSet<OWLClass> superClasses = owlReasoner.getSuperClasses(owlClass); return owlOntology.dataPropertiesInSignature(Imports.INCLUDED) .filter(property -> { Set<OWLDataPropertyDomainAxiom> domains = owlOntology.axioms(OWLDataPropertyDomainAxiom.class, OWLDataPropertyExpression.class, property, Imports.INCLUDED, Navigation.IN_SUB_POSITION).collect(Collectors.toSet()); return hasClassAsDomain(domains.stream(), classIRI, equivalentClasses, superClasses) || hasNoDomain(domains.stream()); }) .map(SimpleOntologyValues::mobiDataProperty) .collect(Collectors.toSet()); } throw new IllegalArgumentException("Class not found in ontology"); }
Example #4
Source File: OwlApiClassExpressionSuperClassesQueryTest.java From elk-reasoner with Apache License 2.0 | 6 votes |
public OwlApiClassExpressionSuperClassesQueryTest( final QueryTestManifest<OWLClassExpression, RelatedEntitiesTestOutput<OWLClass>> manifest) { super(manifest, new OwlApiReasoningTestDelegate<RelatedEntitiesTestOutput<OWLClass>>( manifest) { @Override public RelatedEntitiesTestOutput<OWLClass> getActualOutput() throws Exception { final NodeSet<OWLClass> superNodes = getReasoner() .getSuperClasses(manifest.getInput().getQuery(), true); return new OwlApiRelatedEntitiesTestOutput<OWLClass>( superNodes); } @Override public Class<? extends Exception> getInterruptionExceptionClass() { return ReasonerInterruptedException.class; } }); }
Example #5
Source File: QueryingWithNamedClasses.java From elk-reasoner with Apache License 2.0 | 6 votes |
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 #6
Source File: OwlApiClassExpressionInstancesQueryTest.java From elk-reasoner with Apache License 2.0 | 6 votes |
public OwlApiClassExpressionInstancesQueryTest( final QueryTestManifest<OWLClassExpression, RelatedEntitiesTestOutput<OWLNamedIndividual>> manifest) { super(manifest, new OwlApiReasoningTestDelegate<RelatedEntitiesTestOutput<OWLNamedIndividual>>( manifest) { @Override public RelatedEntitiesTestOutput<OWLNamedIndividual> getActualOutput() throws Exception { final NodeSet<OWLNamedIndividual> subNodes = getReasoner() .getInstances(manifest.getInput().getQuery(), true); return new OwlApiRelatedEntitiesTestOutput<OWLNamedIndividual>( subNodes); } @Override public Class<? extends Exception> getInterruptionExceptionClass() { return ReasonerInterruptedException.class; } }); }
Example #7
Source File: ReduceOperation.java From robot with BSD 3-Clause "New" or "Revised" License | 6 votes |
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 #8
Source File: GraphReasoner.java From owltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
public NodeSet<OWLNamedIndividual> getInstances(OWLClassExpression ce, boolean direct) throws InconsistentOntologyException, ClassExpressionNotInProfileException, FreshEntitiesException, ReasonerInterruptedException, TimeOutException { DefaultNodeSet<OWLNamedIndividual> result = new OWLNamedIndividualNodeSet(); Set<OWLObject> subs = gw.queryDescendants(ce, true, true); for (OWLObject s : subs) { if (s instanceof OWLNamedIndividual) { result.addEntity((OWLNamedIndividual) s); } else { } } return result; }
Example #9
Source File: GraphReasoner.java From owltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
public NodeSet<OWLClass> getSuperClasses(OWLClassExpression ce, boolean direct) throws InconsistentOntologyException, ClassExpressionNotInProfileException, FreshEntitiesException, ReasonerInterruptedException, TimeOutException { DefaultNodeSet<OWLClass> result = new OWLClassNodeSet(); Set<OWLObject> supers = gw.getSubsumersFromClosure(ce); for (OWLObject sup : supers) { if (sup instanceof OWLClassExpression) { if (sup instanceof OWLClass) { result.addEntity((OWLClass) sup); } else { } } else { } } return result; }
Example #10
Source File: GraphReasoner.java From owltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
public NodeSet<OWLClass> getSubClasses(OWLClassExpression ce, boolean direct) throws ReasonerInterruptedException, TimeOutException, FreshEntitiesException, InconsistentOntologyException, ClassExpressionNotInProfileException { DefaultNodeSet<OWLClass> result = new OWLClassNodeSet(); Set<OWLObject> subs = gw.queryDescendants(ce, false, true); for (OWLObject s : subs) { if (s instanceof OWLClassExpression) { if (s instanceof OWLClass) { result.addEntity((OWLClass) s); } else { } } else { } } return result; }
Example #11
Source File: OntologyHelper.java From BioSolr with Apache License 2.0 | 5 votes |
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 #12
Source File: GraphReasoner.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
public NodeSet<OWLObjectPropertyExpression> getSuperObjectProperties( OWLObjectPropertyExpression pe, boolean direct) throws InconsistentOntologyException, FreshEntitiesException, ReasonerInterruptedException, TimeOutException { // TODO Auto-generated method stub return null; }
Example #13
Source File: LegoTools.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
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; }
Example #14
Source File: GraphReasoner.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
public NodeSet<OWLNamedIndividual> getDifferentIndividuals( OWLNamedIndividual ind) throws InconsistentOntologyException, FreshEntitiesException, ReasonerInterruptedException, TimeOutException { // TODO Auto-generated method stub return null; }
Example #15
Source File: GraphReasoner.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
public NodeSet<OWLNamedIndividual> getObjectPropertyValues( OWLNamedIndividual ind, OWLObjectPropertyExpression pe) throws InconsistentOntologyException, FreshEntitiesException, ReasonerInterruptedException, TimeOutException { // TODO Auto-generated method stub return null; }
Example #16
Source File: GraphReasoner.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
public NodeSet<OWLClass> getDataPropertyDomains(OWLDataProperty pe, boolean direct) throws InconsistentOntologyException, FreshEntitiesException, ReasonerInterruptedException, TimeOutException { // TODO Auto-generated method stub return null; }
Example #17
Source File: DLQueryTool.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * 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 #18
Source File: GraphReasoner.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
public NodeSet<OWLClass> getObjectPropertyDomains( OWLObjectPropertyExpression pe, boolean direct) throws InconsistentOntologyException, FreshEntitiesException, ReasonerInterruptedException, TimeOutException { // TODO Auto-generated method stub return null; }
Example #19
Source File: GraphReasoner.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
public NodeSet<OWLClass> getObjectPropertyRanges( OWLObjectPropertyExpression pe, boolean direct) throws InconsistentOntologyException, FreshEntitiesException, ReasonerInterruptedException, TimeOutException { // TODO Auto-generated method stub return null; }
Example #20
Source File: GraphReasoner.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
public NodeSet<OWLObjectPropertyExpression> getDisjointObjectProperties( OWLObjectPropertyExpression pe) throws InconsistentOntologyException, FreshEntitiesException, ReasonerInterruptedException, TimeOutException { // TODO Auto-generated method stub return null; }
Example #21
Source File: OWLOntologyHelper.java From BioSolr with Apache License 2.0 | 5 votes |
private Collection<String> getUrisFromNodeSet(NodeSet<OWLClass> nodeSet) { Set<String> uris = new HashSet<>(); for (Node<OWLClass> node : nodeSet) { uris.addAll(extractIris(node)); } return uris; }
Example #22
Source File: GraphReasoner.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
public NodeSet<OWLDataProperty> getDisjointDataProperties( OWLDataPropertyExpression pe) throws InconsistentOntologyException, FreshEntitiesException, ReasonerInterruptedException, TimeOutException { // TODO Auto-generated method stub return null; }
Example #23
Source File: LazyExpressionMaterializingReasoner.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
public NodeSet<OWLNamedIndividual> getInstances(OWLClassExpression ce, boolean direct) throws InconsistentOntologyException, ClassExpressionNotInProfileException, FreshEntitiesException, ReasonerInterruptedException, TimeOutException { if (ce.isAnonymous()) { OWLClass c = materializeExpression(ce); return getInstances(c, direct); } return getWrappedReasoner().getInstances(ce, direct); }
Example #24
Source File: LazyExpressionMaterializingReasoner.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
public NodeSet<OWLClass> getSuperClasses(OWLClassExpression ce, boolean direct) throws InconsistentOntologyException, ClassExpressionNotInProfileException, FreshEntitiesException, ReasonerInterruptedException, TimeOutException { if (ce.isAnonymous()) { OWLClass c = materializeExpression(ce); return getSuperClasses(c, direct); } return getWrappedReasoner().getSuperClasses(ce, direct); }
Example #25
Source File: LazyExpressionMaterializingReasoner.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
public NodeSet<OWLClass> getSubClasses(OWLClassExpression ce, boolean direct) throws ReasonerInterruptedException, TimeOutException, FreshEntitiesException, InconsistentOntologyException, ClassExpressionNotInProfileException { if (ce.isAnonymous()) { OWLClass c = materializeExpression(ce); return getSubClasses(c, direct); } return getWrappedReasoner().getSubClasses(ce, direct); }
Example #26
Source File: TBoxUnFoldingTool.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Create a new instance for the given ontology graph. Use the given set of parent * ids to retrieve the classes which are to be unfolded. * * @param graph ontology * @param parents set of OBO-style ids * @param reasonerName type of reasoner to be used for inferring the relevant sub classes of the parent set. * @throws NonDeterministicUnfoldException */ public TBoxUnFoldingTool(OWLGraphWrapper graph, Set<String> parents, String reasonerName) throws NonDeterministicUnfoldException { this.graph = graph; this.ontology = graph.getSourceOntology(); final InferenceBuilder inferenceBuilder = new InferenceBuilder(graph, reasonerName); final OWLReasoner reasoner = inferenceBuilder.getReasoner(ontology); final Set<OWLClass> unfoldClasses = new HashSet<OWLClass>(); try { for(String parent : parents) { OWLClass parentClass = graph.getOWLClassByIdentifier(parent); NodeSet<OWLClass> nodeSet = reasoner.getSubClasses(parentClass , false); if (nodeSet != null && !nodeSet.isEmpty() && !nodeSet.isBottomSingleton()) { unfoldClasses.addAll(nodeSet.getFlattened()); } } } finally { inferenceBuilder.dispose(); } if (unfoldClasses.isEmpty()) { throw new RuntimeException("No classes found for given parents."); } visitor = new UnfoldingVisitor(unfoldClasses, ontology); }
Example #27
Source File: ReasonerTaxonomyWalker.java From snomed-owl-toolkit with Apache License 2.0 | 5 votes |
public ReasonerTaxonomy walk() { LOGGER.info(">>> SnomedTaxonomy extraction"); extractProperties(); // Now process the concepts final Deque<Node<OWLClass>> nodesToProcess = new LinkedList<>(); nodesToProcess.add(reasoner.getTopClassNode()); // Breadth-first walk through the class hierarchy while (!nodesToProcess.isEmpty()) { final Node<OWLClass> currentNode = nodesToProcess.removeFirst(); final NodeSet<OWLClass> nextNodeSet = walkClasses(currentNode); if (!nextNodeSet.isEmpty()) { nodesToProcess.addAll(nextNodeSet.getNodes()); } } processedConceptIds.clear(); processedConceptIds = null; // Move attribute ids to after 'Concept model attribute' concept so they are processed in the correct order. List<Long> attributeIds = taxonomy.getAttributeIds(); attributeIds.remove(Concepts.CONCEPT_MODEL_ATTRIBUTE_LONG); List<Long> conceptIds = taxonomy.getConceptIds(); conceptIds.removeAll(attributeIds); conceptIds.addAll(conceptIds.indexOf(Concepts.CONCEPT_MODEL_ATTRIBUTE_LONG) + 1, attributeIds); LOGGER.info("<<< taxonomy extraction"); return taxonomy; }
Example #28
Source File: RedundantAxiomTagger.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static void tagRedundantAxioms(OWLReasoner reasoner) { OWLOntology ont = reasoner.getRootOntology(); OWLOntologyManager mgr = ont.getOWLOntologyManager(); OWLDataFactory df = mgr.getOWLDataFactory(); OWLAnnotationProperty anProp = df.getOWLAnnotationProperty(IRI.create("http://www.geneontology.org/formats/oboInOwl#source")); for (OWLSubClassOfAxiom ax : ont.getAxioms(AxiomType.SUBCLASS_OF)) { if (!ax.getSuperClass().isAnonymous()) { OWLClass supc = (OWLClass) ax.getSuperClass(); mgr.removeAxiom(ont, ax); reasoner.flush(); NodeSet<OWLClass> ancs = reasoner.getSuperClasses(ax.getSubClass(), false); //LOG.info(ax + " ANCS="+ancs); if (ancs.containsEntity( supc)) { String direct = "indirect"; if (reasoner.getSuperClasses(ax.getSubClass(), true).containsEntity( supc)) { direct = "direct"; } LOG.info("SCA = "+ax+" D="+direct); OWLAnnotation ann = df.getOWLAnnotation(anProp, df.getOWLLiteral(direct)); OWLAxiom newAxiom = changeAxiomAnnotations(ax, Collections.singleton(ann), df); mgr.addAxiom(ont, newAxiom); } else { // put it back mgr.addAxiom(ont, ax); } } } }
Example #29
Source File: GoIPICatalyticActivityRestrictionsRule.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
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 #30
Source File: GoIEPRestrictionsRule.java From owltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
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(); } }