ソースを参照

RDF generator.

scossu 3 週間 前
コミット
dc3ffd9e8d
2 ファイル変更25 行追加5 行削除
  1. 24 1
      pkar.lua
  2. 1 4
      src/html_generator.lua

+ 24 - 1
pkar.lua

@@ -3,6 +3,8 @@
 local cli = require "cli"
 local plpath = require "pl.path"
 
+local term = require "volksdata.term"
+
 local pkar = require "pocket_archive"
 local sub = require "pocket_archive.submission"
 local hgen = require "pocket_archive.html_generator"
@@ -42,13 +44,34 @@ submit = cli.command {
     end
 }
 
-generate = cli.command {
+gen_site = cli.command {
     "Generate a static site from the archive.",
 
     function(args) hgen.generate_site() end
 }
 
 
+gen_rdf = cli.command {
+    "Generate an RDF representation of a resource.",
+
+    cli.positional "id" {
+        "ID of the resource, prefixed by `par:`",
+        type = cli.string,
+    },
+    cli.flag "f,format" {
+        "RDF format. `nt` and `ttl` are available.",
+        type = cli.string,
+        default = "ttl",
+    },
+
+    function(args)
+        local s = term.new_iriref_ns(args.id)
+        local res_gr = hgen.get_graph(s)
+        print(res_gr:encode(args.format))
+    end,
+}
+
+
 cli.program {
     "Pocket Archive command line interface.",
 }

+ 1 - 4
src/html_generator.lua

@@ -22,7 +22,7 @@ local dbg = require "debugger"
 local NT = {}
 
 -- Default store graph to search all triples.
-local gr
+local gr = graph.new(pkar.store, term.DEFAULT_CTX)
 
 -- All resource subjects.
 local subjects
@@ -458,9 +458,6 @@ M.generate_site = function()
     if plpath.isdir(M.media_dir) then dir.rmtree(M.media_dir) end
     dir.makepath(plpath.join(M.media_dir, "tn"))
 
-    -- Set module-level graph handle.
-    gr = graph.new(pkar.store, term.DEFAULT_CTX)
-
     -- Copy static assets.
     dir.clonetree("templates/assets", M.asset_dir, dir.copyfile)