Browse Source

Complete LL generation; output LL and RDF to file.

scossu 1 week ago
parent
commit
c45c0c072c
3 changed files with 48 additions and 5 deletions
  1. 7 0
      README.md
  2. 24 2
      pkar.lua
  3. 17 3
      src/generator.lua

+ 7 - 0
README.md

@@ -212,6 +212,8 @@ functional and available for use by the intended audience.
 
 #### Prototype
 
+❏ = pending; ⚒ = in progress; ⎊ = blocked; ✓ = complete; ✖︎ = not implemented.
+
 - ✓ Configuration + config parser
   - ✓ Application
   - ✓ Content model
@@ -266,6 +268,11 @@ functional and available for use by the intended audience.
 - Front end
   - Enhanced styling and access
 - Testing
+- Documentation
+  - Break main sections off README
+  - Submission guide
+  - Site generation guide
+  - Content modeling guide (including proxy concepts)
 
 #### Post-MVP
 

+ 24 - 2
pkar.lua

@@ -73,10 +73,21 @@ gen_rdf = cli.command {
         type = cli.string,
         default = "ttl",
     },
+    cli.flag "o,output" {
+        "Output file. If not specified, output to stdout.",
+        type = cli.string,
+        default = "",
+    },
 
     function(args)
         local s = term.new_iriref_ns(args.id)
-        print(repo.serialize_rsrc(s, args.format))
+        local out = repo.serialize_rsrc(s, args.format)
+        if args.output ~= "" then
+            local fh = assert(io.open(args.output, "w"))
+            fh:write(out)
+            fh:close()
+            print("File written to ", args.output)
+        else print(out) end
     end,
 }
 
@@ -87,10 +98,21 @@ gen_ll = cli.command {
         "ID of the resource, prefixed by `par:`",
         type = cli.string,
     },
+    cli.flag "o,output" {
+        "Output file. If not specified, output to stdout.",
+        type = cli.string,
+        default = "",
+    },
 
     function(args)
         local s = term.new_iriref_ns(args.id)
-        print(gen.generate_ll(s))
+        local out = gen.generate_ll(s)
+        if args.output ~= "" then
+            local fh = assert(io.open(args.output, "w"))
+            fh:write(out)
+            fh:close()
+            print("File written to ", args.output)
+        else print(out) end
     end
 }
 

+ 17 - 3
src/generator.lua

@@ -528,11 +528,24 @@ end
 
 M.generate_ll = function(s)
     local res_gr = repo.get_rsrc(s)
-    tdata = {}
+    local mconf = get_mconf(s)
+
+    local tdata = {
+        {
+            id = path.basename(s.data),
+            content_type = mconf.id,
+        },
+    }
     for p, ots in pairs(res_gr:connections(s, term.LINK_OUTBOUND)) do
-        pname = nsm.denormalize_uri(p.data)
+        local pname = model.uri_to_id[nsm.denormalize_uri(p.data)]
+        --if p == pkar.RDF_TYPE then goto skip_p end
+        if not pname then goto skip_p end
+        if pname == "content_type" then goto skip_p end
         for _, o in pairs (ots) do
             -- Find a row where the pname slot has not been occupied.
+            if (mconf.properties[pname] or {}).type == "resource" then
+                o = {data = o.data:gsub(nsm.get_ns("par"), "")}
+            end
             for i = 1, math.huge do
                 if (tdata[i] or NT)[pname] then goto continue
                 else
@@ -543,11 +556,12 @@ M.generate_ll = function(s)
                 ::continue::
             end
         end
+        ::skip_p::
     end
     -- FIXME ftcsv encodes nil values as `"nil"`. See
     -- https://github.com/FourierTransformer/ftcsv/issues/46
 
-    return csv.encode(tdata)
+    return csv.encode(tdata, {encodeNilAs = ""})
 end