Commits

Anonymous committed 1959c15

ordf_load should just call pkg.rdf_data, no more digging around in directories of n3 files

Comments (0)

Files changed (2)

 :program:`ordf_load`
 =======================
 
-Utility program for loading any N3 fixtures that are packaged with some
+Utility program for loading any RDF fixtures that are packaged with some
 python modules. Normal usage is as in::
 
-    % ordf_load -p ordf.vocab -b http://ordf.org/schema/
+    % ordf_load -p ordf.vocab
     INFO  [ordf.handler] Handler(0/0) initialised ver 0.7.246.1a3933607282
     INFO  [ordf.handler] Handler(1/0) reading from <ordf.handler.pt.PairTree object ...>
     INFO  [ordf.handler] Handler(1/1) writing to <ordf.handler.pt.PairTree object ...>
     INFO  [ordf.load/3149] Loading http://ordf.org/schema/ordf
     INFO  [ordf.changeset] 20 changes urn:uuid:44764ed0-8d12-11df-acde-001f5bef60ee
 
-    % ordf_load -p ordf.onto -b http://ordf.org/lens/
+    % ordf_load -p ordf.onto
     INFO  [ordf.handler] Handler(0/0) initialised ver 0.7.246.1a3933607282
     INFO  [ordf.handler] Handler(1/0) reading from <ordf.handler.pt.PairTree ...>
     INFO  [ordf.handler] Handler(1/1) writing to <ordf.handler.pt.PairTree ...>
     doesn't work with namespace packages (e.g. ordf itself which is why
     the schema fixtures are in the ordf.vocab sub-module).
 
-.. cmdoption:: -b, --base
-
-    The Base URI for loading graphs into. The URI of the graph will be
-    *base* + *filename* where *filename* has had the *.n3* extension
-    stripped.
-
 Command Implementation -- :class:`Command`
 ==========================================
 
 class LoadN3(Command):
     usage = "%prog [options]"
     parser = Command.StandardParser(usage=usage)
-    parser.add_option("-b", "--base",
-                      dest="base_uri",
-                      default="http://ordf.org/schema/",
-                      help="Base URI (default: http://ordf.org/schema/)")
     parser.add_option("-p", "--package",
                       dest="package_name",
                       default="ordf.vocab",
                     self.handler.put(graph)
                 else:
                     ctx.add(graph)
-        else:
-            n3data = os.path.join(os.path.dirname(pkg.__file__), "n3")
-            for fname in pkg_resources.resource_listdir(self.options.package_name, "n3"):
-                if not fname.endswith(".n3"):
-                    continue
-                fbase, ext = fname.rsplit(".", 1)
-                graph_uri = self.options.base_uri + fbase
-                self.log.info("Loading %s" % graph_uri)
-
-                graph = Graph(identifier=graph_uri)
-                fp = pkg_resources.resource_stream(self.options.package_name,
-                                                   os.path.join("n3", fname))
-                graph.parse(fp, format="n3")
-                fp.close()
-
-                proc = Process()
-                proc.result(graph)
-                if self.options.nocs:
-                    self.handler.put(graph)
-                else:
-                    ctx.add(graph)
 
         if not self.options.nocs:
             ctx.commit()

ordf/vocab/__init__.py

+import os
+import pkg_resources
+from getpass import getuser
+from logging import getLogger
+from ordf.graph import Graph
+
+log = getLogger(__name__)
+
+def rdf_data():
+    graph_uri = "http://ordf.org/schema/ordf"
+    log.info("Loading %s" % graph_uri)
+
+    graph = Graph(identifier=graph_uri)
+    fp = pkg_resources.resource_stream("ordf.vocab", os.path.join("n3", "ordf.n3"))
+    graph.parse(fp, format="n3")
+    fp.close()
+
+    from ordf.vocab.opmv import Agent, Process
+    agent = Agent()
+    agent.nick(getuser())
+    proc = Process()
+    proc.result(graph)
+
+    yield graph