Anonymous committed 9636c0c

tweak fuxi to handle the case where a single graph is
passed in instead of a store or conjunctive graph.

add unit tests for fuxi

Comments (0)

Files changed (2)

-from ordf.graph import Graph, ConjunctiveGraph
+from ordf.graph import Graph, _Graph, ConjunctiveGraph
 from ordf.handler import Handler, HandlerPlugin
 from ordf.namespace import CS, RDF
 from ordf.term import URIRef
 from FuXi.Syntax.InfixOWL import Class, Property
 from StringIO import StringIO
 from getpass import getuser
+from string import strip
 from logging import getLogger
 log = getLogger(__name__)
     :ref:`configuring-inferencing` section of the configuration guide
     for how to do this.
-    :param rule_files: comma separated list of files containing inferencing
-        rules in N3 notation
+    :param rule_modules: comma separated list of modules that export
+        an :meth:`inference_rules` method
-    def __init__(self, rule_files, **kw):
+    def __init__(self, rule_modules, **kw):
         super(HandlerPlugin, self).__init__(**kw)
-        self.rule_files = rule_files.split(",")
+        self.rule_modules = map(strip, rule_modules.split(","))
         self.busy = False
     def put(self, store):
         self.busy = True
+        if isinstance(store, _Graph):
+            store =
         def _get(graph):
             if isinstance(graph, basestring):
                 identifier = graph
         self.get = _get
         rstore, rgraph, rete = SetupRuleStore(makeNetwork=True)
-        for rule_file in self.rule_files:
-            for rule in HornFromN3(rule_file):
-                rete.buildNetworkFromClause(rule)
+        for modname in self.rule_modules:
+            __import__(modname, {}, {}, ["inference_rules"]).inference_rules(self.handler, rete)
         ### widen the set of statements to inference from
         ### any references, at one degree from the contents of


+from ordf.graph import Graph
+from ordf.handler import init_handler
+from ordf.namespace import Namespace, RDF, RDFS
+def fuxi_handler():
+    config = {
+        "ordf.readers": "fuxi,rdflib",
+        "ordf.writers": "fuxi,rdflib",
+        "fuxi.args": "ordf.vocab.rdfs",
+        }
+    return init_handler(config)
+EX = Namespace("")
+def test_01_rdfs():
+    h = fuxi_handler()
+    g = Graph(identifier=EX["Max"])
+    g.add((EX["Max"], RDF["type"], EX["Cat"]))
+    h.put(g)
+    r = h.get(EX["Max"])
+    assert r.exists((EX["Max"], RDF["type"], RDFS["Resource"]))