You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Claude Warren <cl...@xenei.com> on 2012/08/15 16:39:42 UTC
Reasoner and data graphs
I have gotten my first chance to look at building a rule base reasoner and
was wondering why updates to the data graph are not processed by the
reasoner. My code:
@Test
public void testSubClassOf()
{
Model model = ModelFactory.createDefaultModel();
// create a resource (empty resource)
Resource config = model.createResource();
// set engine mode
config.addProperty(ReasonerVocabulary.PROPruleMode, "hybrid");
config.addProperty(ReasonerVocabulary.PROPruleSet, "etc/rdfs-fb.rules");
Reasoner reasoner = GenericRuleReasonerFactory
.theInstance().create(config);
Graph graph = GraphFactory.createGraphMem();
InfGraph infGraph = reasoner.bind( graph );
Node n1 = Node.createURI( "http://example.com/p1");
Node n2 = Node.createURI( "http://example.com/p2");
Node n3 = Node.createURI( "http://example.com/p3");
graph.add( new Triple( n1, RDFS.subClassOf.asNode(), n2 ));
Assert.assertTrue( infGraph.contains( n1, RDFS.subClassOf.asNode(), n2 ));
System.out.println( "Adding triple ");
graph.add( new Triple( n2, RDFS.subClassOf.asNode(), n3));
Assert.assertTrue( infGraph.contains( n1, RDFS.subClassOf.asNode(), n2 ));
Assert.assertTrue( infGraph.contains( n2, RDFS.subClassOf.asNode(), n3 ));
Assert.assertTrue( infGraph.contains( n1, RDFS.subClassOf.asNode(), n3 ));
}
fails on the last Assert. However if I change "graph.add( new Triple( n2,
RDFS.subClassOf.asNode(), n3));"
to "infGraph.add( new Triple( n2, RDFS.subClassOf.asNode(), n3));" it works
as expected.
Shouldn't the infGraph listen to the changes in the underlying graph and
update the reasoned triples accordingly or am I missing something ?
Thx,
Claude
--
I like: Like Like - The likeliest place on the web<http://like-like.xenei.com>
Identity: https://www.identify.nu/user.php?claude@xenei.com
LinkedIn: http://www.linkedin.com/in/claudewarren
Re: Reasoner and data graphs
Posted by Dave Reynolds <da...@gmail.com>.
Hi,
On 15/08/12 15:39, Claude Warren wrote:
> I have gotten my first chance to look at building a rule base reasoner and
> was wondering why updates to the data graph are not processed by the
> reasoner. My code:
>
> @Test
> public void testSubClassOf()
> {
> Model model = ModelFactory.createDefaultModel();
>
> // create a resource (empty resource)
> Resource config = model.createResource();
>
> // set engine mode
> config.addProperty(ReasonerVocabulary.PROPruleMode, "hybrid");
>
> config.addProperty(ReasonerVocabulary.PROPruleSet, "etc/rdfs-fb.rules");
> Reasoner reasoner = GenericRuleReasonerFactory
> .theInstance().create(config);
>
> Graph graph = GraphFactory.createGraphMem();
> InfGraph infGraph = reasoner.bind( graph );
> Node n1 = Node.createURI( "http://example.com/p1");
> Node n2 = Node.createURI( "http://example.com/p2");
> Node n3 = Node.createURI( "http://example.com/p3");
> graph.add( new Triple( n1, RDFS.subClassOf.asNode(), n2 ));
> Assert.assertTrue( infGraph.contains( n1, RDFS.subClassOf.asNode(), n2 ));
> System.out.println( "Adding triple ");
> graph.add( new Triple( n2, RDFS.subClassOf.asNode(), n3));
> Assert.assertTrue( infGraph.contains( n1, RDFS.subClassOf.asNode(), n2 ));
> Assert.assertTrue( infGraph.contains( n2, RDFS.subClassOf.asNode(), n3 ));
> Assert.assertTrue( infGraph.contains( n1, RDFS.subClassOf.asNode(), n3 ));
>
> }
>
> fails on the last Assert. However if I change "graph.add( new Triple( n2,
> RDFS.subClassOf.asNode(), n3));"
> to "infGraph.add( new Triple( n2, RDFS.subClassOf.asNode(), n3));" it works
> as expected.
Correct, that's the intended usage.
The InfGraph is a layer over the top of some other graph (or stack of
other graphs). If you add data into the top of the layer the reasoner
sees it immediately and can process it. If you "sneak behind its back"
and add data at a lower layer then call infgraph.rebind() to let the
reasoner know.
> Shouldn't the infGraph listen to the changes in the underlying graph and
> update the reasoned triples accordingly or am I missing something ?
That's not the current design. Partly that's historic and partly a
reluctance to rely on always having complete graph listeners in order to
use inference.
Dave