Преглед изворни кода

Convert local paths to URIs.

scossu пре 2 недеља
родитељ
комит
d1ba25b01d
4 измењених фајлова са 41 додато и 9 уклоњено
  1. 9 5
      config/model/typedef/artifact.lua
  2. 18 0
      config/model/typedef/collection.lua
  3. 1 0
      src/model.lua
  4. 13 4
      src/submission.lua

+ 9 - 5
config/model/typedef/artifact.lua

@@ -5,21 +5,25 @@ return {
     broader = "anything",
 
     properties = {
+        has_member = {
+            uri = "pas:hasMember",
+            label = "Has member",
+            type = "resource",
+        },
         first = {
             uri = "pas:first",
             label = "First child",
             type = "resource",
-            range = {part = true},
+            range = {brick = true},
         },
-        has_representation = {
-            uri = "pas:hasRepresentation",
-            label = "Representation",
+        pref_rep = {
+            uri = "pas:hasPreferredRepresentation",
+            label = "Preferred representation",
             description =
                 [[Preferred representation. Used to generate
                 a thumbnail (for a visual item) or sample (for non-visual
                 materials such as audio).]],
             type = "resource",
-            range = {file = true},
         },
         has_file = {
             uri = "pas:hasFile",

+ 18 - 0
config/model/typedef/collection.lua

@@ -3,6 +3,24 @@ return {
     label = "Collection",
 
     broader = "brick",
+
+    properties = {
+        has_member = {
+            uri = "pas:hasMember",
+            label = "Member",
+            type = "resource",
+        },
+        pref_rep = {
+            uri = "pas:hasPreferredRepresentation",
+            label = "Preferred representation",
+            description =
+                [[Preferred representation. Used to generate
+                a thumbnail (for a visual item) or sample (for non-visual
+                materials such as audio).]],
+            type = "resource",
+            range = {file = true},
+        },
+    }
 }
 
 

+ 1 - 0
src/model.lua

@@ -24,6 +24,7 @@ local M = {
 }
 
 M.from_uri = function(type_uri)
+    dbg.assert(type_uri)
     return M.types[M.uri_to_id[nsm.denormalize_uri(type_uri.data)]]
 end
 

+ 13 - 4
src/submission.lua

@@ -23,6 +23,9 @@ local dbg = require "debugger"
 -- "nil" table - for missing key fallback in chaining.
 local NT = {}
 
+-- Local path to URI mapping. For linking between newly created resources.
+local path_to_uri
+
 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 = 97, 122 do table.insert(chpool, i) end  -- a-z
 
+
 --[[
 Generate a random, reader-friendly ID.
 
@@ -55,6 +59,7 @@ end
 
 M.generate_sip = function(path)
     local sip = {root_path = path:match("(.*/)")}
+    path_to_uri = {}
 
     local tn_dir = plpath.join(sip.root_path, "proc", "tn")
     dir.makepath(tn_dir)
@@ -73,6 +78,8 @@ M.generate_sip = function(path)
             prev_path = row.source_path
             -- New row.
             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
                 if v == "" then goto cont1 end  -- skip empty strings.
                 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
         end
         -- 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
         for i, vv in ipairs(v) do
             if k == "content_type" then
                 vv = rmod.uri
             end
             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)
             elseif datatype == "ext_resource" then
                 o = term.new_iriref(vv)
@@ -215,7 +225,7 @@ M.deposit = function(sip)
 
             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 fsize = 0
             logger:debug("Hashing ", in_path)
@@ -228,8 +238,7 @@ M.deposit = function(sip)
                 fsize = fsize + #chunk
             end
             local checksum = hash_it:final(true)
-            rsrc.checksum = {
-                    ["urn:blake2:" .. checksum] = true}
+            rsrc.checksum = {"urn:blake2:" .. checksum}
             rsrc.size = fsize
 
             ofh:close()