Module:SMWUtils: Difference between revisions
Add mainlabel support to include subject/page name column in output (via update-page on MediaWiki MCP Server) |
Add deduplication by subject column to eliminate duplicate rows from multiple matching subobjects (via update-page on MediaWiki MCP Server) |
||
| Line 40: | Line 40: | ||
if not s then return nil end | if not s then return nil end | ||
return trim(s:gsub('<[^>]+>', ''):gsub('&[^;]+;', '')) | return trim(s:gsub('<[^>]+>', ''):gsub('&[^;]+;', '')) | ||
end | |||
-- Deduplicate rows by subject column (row[1]), keeping the first occurrence | |||
local function deduplicateBySubject(rows) | |||
local seen = {} | |||
local deduped = {} | |||
for _, row in ipairs(rows) do | |||
local key = stripHtml(row[1]) or row[1] or '' | |||
if not seen[key] then | |||
seen[key] = true | |||
table.insert(deduped, row) | |||
end | |||
end | |||
return deduped | |||
end | end | ||
| Line 176: | Line 190: | ||
end | end | ||
end | end | ||
-- Deduplicate by subject (multiple subobjects on same page produce duplicate rows) | |||
filtered = deduplicateBySubject(filtered) | |||
-- Build headers list | -- Build headers list | ||
| Line 254: | Line 271: | ||
end | end | ||
end | end | ||
-- Deduplicate by subject (multiple subobjects on same page produce duplicate rows) | |||
filtered = deduplicateBySubject(filtered) | |||
-- Build headers list | -- Build headers list | ||