/** * Tries to shut down the reasoner within 1 minute * * @return {@code true} if the operation was successful * @throws InterruptedException * if the current thread was interrupted */ public synchronized boolean shutdown() throws InterruptedException { return shutdown(1, TimeUnit.MINUTES); }
/** * Check if the given {@link ElkClassExpression} is satisfiable, that is, if * it can possibly have instances. {@link ElkClassExpression}s are not * satisfiable if they are equivalent to {@code owl:Nothing}. A satisfiable * {@link ElkClassExpression} is also called consistent or coherent. Calling * of this method may trigger the computation of the taxonomy, if it has not * been done yet. * * @param classExpression * the {@link ElkClassExpression} for which to check * satisfiability * @return {@code true} if the given input is satisfiable * @throws ElkException * if the result cannot be computed */ public synchronized boolean isSatisfiable( ElkClassExpression classExpression) throws ElkException { if (classExpression instanceof ElkClass) { final TaxonomyNode<ElkClass> queryNode = getTaxonomyNode( (ElkClass) classExpression); return !queryNode.contains(getElkFactory().getOwlNothing()); } return querySatisfiability(classExpression); }
throws ElkException { try { return getInstances(classExpression, direct); } catch (final ElkInconsistentOntologyException e) { final TypeNode<ElkClass, ElkNamedIndividual> node = getInstanceTaxonomyQuietly() .getBottomNode(); return direct ? node.getDirectInstanceNodes()
/** * Return the {@code Node} containing equivalent classes of the given * {@link ElkClassExpression}. Calling of this method may trigger the * computation of the taxonomy, if it has not been done yet. * * @param classExpression * the {@link ElkClassExpression} for which to return the * {@link Node} * @return the set of {@link Node} whose members are {@link ElkClass}es * equivalent to the given {@link ElkClassExpression} * @throws ElkException * if the result cannot be computed */ public synchronized Node<ElkClass> getEquivalentClassesQuietly( ElkClassExpression classExpression) throws ElkException { try { return getEquivalentClasses(classExpression); } catch (final ElkInconsistentOntologyException e) { // All classes are equivalent to each other, so also to owl:Nothing. return getTaxonomyQuietly().getBottomNode(); } }
/** * Return the (direct or indirect) subclasses of the given * {@link ElkClassExpression} as specified by the parameter. The method * returns a set of {@link Node}s, each of which representing an equivalent * class of subclasses. Calling of this method may trigger the computation * of the taxonomy, if it has not been done yet. * * @param classExpression * the {@link ElkClassExpression} for which to return the * subclass {@link Node}s * @param direct * if {@code true}, only direct subclasses should be returned * @return the set of {@link Node}s for direct or indirect subclasses of the * given {@link ElkClassExpression} according to the specified * parameter * @throws ElkException * if the result cannot be computed */ public synchronized Set<? extends Node<ElkClass>> getSubClassesQuietly( final ElkClassExpression classExpression, final boolean direct) throws ElkException { try { return getSubClasses(classExpression, direct); } catch (final ElkInconsistentOntologyException e) { // All classes are equivalent to each other, so also to owl:Nothing. final TaxonomyNode<ElkClass> node = getTaxonomyQuietly() .getBottomNode(); return direct ? node.getDirectSubNodes() : node.getAllSubNodes(); } }
Taxonomy<ElkClass> taxonomy = reasoner.getTaxonomyQuietly(); InstanceTaxonomy<ElkClass, ElkNamedIndividual> instanceTaxonomy = reasoner.getInstanceTaxonomyQuietly(); boolean isConsistent = reasoner.isInconsistent(); reasoner.shutdown();
@Override public void precomputeInferences(InferenceType... inferenceTypes) throws ReasonerInterruptedException, TimeOutException, InconsistentOntologyException { LOGGER_.trace("precomputeInferences(InferenceType...)"); checkInterrupted(); // we use the main progress monitor only here this.reasoner_.setProgressMonitor(this.mainProgressMonitor_); try { for (InferenceType inferenceType : inferenceTypes) { if (inferenceType.equals(InferenceType.CLASS_HIERARCHY)) reasoner_.getTaxonomy(); else if (inferenceType.equals(InferenceType.CLASS_ASSERTIONS)) reasoner_.getInstanceTaxonomy(); else if (inferenceType .equals(InferenceType.OBJECT_PROPERTY_HIERARCHY)) { reasoner_.getObjectPropertyTaxonomy(); } } } catch (ElkUnsupportedReasoningTaskException e) { throw unsupportedOwlApiMethod( "precomputeInferences(inferenceTypes)", e.getMessage()); } catch (ElkException e) { throw elkConverter_.convert(e); } catch (ElkRuntimeException e) { throw elkConverter_.convert(e); } finally { this.reasoner_.setProgressMonitor(this.secondaryProgressMonitor_); } }
Reasoner reasoner = TestReasonerUtils.createTestReasoner(loader); reasoner.setAllowIncrementalMode(false); reasoner.getInstanceTaxonomyQuietly(); reasoner.setAllowIncrementalMode(true); reasoner.registerAxiomLoader(new TestAxiomLoaderFactory(changeLoader)); reasoner.getInstanceTaxonomyQuietly(); reasoner.getInstanceTaxonomyQuietly(); changeLoader.remove(axDisj); reasoner.getInstanceTaxonomyQuietly();
reasoner.setAllowIncrementalMode(false); assertFalse(reasoner.isInconsistent()); reasoner.getTaxonomy(); reasoner.setAllowIncrementalMode(true); reasoner.registerAxiomLoader(new TestAxiomLoaderFactory(changeLoader)); assertTrue(reasoner.isInconsistent());
@Override public void accept(TracingTestVisitor visitor) throws Exception { if (reasoner_.isInconsistent()) { Factory elkFactory = reasoner_.getElkFactory(); visitor.testSubsumption(elkFactory.getOwlThing(), elkFactory.getOwlNothing()); Taxonomy<ElkClass> classTaxonomy = reasoner_.getTaxonomy();
this.owlOntologymanager_.addOntologyChangeProgessListener( ontologyChangeProgressListener_); this.objectFactory_ = internalReasoner.getElkFactory(); this.owlConverter_ = OwlConverter.getInstance(); this.elkConverter_ = ElkConverter.getInstance(); reasoner_.registerAxiomLoader(bufferedChangesLoader_);
throws ElkException { try { return getSuperClasses(classExpression, direct); } catch (final ElkInconsistentOntologyException e) { final TaxonomyNode<ElkClass> node = getTaxonomyQuietly() .getBottomNode(); return direct ? node.getDirectSuperNodes()
Reasoner reasoner = TestReasonerUtils.createTestReasoner(loader); reasoner.setAllowIncrementalMode(false); Taxonomy<ElkClass> taxonomy = reasoner.getTaxonomyQuietly(); reasoner.setAllowIncrementalMode(true); TestChangesLoader changeLoader = new TestChangesLoader(); reasoner.registerAxiomLoader(new TestAxiomLoaderFactory(changeLoader)); taxonomy = reasoner.getTaxonomyQuietly();
@Test public void randomWalk() throws Exception { // axioms that can change OnOffVector<ElkAxiom> changingAxioms = new OnOffVector<ElkAxiom>(128); // other axioms that do not change List<ElkAxiom> staticAxioms = new ArrayList<ElkAxiom>(); Reasoner incrementalReasoner; long seed = RandomSeedProvider.VALUE; LOGGER_.info("Initial load of test axioms"); InputStream stream = manifest.getInput().getUrl().openStream(); AxiomLoader fileLoader = new Owl2StreamLoader.Factory( new Owl2FunctionalStyleParserFactory(), stream).getAxiomLoader(DummyInterruptMonitor.INSTANCE); TestAxiomLoader trackingLoader = getAxiomTrackingLoader(fileLoader, changingAxioms, staticAxioms); incrementalReasoner = TestReasonerUtils.createTestReasoner( trackingLoader); incrementalReasoner.setAllowIncrementalMode(true); try { // incrementalReasoner.loadAxioms(); // let the runner run.. getRandomWalkRunner(MAX_ROUNDS, ITERATIONS).run( incrementalReasoner, changingAxioms, staticAxioms, seed); } catch (Exception e) { throw new ElkRuntimeException("Seed " + seed, e); } finally { stream.close(); assertTrue(incrementalReasoner.shutdown()); } }
throws ElkException { final ElkObject.Factory elkFactory = reasoner.getElkFactory(); final EntailmentQueryResult result = reasoner.isEntailed( elkFactory.getSubClassOfAxiom(subClass, superClass)); result.accept(
protected static void printResult(Reasoner reasoner, Writer writer) throws IOException, ElkException { Taxonomy<ElkClass> taxonomy = reasoner.getTaxonomyQuietly(); TaxonomyPrinter.dumpTaxomomy(taxonomy, writer, false); writer.flush(); }
@Override public InstanceTaxonomy<ElkClass, ElkNamedIndividual> getTaxonomy(final String resource) throws ElkException { final Reasoner reasoner = TestReasonerUtils.createTestReasoner( getClass().getClassLoader().getResourceAsStream(resource), 1); return reasoner.getInstanceTaxonomy(); } @Override
public ElkProofGenerator(final Proof<? extends EntailmentInference> evidence, final Reasoner reasoner, final ElkInference.Factory inferenceFactory) { this(evidence, reasoner, reasoner.getElkFactory(), inferenceFactory); }
@Override protected String getResultHash(Reasoner reasoner) throws ElkException { InstanceTaxonomy<ElkClass, ElkNamedIndividual> taxonomy = reasoner .getInstanceTaxonomyQuietly(); return TaxonomyPrinter.getInstanceHashString(taxonomy); }
private Node<OWLClass> getClassNode(ElkClass elkClass) throws FreshEntitiesException, InconsistentOntologyException, ElkException { try { return elkConverter_ .convertClassNode(reasoner_.getEquivalentClasses(elkClass)); } catch (ElkException e) { throw elkConverter_.convert(e); } }