|
@@ -14,6 +14,7 @@ local graph = require "volksdata.graph"
|
|
local pkar = require "pocket_archive"
|
|
local pkar = require "pocket_archive"
|
|
local logger = pkar.logger
|
|
local logger = pkar.logger
|
|
local model = require "pocket_archive.model"
|
|
local model = require "pocket_archive.model"
|
|
|
|
+local repo = require "pocket_archive.repo"
|
|
local transformers = require "pocket_archive.transformers"
|
|
local transformers = require "pocket_archive.transformers"
|
|
|
|
|
|
local dbg = require "debugger"
|
|
local dbg = require "debugger"
|
|
@@ -22,9 +23,6 @@ local dbg = require "debugger"
|
|
-- "nil" table - for missing key fallback in chaining.
|
|
-- "nil" table - for missing key fallback in chaining.
|
|
local NT = {}
|
|
local NT = {}
|
|
|
|
|
|
--- Default store graph to search all triples.
|
|
|
|
-local gr = graph.new(pkar.store, term.DEFAULT_CTX)
|
|
|
|
-
|
|
|
|
-- All resource subjects.
|
|
-- All resource subjects.
|
|
local subjects
|
|
local subjects
|
|
|
|
|
|
@@ -75,7 +73,7 @@ end
|
|
|
|
|
|
|
|
|
|
local function get_tn_url(s)
|
|
local function get_tn_url(s)
|
|
- if gr:attr(s, pkar.RDF_TYPE)[pkar.FILE_T.hash] then
|
|
|
|
|
|
+ if repo.gr:attr(s, pkar.RDF_TYPE)[pkar.FILE_T.hash] then
|
|
-- The subject is a file.
|
|
-- The subject is a file.
|
|
tn_fname = (s.data:gsub(pkar.PAR_NS, "") .. ".jpg") -- FIXME do not hardcode.
|
|
tn_fname = (s.data:gsub(pkar.PAR_NS, "") .. ".jpg") -- FIXME do not hardcode.
|
|
return plpath.join(
|
|
return plpath.join(
|
|
@@ -85,7 +83,7 @@ local function get_tn_url(s)
|
|
-- Recurse through all first children until one with a thumbnail, or a
|
|
-- Recurse through all first children until one with a thumbnail, or a
|
|
-- leaf without children, is found.
|
|
-- leaf without children, is found.
|
|
local first_child
|
|
local first_child
|
|
- _, first_child = next(gr:attr(s, pkar.FIRST_P))
|
|
|
|
|
|
+ _, first_child = next(repo.gr:attr(s, pkar.FIRST_P))
|
|
if first_child then return get_tn_url(first_child) end
|
|
if first_child then return get_tn_url(first_child) end
|
|
end
|
|
end
|
|
|
|
|
|
@@ -96,7 +94,7 @@ local function generate_dres(s, mconf)
|
|
local children = {}
|
|
local children = {}
|
|
local title
|
|
local title
|
|
-- Metadata
|
|
-- Metadata
|
|
- local attrs = gr:connections(s, term.LINK_OUTBOUND)
|
|
|
|
|
|
+ local attrs = repo.gr:connections(s, term.LINK_OUTBOUND)
|
|
for p, ots in pairs(attrs) do
|
|
for p, ots in pairs(attrs) do
|
|
local pname = nsm.denormalize_uri(p.data)
|
|
local pname = nsm.denormalize_uri(p.data)
|
|
p_label = ((mconf.properties or NT)[pname] or NT).label
|
|
p_label = ((mconf.properties or NT)[pname] or NT).label
|
|
@@ -116,10 +114,10 @@ local function generate_dres(s, mconf)
|
|
|
|
|
|
-- Fallback labels.
|
|
-- Fallback labels.
|
|
local label
|
|
local label
|
|
- _, label = next(gr:attr(child_s, pkar.DC_TITLE_P))
|
|
|
|
|
|
+ _, label = next(repo.gr:attr(child_s, pkar.DC_TITLE_P))
|
|
if label then label = label.data
|
|
if label then label = label.data
|
|
else
|
|
else
|
|
- _, label = next(gr:attr(child_s, pkar.PATH_P))
|
|
|
|
|
|
+ _, label = next(repo.gr:attr(child_s, pkar.PATH_P))
|
|
if label then label = plpath.basename(label.data)
|
|
if label then label = plpath.basename(label.data)
|
|
else label = child_s.data end
|
|
else label = child_s.data end
|
|
end
|
|
end
|
|
@@ -135,7 +133,7 @@ local function generate_dres(s, mconf)
|
|
})
|
|
})
|
|
logger:debug("Child label for ", child_s.data, ": ", ll[#ll].label or "nil")
|
|
logger:debug("Child label for ", child_s.data, ": ", ll[#ll].label or "nil")
|
|
-- There can only be one "next"
|
|
-- There can only be one "next"
|
|
- _, child_s = next(gr:attr(child_s, pkar.NEXT_P))
|
|
|
|
|
|
+ _, child_s = next(repo.gr:attr(child_s, pkar.NEXT_P))
|
|
end
|
|
end
|
|
table.insert(children, ll)
|
|
table.insert(children, ll)
|
|
end
|
|
end
|
|
@@ -195,7 +193,7 @@ local function generate_ores(s, mconf)
|
|
local techmd = {}
|
|
local techmd = {}
|
|
local rel = {}
|
|
local rel = {}
|
|
-- Metadata
|
|
-- Metadata
|
|
- local attrs = gr:connections(s, term.LINK_OUTBOUND)
|
|
|
|
|
|
+ local attrs = repo.gr:connections(s, term.LINK_OUTBOUND)
|
|
for p, ots in pairs(attrs) do
|
|
for p, ots in pairs(attrs) do
|
|
local pname = nsm.denormalize_uri(p.data)
|
|
local pname = nsm.denormalize_uri(p.data)
|
|
p_label = ((mconf.properties or NT)[pname] or NT).label
|
|
p_label = ((mconf.properties or NT)[pname] or NT).label
|
|
@@ -286,14 +284,6 @@ local function generate_ores(s, mconf)
|
|
end
|
|
end
|
|
|
|
|
|
|
|
|
|
-M.get_graph = function(s)
|
|
|
|
- out_gr = graph.new(nil, s.data)
|
|
|
|
- gr:copy(out_gr, s)
|
|
|
|
-
|
|
|
|
- return out_gr
|
|
|
|
-end
|
|
|
|
-
|
|
|
|
-
|
|
|
|
M.generate_res_idx = function(s, mconf)
|
|
M.generate_res_idx = function(s, mconf)
|
|
local rrep = {
|
|
local rrep = {
|
|
id = nsm.denormalize_uri(s.data),
|
|
id = nsm.denormalize_uri(s.data),
|
|
@@ -301,7 +291,7 @@ M.generate_res_idx = function(s, mconf)
|
|
href = pkar.gen_pairtree("/res", s.data, ".html", true),
|
|
href = pkar.gen_pairtree("/res", s.data, ".html", true),
|
|
}
|
|
}
|
|
|
|
|
|
- local attrs = gr:connections(s, term.LINK_OUTBOUND)
|
|
|
|
|
|
+ local attrs = repo.gr:connections(s, term.LINK_OUTBOUND)
|
|
|
|
|
|
local function format_value(pname, o)
|
|
local function format_value(pname, o)
|
|
logger:debug("Adding value to " .. pname .. ": " .. ((o or NT).data or "nil"))
|
|
logger:debug("Adding value to " .. pname .. ": " .. ((o or NT).data or "nil"))
|
|
@@ -339,16 +329,8 @@ M.generate_res_idx = function(s, mconf)
|
|
end
|
|
end
|
|
|
|
|
|
|
|
|
|
-M.generate_rdf = function(s, format)
|
|
|
|
- local res_gr = M.get_graph(s)
|
|
|
|
- logger:debug("Serializing graph: ", s.data)
|
|
|
|
-
|
|
|
|
- return res_gr:encode(format or "ttl")
|
|
|
|
-end
|
|
|
|
-
|
|
|
|
-
|
|
|
|
M.generate_ll = function(s)
|
|
M.generate_ll = function(s)
|
|
- local res_gr = M.get_graph(s)
|
|
|
|
|
|
+ local res_gr = repo.get_rsrc(s)
|
|
tdata = {}
|
|
tdata = {}
|
|
for p, ots in pairs(res_gr:connections(s, term.LINK_OUTBOUND)) do
|
|
for p, ots in pairs(res_gr:connections(s, term.LINK_OUTBOUND)) do
|
|
pname = nsm.denormalize_uri(p.data)
|
|
pname = nsm.denormalize_uri(p.data)
|
|
@@ -374,13 +356,13 @@ end
|
|
|
|
|
|
M.generate_resource = function(s)
|
|
M.generate_resource = function(s)
|
|
local res_type
|
|
local res_type
|
|
- _, res_type = next(gr:attr(s, pkar.CONTENT_TYPE_P))
|
|
|
|
|
|
+ _, res_type = next(repo.gr:attr(s, pkar.CONTENT_TYPE_P))
|
|
local mconf = model.models[res_type.data]
|
|
local mconf = model.models[res_type.data]
|
|
|
|
|
|
-- Generate RDF/Turtle doc.
|
|
-- Generate RDF/Turtle doc.
|
|
local res_path = pkar.gen_pairtree(M.res_dir, s.data, ".ttl")
|
|
local res_path = pkar.gen_pairtree(M.res_dir, s.data, ".ttl")
|
|
local ofh = assert(io.open(res_path, "w"))
|
|
local ofh = assert(io.open(res_path, "w"))
|
|
- ofh:write(M.generate_rdf(s, "ttl"))
|
|
|
|
|
|
+ ofh:write(repo.serialze_rsrc(s, "ttl"))
|
|
ofh:close()
|
|
ofh:close()
|
|
|
|
|
|
-- Generate HTML doc.
|
|
-- Generate HTML doc.
|
|
@@ -401,7 +383,7 @@ end
|
|
|
|
|
|
M.generate_resources = function()
|
|
M.generate_resources = function()
|
|
-- Look up if subjects are already populated.
|
|
-- Look up if subjects are already populated.
|
|
- subjects = subjects or gr:unique_terms(triple.POS_S)
|
|
|
|
|
|
+ subjects = subjects or repo.gr:unique_terms(triple.POS_S)
|
|
|
|
|
|
-- Initialize the JSON template with an opening brace.
|
|
-- Initialize the JSON template with an opening brace.
|
|
local ofh = assert(io.open(index_path, "w"))
|
|
local ofh = assert(io.open(index_path, "w"))
|
|
@@ -431,14 +413,14 @@ end
|
|
M.generate_idx = function()
|
|
M.generate_idx = function()
|
|
local obj_idx = {}
|
|
local obj_idx = {}
|
|
-- Get all subject of type: Artifact.
|
|
-- Get all subject of type: Artifact.
|
|
- s_ts = gr:term_set(
|
|
|
|
|
|
+ s_ts = repo.gr:term_set(
|
|
pkar.RDF_TYPE, triple.POS_P,
|
|
pkar.RDF_TYPE, triple.POS_P,
|
|
term.new_iriref_ns("pas:Artifact"), triple.POS_O
|
|
term.new_iriref_ns("pas:Artifact"), triple.POS_O
|
|
)
|
|
)
|
|
for _, s in pairs(s_ts) do
|
|
for _, s in pairs(s_ts) do
|
|
local title, created
|
|
local title, created
|
|
- _, title = next(gr:attr(s, pkar.DC_TITLE_P))
|
|
|
|
- _, created = next(gr:attr(s, pkar.DC_CREATED_P))
|
|
|
|
|
|
+ _, title = next(repo.gr:attr(s, pkar.DC_TITLE_P))
|
|
|
|
+ _, created = next(repo.gr:attr(s, pkar.DC_CREATED_P))
|
|
|
|
|
|
local obj = {
|
|
local obj = {
|
|
href = pkar.gen_pairtree("/res", s.data, ".html", true),
|
|
href = pkar.gen_pairtree("/res", s.data, ".html", true),
|