Jelajahi Sumber

Generate rels and sequences with implicit bricks

scossu 2 minggu lalu
induk
melakukan
5471504b13
6 mengubah file dengan 69 tambahan dan 42 penghapusan
  1. 9 6
      README.md
  2. 4 3
      src/core.lua
  3. 47 28
      src/generator.lua
  4. 5 1
      src/submission.lua
  5. 2 2
      templates/dres.html
  6. 2 2
      templates/ores.html

+ 9 - 6
README.md

@@ -216,11 +216,11 @@ functional and available for use by the intended audience.
   - ✓ Application
   - ✓ Content model
     - ✓ Validation rules
--  Submission module
+-  Submission module
   - ✓ SIP building
   - ✓ Metadata from LL
-  -  Brick structures
-  -  Structure inference
+  -  Brick structures
+  -  Structure inference
 - ✓ HTML generator
   - ✓ Index
   - ✓ Resource
@@ -236,11 +236,11 @@ functional and available for use by the intended audience.
   - ✓ Generate LL (single resource)
   - ✓ Generate RDF (single resource)
 - ⚒ Front end
-  -  JS search engine
-  - ⎊ Styling
+  -  JS search engine
+  - ⎊ Basic styling
       - ⎊ Default type icons
 - ⎊ QA
-  - ⎊ >100 resource data set
+  - ⎊ ~50 resource data set
 
 #### MVP
 
@@ -259,3 +259,6 @@ functional and available for use by the intended audience.
 - CLI
   - Generate LL (multi)
   - Generate RDF (multi)
+- Front end
+  - Enhanced styling and access
+- Testing

+ 4 - 3
src/core.lua

@@ -49,13 +49,14 @@ local M = {
     -- Commonly used terms.
     RDF_TYPE = term.new_iriref_ns("rdf:type"),
 
+    CONTENT_TYPE_P = term.new_iriref_ns("pas:contentType"),
     DC_TITLE_P = term.new_iriref_ns("dc:title"),
-    SUBMITTED_P = term.new_iriref_ns("dc:dateSubmitted"),
-    TN_P = term.new_iriref_ns("pas:thumbnail"),
     FIRST_P = term.new_iriref_ns("pas:first"),
     NEXT_P = term.new_iriref_ns("pas:next"),
     PATH_P = term.new_iriref_ns("pas:sourcePath"),
-    CONTENT_TYPE_P = term.new_iriref_ns("pas:contentType"),
+    REF_P = term.new_iriref_ns("pas:ref"),
+    SUBMITTED_P = term.new_iriref_ns("dc:dateSubmitted"),
+    TN_P = term.new_iriref_ns("pas:thumbnail"),
 
     ART_T = term.new_iriref_ns("pas:Artifact"),
     PART_T = term.new_iriref_ns("pas:Part"),

+ 47 - 28
src/generator.lua

@@ -81,25 +81,33 @@ end
     its own, traverse the list of first children and use the first one found
     with a thumbnail.
 
-    @TODO This should actually use the `pas:hasRepresentation` property
-    instead of the first child.
-
     @param[in] s Subject (resource) URI.
 
     @param[in] ext Optional extension to add, including the extension separator
     (`.`). If not provided, `.jpg` is used.
 --]]
 local function get_tn_url(s, ext)  -- TODO caller needs to pass correct ext
-    if repo.gr:attr(s, pkar.RDF_TYPE)[pkar.FILE_T.hash] then
+    if repo.gr:contains(triple.new(s, pkar.RDF_TYPE, pkar.FILE_T)) then
         -- The subject is a file.
         return pkar.gen_pairtree(TN_WEB_PATH, s.data, ext or ".jpg", true)
     end
 
+    -- If it's a brick, look for its ref.
+    local ref
+    _, ref = next(repo.gr:attr(s, pkar.REF_P))
+    if ref then return get_tn_url(ref, ext) end
+
     -- Recurse through all first children until one with a thumbnail, or a
     -- leaf without children, is found.
-    local first_child
-    _, first_child = next(repo.gr:attr(s, pkar.FIRST_P))
-    if first_child then return get_tn_url(first_child, ext) end
+    local t
+    -- Look for preferred rep first.
+    _, t = next(repo.gr:attr(s, model.id_to_uri["pref_rep"]))
+    if not t then
+        -- If not found, look for reference of first child.
+        _, t = next(repo.gr:attr(s, pkar.FIRST_P))
+        if t then _, t = next(repo.gr:attr(t, pkar.REF_P)) end
+    end
+    if t then return get_tn_url(t, ext) end
 end
 
 
@@ -115,16 +123,8 @@ local function generate_dres(s, mconf)
         logger:debug("DRES pname: " .. pname)
         local pconf = ((mconf.properties or NT)[pname] or NT)
         -- RDF types are shown in in breadcrumbs.
-        if pname == pkar.RDF_TYPE.data then goto skip
-        elseif ((mconf.properties or NT)[pname] or NT).type == "rel" then
-            -- Relationship.
-            rel[pname] = {
-                label = pconf.label,
-                description = pconf.description,
-                uri = pconf.uri
-            }
-            for _, o in pairs(ots) do table.insert(dmd[pname], o.data) end
-        elseif pname == "first" then
+        if pname == pkar.RDF_TYPE.data then goto skip end
+        if pname == "first" then
             -- Build a linked list for every first found.
             for _, o in pairs(ots) do
                 -- Loop through all first children.
@@ -144,13 +144,14 @@ local function generate_dres(s, mconf)
 
                 while child_s do
                     -- Loop trough all next nodes for each first child.
+                    local _, ref = next(repo.gr:attr(child_s, pkar.REF_P))
+                    --dbg()
                     table.insert(ll, {
-                        href = pkar.gen_pairtree(
-                                "/res", child_s.data, ".html", true),
+                        href = pkar.gen_pairtree("/res", ref.data, ".html", true),
                         label = label,
-                        tn = get_tn_url(child_s),
+                        tn = get_tn_url(ref),
                     })
-                    logger:debug("Child label for ", child_s.data, ": ", ll[#ll].label or "nil")
+                    logger:debug("Child label for ", ref.data, ": ", ll[#ll].label or "nil")
                     -- There can only be one "next"
                     _, child_s = next(repo.gr:attr(child_s, pkar.NEXT_P))
                 end
@@ -159,6 +160,19 @@ local function generate_dres(s, mconf)
         elseif pname == "next" then
             -- Sibling.
             for _, o in pairs(ots) do ls_next = o.data break end
+        elseif pconf.type == "resource" then
+            -- Relationship.
+            rel[pname] = {
+                label = pconf.label,
+                description = pconf.description,
+                uri = pconf.uri,
+            }
+            for _, o in pairs(ots) do
+                table.insert(rel[pname], {
+                    href = pkar.gen_pairtree("/res", o.data, ".html", true),
+                    label = nsm.denormalize_uri(o.data),
+                })
+            end
         else
             -- Descriptive metadata.
             local attr = {
@@ -221,18 +235,23 @@ local function generate_ores(s, mconf)
         local pname = model.uri_to_id[nsm.denormalize_uri(p.data)] or p.data
         local pconf = ((mconf.properties or NT)[pname] or NT)
         -- RDF types are shown in in breadcrumbs.
-        if pname == pkar.RDF_TYPE.data then goto skip
-        elseif pconf.type == "rel" then
+        if pname == pkar.RDF_TYPE.data then goto skip end
+        if pname == "next" then
+            -- Sibling.
+            for _, o in pairs(ots) do ls_next = o.data break end
+        elseif pconf.type == "resource" then
             -- Relationship.
             rel[pname] = {
                 label = pconf.label,
                 description = pconf.description,
-                uri = pconf.uri
+                uri = pconf.uri,
             }
-            for _, o in pairs(ots) do table.insert(techmd[pname], o.data) end
-        elseif pname == "next" then
-            -- Sibling.
-            for _, o in pairs(ots) do ls_next = o.data break end
+            for _, o in pairs(ots) do
+                table.insert(rel[pname], {
+                    href = pkar.gen_pairtree("/res", o.data, ".html", true),
+                    label = nsm.denormalize_uri(o.data),
+                })
+            end
         else
             -- Descriptive metadata.
             techmd[pname] = {

+ 5 - 1
src/submission.lua

@@ -214,7 +214,7 @@ M.rsrc_to_graph = function(rsrc)
                     it:add_iter(triple.new(proxy_s, pkar.NEXT_P, brick_uri))
                 end
                 -- Add the reference.
-                -- Add RDF types.
+                -- Add basic triples.
                 for t in pairs(model.types.brick.types) do
                     it:add_iter(triple.new(
                         brick_uri,
@@ -222,6 +222,10 @@ M.rsrc_to_graph = function(rsrc)
                         model.id_to_uri[t]
                     ))
                 end
+                it:add_iter(triple.new(
+                    brick_uri,
+                    pkar.CONTENT_TYPE_P,
+                    term.new_iriref_ns("pas:Brick")))
                 -- Add reference.
                 it:add_iter(triple.new(
                     brick_uri,

+ 2 - 2
templates/dres.html

@@ -42,7 +42,7 @@
                 <% end %>
                 </dl>
             </section>
-            <% if #rel > 0 then %>
+            <% if next(rel) then %>
             <section id="res_rel">
                 <h2>Relationships</h2>
                 <dl class="res_md">
@@ -52,7 +52,7 @@
                         <% else %><code><%= ol.uri %></code><% end %>
                     </dt>
                     <% for _, o in ipairs(ol) do %>
-                        <dd><a href="/res/<%= o.data %>.html"><%= o.data %></a></dd>
+                        <dd><a href="/res/<%= o.href %>"><%= o.label %></a></dd>
                     <% end %>
                 <% end %>
                 </dl>

+ 2 - 2
templates/ores.html

@@ -42,7 +42,7 @@
                 <% end %>
                 </dl>
             </section>
-            <% if #rel > 0 then %>
+            <% if next(rel) then %>
             <section class="res_md" id="res_rel">
                 <h2>Relationships</h2>
                 <dl>
@@ -52,7 +52,7 @@
                         <% else %><code><%= ol.uri %></code><% end %>
                     </dt>
                     <% for _, o in ipairs(ol) do %>
-                        <dd><a href="/res/<%= o.data %>.html"><%= o.data %></a></dd>
+                        <dd><a href="/res/<%= o.href %>"><%= o.label %></a></dd>
                     <% end %>
                 <% end %>
                 </dl>