|
@@ -23,6 +23,9 @@ local dbg = require "debugger"
|
|
-- "nil" table - for missing key fallback in chaining.
|
|
-- "nil" table - for missing key fallback in chaining.
|
|
local NT = {}
|
|
local NT = {}
|
|
|
|
|
|
|
|
+-- Local path to URI mapping. For linking between newly created resources.
|
|
|
|
+local path_to_uri
|
|
|
|
+
|
|
local M = {} -- Submission module
|
|
local M = {} -- Submission module
|
|
|
|
|
|
|
|
|
|
@@ -37,6 +40,7 @@ for i = 48, 57 do table.insert(chpool, i) end -- 0-9
|
|
for i = 65, 90 do table.insert(chpool, i) end -- A-Z
|
|
for i = 65, 90 do table.insert(chpool, i) end -- A-Z
|
|
for i = 97, 122 do table.insert(chpool, i) end -- a-z
|
|
for i = 97, 122 do table.insert(chpool, i) end -- a-z
|
|
|
|
|
|
|
|
+
|
|
--[[
|
|
--[[
|
|
Generate a random, reader-friendly ID.
|
|
Generate a random, reader-friendly ID.
|
|
|
|
|
|
@@ -55,6 +59,7 @@ end
|
|
|
|
|
|
M.generate_sip = function(path)
|
|
M.generate_sip = function(path)
|
|
local sip = {root_path = path:match("(.*/)")}
|
|
local sip = {root_path = path:match("(.*/)")}
|
|
|
|
+ path_to_uri = {}
|
|
|
|
|
|
local tn_dir = plpath.join(sip.root_path, "proc", "tn")
|
|
local tn_dir = plpath.join(sip.root_path, "proc", "tn")
|
|
dir.makepath(tn_dir)
|
|
dir.makepath(tn_dir)
|
|
@@ -73,6 +78,8 @@ M.generate_sip = function(path)
|
|
prev_path = row.source_path
|
|
prev_path = row.source_path
|
|
-- New row.
|
|
-- New row.
|
|
sip[i] = {id = "par:" .. M.idgen()}
|
|
sip[i] = {id = "par:" .. M.idgen()}
|
|
|
|
+ -- Add to path to URI map for later referencing.
|
|
|
|
+ path_to_uri[row.source_path] = sip[i].id
|
|
for k, v in pairs(row) do
|
|
for k, v in pairs(row) do
|
|
if v == "" then goto cont1 end -- skip empty strings.
|
|
if v == "" then goto cont1 end -- skip empty strings.
|
|
if pkar.config.md.single_values[k] then sip[i][k] = v
|
|
if pkar.config.md.single_values[k] then sip[i][k] = v
|
|
@@ -169,13 +176,16 @@ M.rsrc_to_graph = function(rsrc)
|
|
rdf_type = term.new_iriref_ns(rdf_type_str).data
|
|
rdf_type = term.new_iriref_ns(rdf_type_str).data
|
|
end
|
|
end
|
|
-- Force all fields to be multi-valued.
|
|
-- Force all fields to be multi-valued.
|
|
- if type(v) ~= "table" then v = {[v] = true} end
|
|
|
|
|
|
+ if type(v) ~= "table" then v = {v} end
|
|
local o
|
|
local o
|
|
for i, vv in ipairs(v) do
|
|
for i, vv in ipairs(v) do
|
|
if k == "content_type" then
|
|
if k == "content_type" then
|
|
vv = rmod.uri
|
|
vv = rmod.uri
|
|
end
|
|
end
|
|
if datatype == "resource" then
|
|
if datatype == "resource" then
|
|
|
|
+ if not vv:match("^[a-z]*:") then
|
|
|
|
+ -- Convert local path to URIs.
|
|
|
|
+ vv = assert(path_to_uri[vv]) end
|
|
o = term.new_iriref_ns(vv)
|
|
o = term.new_iriref_ns(vv)
|
|
elseif datatype == "ext_resource" then
|
|
elseif datatype == "ext_resource" then
|
|
o = term.new_iriref(vv)
|
|
o = term.new_iriref(vv)
|
|
@@ -215,7 +225,7 @@ M.deposit = function(sip)
|
|
|
|
|
|
local ifh = assert(io.open(in_path, "r"))
|
|
local ifh = assert(io.open(in_path, "r"))
|
|
|
|
|
|
- rsrc.format = {[magic:filehandle(ifh)] = true}
|
|
|
|
|
|
+ rsrc.format = {magic:filehandle(ifh)}
|
|
local hash_it = mc.new_blake2b()
|
|
local hash_it = mc.new_blake2b()
|
|
local fsize = 0
|
|
local fsize = 0
|
|
logger:debug("Hashing ", in_path)
|
|
logger:debug("Hashing ", in_path)
|
|
@@ -228,8 +238,7 @@ M.deposit = function(sip)
|
|
fsize = fsize + #chunk
|
|
fsize = fsize + #chunk
|
|
end
|
|
end
|
|
local checksum = hash_it:final(true)
|
|
local checksum = hash_it:final(true)
|
|
- rsrc.checksum = {
|
|
|
|
- ["urn:blake2:" .. checksum] = true}
|
|
|
|
|
|
+ rsrc.checksum = {"urn:blake2:" .. checksum}
|
|
rsrc.size = fsize
|
|
rsrc.size = fsize
|
|
|
|
|
|
ofh:close()
|
|
ofh:close()
|