/** * Return an inference graph working over the given rule set and raw data. * Can be overridden by subclasses of this test class. * @param rules the rule set to use * @param data the graph of triples to process */ public InfGraph makeInfGraph(List<Rule> rules, Graph data) { FBRuleReasoner reasoner = new FBRuleReasoner(rules); FBRuleInfGraph infgraph = (FBRuleInfGraph) reasoner.bind(data); // infgraph.setTraceOn(true); return infgraph; }
/** * Precompute the implications of a schema Model. The statements in the graph * will be combined with the data when the final InfGraph is created. */ @Override public Reasoner bindSchema(Model tbox) throws ReasonerException { return bindSchema(tbox.getGraph()); }
/** Set a parameter from a statement, given the property and its RDFNode value. Most parameters are, historically, set from the string value of the RDFNode, but newer parameters may have Resource values with embedded models, for which their toString() is not just suspect, but definitively wrong. Hence the introduction of this relay station. @param parameter the propoerty naming the value to set @param value the RDFNode with the value of that property @return true if the property was understood, false otherwise */ protected boolean doSetRDFNodeParameter( Property parameter, RDFNode value ) { return (value instanceof Resource && doSetResourceParameter( parameter, (Resource) value )) || (value instanceof Literal && doSetParameter( parameter, ((Literal)value).getValue() )) || doSetParameter(parameter, value.toString()) ; }
public FBRuleReasoner createReasoner(List<Rule> rules) { FBRuleReasoner reasoner = new FBRuleReasoner(rules); reasoner.tablePredicate(RDFS.Nodes.subClassOf); reasoner.tablePredicate(RDF.Nodes.type); reasoner.tablePredicate(p); return reasoner; }
/** * Precompute the implications of a schema graph. The statements in the graph * will be combined with the data when the final InfGraph is created. */ @Override public Reasoner bindSchema(Graph tbox) throws ReasonerException { if (schemaGraph != null) { throw new ReasonerException("Can only bind one schema at a time to an OWLRuleReasoner"); } FBRuleInfGraph graph = new FBRuleInfGraph(this, rules, getPreload(), tbox); graph.prepare(); FBRuleReasoner fbr = new FBRuleReasoner(rules, graph, factory); fbr.setDerivationLogging(recordDerivations); fbr.setTraceOn(traceOn); return fbr; }
/** * Return the reasoner to test */ public static Reasoner makeReasoner() { FBRuleReasoner reasoner = new FBRuleReasoner(loadRules()); // Don't have TGC enable yet. return reasoner; }
return super.doSetParameter( parameter, value );
public void testSchema() { Model schema = model( "P rdf:type owl:ObjectProperty" ); Resource root = resourceInModel( "x rdf:type ja:ReasonerFactory; x ja:schema S" ); Assembler sub = new NamedObjectAssembler( resource( "S" ), schema ); ReasonerFactory rf = (ReasonerFactory) ASSEMBLER.open( sub, root ); Reasoner r = rf.create( null ); assertIsomorphic( schema.getGraph(), ((FBRuleReasoner) r).getBoundSchema() ); }
/** * Constructor * @param factory the parent reasoner factory which is consulted to answer capability questions * @param configuration RDF node to configure the rule set and mode, can be null */ public FBRuleReasoner(ReasonerFactory factory, Resource configuration) { this( new ArrayList<Rule>(), factory); this.configuration = configuration; if (configuration != null) loadConfiguration( configuration ); }
/** * Cause the inference graph to reconsult both the underlying graph and * the reasoner ruleset, permits the forward rule set to be dynamically changed. * Causes the entire rule engine to be rebuilt from the current ruleset and * reinitialized against the current data. Not needed for normal cases. */ public void rebindAll() { rawRules = ((FBRuleReasoner)reasoner).getRules(); instantiateRuleEngine( rawRules ); rebind(); }
/** load the configuration from the configuring Resource (in its Model). */ protected void loadConfiguration( Resource configuration ) { StmtIterator i = configuration.listProperties(); while (i.hasNext()) { Statement st = i.nextStatement(); doSetRDFNodeParameter( st.getPredicate(), st.getObject() ); } }
/** * Attach the reasoner to a set of RDF data to process. * The reasoner may already have been bound to specific rules or ontology * axioms (encoded in RDF) through earlier bindRuleset calls. * * @param data the RDF data to be processed, some reasoners may restrict * the range of RDF which is legal here (e.g. syntactic restrictions in OWL). * @return an inference graph through which the data+reasoner can be queried. * @throws ReasonerException if the data is ill-formed according to the * constraints imposed by this reasoner. */ @Override public InfGraph bind( Graph data ) throws ReasonerException { Graph schemaArg = schemaGraph == null ? getPreload() : (FBRuleInfGraph) schemaGraph; FBRuleInfGraph graph = new FBRuleInfGraph( this, rules, schemaArg ); graph.setDerivationLogging( recordDerivations ); graph.setTraceOn( traceOn ); graph.rebind( data ); return graph; }
public FBRuleReasoner createReasoner(List<Rule> rules) { FBRuleReasoner reasoner = new FBRuleReasoner(rules); reasoner.tablePredicate(RDFS.Nodes.subClassOf); reasoner.tablePredicate(RDF.Nodes.type); reasoner.tablePredicate(p); return reasoner; }
/** * Precompute the implications of a schema graph. The statements in the graph * will be combined with the data when the final InfGraph is created. */ @Override public Reasoner bindSchema(Graph tbox) throws ReasonerException { if (schemaGraph != null) { throw new ReasonerException("Can only bind one schema at a time to an OWLRuleReasoner"); } FBRuleInfGraph graph = new FBRuleInfGraph(this, rules, getPreload(), tbox); graph.prepare(); FBRuleReasoner fbr = new FBRuleReasoner(rules, graph, factory); fbr.setDerivationLogging(recordDerivations); fbr.setTraceOn(traceOn); return fbr; }
/** * Return the reasoner to test */ public static Reasoner makeReasoner() { FBRuleReasoner reasoner = new FBRuleReasoner(loadRules()); // Don't have TGC enable yet. return reasoner; }
@Test public void testTabledGoalsLeak() throws Exception { Graph data = Factory.createGraphMem(); data.add(new Triple(a, ty, C1)); List<Rule> rules = Rule .parseRules("[r1: (?x p ?t) <- (?x rdf:type C1), makeInstance(?x, p, C2, ?t)]" + "[r2: (?t rdf:type C2) <- (?x rdf:type C1), makeInstance(?x, p, C2, ?t)]"); FBRuleInfGraph infgraph = (FBRuleInfGraph) createReasoner(rules).bind( data); LPBRuleEngine engine = getEngineForGraph(infgraph); assertEquals(0, engine.activeInterpreters.size()); assertEquals(0, engine.tabledGoals.size()); ExtendedIterator<Triple> it = infgraph.find(a, ty, C1); it.close(); // how many were cached assertEquals(1, engine.tabledGoals.size()); // and no leaks of activeInterpreters assertEquals(0, engine.activeInterpreters.size()); // Now ask again: it = infgraph.find(a, ty, C1); it.close(); // if it was a cache hit, no change here: assertEquals(1, engine.tabledGoals.size()); assertEquals(0, engine.activeInterpreters.size()); //the cached generator should not have any consumingCP left for(Generator generator : engine.tabledGoals.asMap().values()){ assertEquals(0, generator.consumingCPs.size()); } }
return super.doSetParameter( parameter, value );
public void testSchema() { Model schema = model( "P rdf:type owl:ObjectProperty" ); Resource root = resourceInModel( "x rdf:type ja:ReasonerFactory; x ja:schema S" ); Assembler sub = new NamedObjectAssembler( resource( "S" ), schema ); ReasonerFactory rf = (ReasonerFactory) ASSEMBLER.open( sub, root ); Reasoner r = rf.create( null ); assertIsomorphic( schema.getGraph(), ((FBRuleReasoner) r).getBoundSchema() ); }
/** * Constructor * @param factory the parent reasoner factory which is consulted to answer capability questions * @param configuration RDF node to configure the rule set and mode, can be null */ public FBRuleReasoner(ReasonerFactory factory, Resource configuration) { this( new ArrayList<Rule>(), factory); this.configuration = configuration; if (configuration != null) loadConfiguration( configuration ); }