Module:SMWUtils: Difference between revisions

Add deduplication by subject column to eliminate duplicate rows from multiple matching subobjects (via update-page on MediaWiki MCP Server)
Fix deduplication: key on printout columns instead of subject (subobject subjects are unique per-input) (via update-page on MediaWiki MCP Server)
 
Line 42: Line 42:
end
end


-- Deduplicate rows by subject column (row[1]), keeping the first occurrence
-- Deduplicate rows by printout columns, keeping the first occurrence
local function deduplicateBySubject(rows)
-- Uses stripped text of printout columns (2..n+1) as the dedup key,
-- since subobject queries produce unique subjects (e.g. Page#sub1, Page#sub2)
-- but identical printout values for the same parent page
local function deduplicateRows(rows, numPrintouts)
     local seen = {}
     local seen = {}
     local deduped = {}
     local deduped = {}
     for _, row in ipairs(rows) do
     for _, row in ipairs(rows) do
         local key = stripHtml(row[1]) or row[1] or ''
         local keyParts = {}
        for j = 2, numPrintouts + 1 do
            table.insert(keyParts, stripHtml(row[j]) or '')
        end
        local key = table.concat(keyParts, '|')
         if not seen[key] then
         if not seen[key] then
             seen[key] = true
             seen[key] = true
Line 191: Line 198:
     end
     end
      
      
     -- Deduplicate by subject (multiple subobjects on same page produce duplicate rows)
     -- Deduplicate (multiple subobjects on same page produce duplicate rows)
     filtered = deduplicateBySubject(filtered)
     filtered = deduplicateRows(filtered, #printoutProps)
      
      
     -- Build headers list
     -- Build headers list
Line 272: Line 279:
     end
     end
      
      
     -- Deduplicate by subject (multiple subobjects on same page produce duplicate rows)
     -- Deduplicate (multiple subobjects on same page produce duplicate rows)
     filtered = deduplicateBySubject(filtered)
     filtered = deduplicateRows(filtered, #printoutProps)
      
      
     -- Build headers list
     -- Build headers list
MediaWiki Appliance - Powered by TurnKey Linux