I called it quits (for now) in trying to retrofit the RETE-based algorithm to handle N3 functions & filters. I've checked in a rewritten Rete module with tests for SHIOF Description Logic axioms.
Tracking dependencies between filter / function variables, became hairy.
An SVG diagram of these rules compiled into a RETE-like network was generated using an included Boost Graph Library utility function.
It's unit test output:
testRules (__main__.TestEvaluateNetwork) ... Time to build production rule (RDFLib): 0.0118989944458 seconds Time to calculate closure on working memory: 0.478726148605 seconds ok ---------------------------------------------------------------------- Ran 1 test in 0.751s OK
I also integrated Python iterator algebra implementation of a relational hash join (for the Beta Nodes).
It workes with RDFLib, so I'd eventually like to integrate the ability to dispatch SPARQL queries over an N3 Closure Graph - generated from the network. The speed in which it is able to render rules graphs rendered the option of serializing a compiled network into persistence a non-issue.
From the README.txt:
Fu Xi (pronounced foo-see) is a forward-chaining inferencing expert system for RDFLib Notation 3 graphs. It is named after the first mythical soveriegn of ancient china who supposedly, 'looked upward and contemplated the images in the heavens, and looked downward and contemplated the occurrences on earth.'.
Originally, it was an idea to express the formalisms of the Yi Jing / I Ching in Description & First Order Logic.
It relies on Charles Forgy's Rete algorithm for the many pattern/many object match problem - which builds a triple pattern reasoning network. It can be used as a reasoner with capabilities for certain expressive Description Logics (via OWL/RDFS axioms in N3) or a general N3 production / expert system. It uses Python hash / set / list idioms to maximize matching efficiency of the network. In particular, it uses an Iterator algebra implementation for the join activation mechanism
An example of its use:
from FuXi.Rete.Util import generateTokenSet from FuXi.Rete import * from rdflib.Graph import Graph,ReadOnlyGraphAggregate from rdflib import plugin from FuXi.Rete.RuleStore import N3RuleStore store = plugin.get('IOMemory',Store)() store.open('') ruleGraph = Graph(N3RuleStore()) ruleGraph.parse(open('some-rule-file.n3'),format='n3') factGraph = Graph(store) factGraph.parse(open('fact-file'),format='..') closureDeltaGraph = Graph(store) network = ReteNetwork(ruleStore, initialWorkingMemory=generateTokenSet(factGraph), inferredTarget = closureDeltaGraph) for s,p,o in network.closureGraph(factGraph): .. do something with triple ..
To check out from cvs:
cvs -d:pserver:email@example.com:/var/local/cvsroot login cvs -d:pserver:firstname.lastname@example.org:/var/local/cvsroot get Fuxi