/** * Perform any initial processing and caching. This call is optional. Most * engines either have negligable set up work or will perform an implicit * "prepare" if necessary. The call is provided for those occasions where * substantial preparation work is possible (e.g. running a forward chaining * rule system) and where an application might wish greater control over when * this preparation is done rather than just leaving to be done at first query time. */ @Override public void prepare() { getInfGraph().prepare(); }
/** * Get the single static precomputed rule closure. */ protected synchronized InfGraph getPreload() { if (cachePreload && preload == null) { preload = (new FBRuleInfGraph(this, rules, null)); preload.prepare(); } return preload; }
/** * Get the single static precomputed rule closure. */ protected synchronized InfGraph getPreload() { if (cachePreload && preload == null) { preload = (new FBRuleInfGraph(this, rules, null)); preload.prepare(); } return preload; }
/** * Perform any initial processing and caching. This call is optional. Most * engines either have negligable set up work or will perform an implicit * "prepare" if necessary. The call is provided for those occasions where * substantial preparation work is possible (e.g. running a forward chaining * rule system) and where an application might wish greater control over when * this preparation is done rather than just leaving to be done at first query time. */ @Override public void prepare() { getInfGraph().prepare(); }
/** * Perform any initial processing and caching. This call is optional. Most * engines either have negligable set up work or will perform an implicit * "prepare" if necessary. The call is provided for those occasions where * substantial preparation work is possible (e.g. running a forward chaining * rule system) and where an application might wish greater control over when * this prepration is done rather than just leaving to be done at first query time. */ @Override public void prepare() { if (getGraph() instanceof InfGraph) { ((InfGraph) getGraph()).prepare(); } }
/** * Perform any initial processing and caching. This call is optional. Most * engines either have negligable set up work or will perform an implicit * "prepare" if necessary. The call is provided for those occasions where * substantial preparation work is possible (e.g. running a forward chaining * rule system) and where an application might wish greater control over when * this prepration is done rather than just leaving to be done at first query time. */ @Override public void prepare() { if (getGraph() instanceof InfGraph) { ((InfGraph) getGraph()).prepare(); } }
/** * Get the single static precomputed rule closure. */ @Override protected synchronized InfGraph getPreload() { // We only support this in HYBRID mode if (cachePreload && preload == null && mode == HYBRID) { preload = new FBRuleInfGraph( this, rules, null, Factory.createDefaultGraph() ); if (enableTGCCaching) ((FBRuleInfGraph)preload).setUseTGCCache(); preload.prepare(); } return preload; }
/** * Get the single static precomputed rule closure. */ @Override protected synchronized InfGraph getPreload() { // We only support this in HYBRID mode if (cachePreload && preload == null && mode == HYBRID) { preload = new FBRuleInfGraph( this, rules, null, Factory.createDefaultGraph() ); if (enableTGCCaching) ((FBRuleInfGraph)preload).setUseTGCCache(); preload.prepare(); } return preload; }
@Override protected MultiValueMap<ATermAppl, ATermAppl> run(final Collection<ATermAppl> classes) { addClasses(classes); addClasses(_names.getAllAnons()); final Reasoner reasoner = new GenericRuleReasoner(new ArrayList<>(_rules)); final InfGraph inf = reasoner.bind(_facts); inf.prepare(); final MultiValueMap<ATermAppl, ATermAppl> subsumers = getSubsumptions(inf); for (final ATermAppl c : classes) subsumers.add(ATermUtils.BOTTOM, c); return subsumers; }
@Override protected MultiValueMap<ATermAppl, ATermAppl> run(final Collection<ATermAppl> classes) { addClasses(classes); addClasses(_names.getAllAnons()); final Reasoner reasoner = new GenericRuleReasoner(new ArrayList<>(_rules)); final InfGraph inf = reasoner.bind(_facts); inf.prepare(); final MultiValueMap<ATermAppl, ATermAppl> subsumers = getSubsumptions(inf); for (final ATermAppl c : classes) subsumers.add(ATermUtils.BOTTOM, c); return subsumers; }
@Override protected MultiValueMap<ATermAppl, ATermAppl> run(final Collection<ATermAppl> classes) { addClasses(classes); addClasses(_names.getAllAnons()); final Reasoner reasoner = new GenericRuleReasoner(new ArrayList<>(_rules)); final InfGraph inf = reasoner.bind(_facts); inf.prepare(); final MultiValueMap<ATermAppl, ATermAppl> subsumers = getSubsumptions(inf); for (final ATermAppl c : classes) subsumers.add(ATermUtils.BOTTOM, c); return subsumers; }
/** * <p>Returns a derivations model. The rule reasoners typically create a * graph containing those triples added to the base graph due to rule firings. * In some applications it can useful to be able to access those deductions * directly, without seeing the raw data which triggered them. In particular, * this allows the forward rules to be used as if they were rewrite transformation * rules.</p> * * @return The derivations model, if one is defined, or else null */ @Override public Model getDeductionsModel() { if (m_deductionsModel == null) { InfGraph infGraph = getInfGraph(); if (infGraph != null) { Graph deductionsGraph = infGraph.getDeductionsGraph(); if (deductionsGraph != null) { m_deductionsModel = ModelFactory.createModelForGraph( deductionsGraph ); } } } else { // ensure that the cached model sees the updated changes from the // underlying reasoner graph getInfGraph().prepare(); } return m_deductionsModel; }
/** * <p>Returns a derivations model. The rule reasoners typically create a * graph containing those triples added to the base graph due to rule firings. * In some applications it can useful to be able to access those deductions * directly, without seeing the raw data which triggered them. In particular, * this allows the forward rules to be used as if they were rewrite transformation * rules.</p> * * @return The derivations model, if one is defined, or else null */ @Override public Model getDeductionsModel() { if (m_deductionsModel == null) { InfGraph infGraph = getInfGraph(); if (infGraph != null) { Graph deductionsGraph = infGraph.getDeductionsGraph(); if (deductionsGraph != null) { m_deductionsModel = ModelFactory.createModelForGraph( deductionsGraph ); } } } else { // ensure that the cached model sees the updated changes from the // underlying reasoner graph getInfGraph().prepare(); } return m_deductionsModel; }
/** * Test early detection of illegal backward rules. */ public void testBRuleErrorHandling() { Graph data = Factory.createGraphMem(); List<Rule> rules = Rule.parseRules( "[a1: -> [(?x eg:p ?y) (?x eg:q ?y) <- (?x eg:r ?y)]]" ); boolean foundException = false; try { GenericRuleReasoner reasoner = (GenericRuleReasoner)GenericRuleReasonerFactory.theInstance().create(null); reasoner.setRules(rules); reasoner.setMode(GenericRuleReasoner.HYBRID); InfGraph infgraph = reasoner.bind(data); infgraph.prepare(); } catch (ReasonerException e) { foundException = true; } assertTrue("Catching use of multi-headed brules", foundException); }
/** * Test early detection of illegal backward rules. */ public void testBRuleErrorHandling() { Graph data = Factory.createGraphMem(); List<Rule> rules = Rule.parseRules( "[a1: -> [(?x eg:p ?y) (?x eg:q ?y) <- (?x eg:r ?y)]]" ); boolean foundException = false; try { GenericRuleReasoner reasoner = (GenericRuleReasoner)GenericRuleReasonerFactory.theInstance().create(null); reasoner.setRules(rules); reasoner.setMode(GenericRuleReasoner.HYBRID); InfGraph infgraph = reasoner.bind(data); infgraph.prepare(); } catch (ReasonerException e) { foundException = true; } assertTrue("Catching use of multi-headed brules", foundException); }
/** * Test regex handling of null groups */ public void testRegexNulls() { String rules = "[r2: (?x p ?y) regex(?y, '((Boys)|(Girls))(.*)', ?m1, ?m2, ?m3, ?m4) -> (?x q ?m2) (?x r ?m3) (?x s ?m4) ] \n" + ""; Graph data = Factory.createGraphMem(); data.add(new Triple(n1, p, NodeFactory.createLiteral("Girls44")) ); InfGraph infgraph = createInfGraph(rules, data); infgraph.prepare(); TestUtil.assertIteratorValues(this, infgraph.getDeductionsGraph().find(null, null, null), new Triple[] { new Triple(n1, q, NodeFactory.createLiteral("")), new Triple(n1, r, NodeFactory.createLiteral("Girls")), new Triple(n1, s, NodeFactory.createLiteral("44")), }); }
/** * Test regex handling of null groups */ public void testRegexNulls() { String rules = "[r2: (?x p ?y) regex(?y, '((Boys)|(Girls))(.*)', ?m1, ?m2, ?m3, ?m4) -> (?x q ?m2) (?x r ?m3) (?x s ?m4) ] \n" + ""; Graph data = Factory.createGraphMem(); data.add(new Triple(n1, p, NodeFactory.createLiteral("Girls44")) ); InfGraph infgraph = createInfGraph(rules, data); infgraph.prepare(); TestUtil.assertIteratorValues(this, infgraph.getDeductionsGraph().find(null, null, null), new Triple[] { new Triple(n1, q, NodeFactory.createLiteral("")), new Triple(n1, r, NodeFactory.createLiteral("Girls")), new Triple(n1, s, NodeFactory.createLiteral("44")), }); }
infgraph.prepare(); Graph result = infgraph.getDeductionsGraph(); assertEquals(1, result.size());