Module:Process Query Output 3: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| (32 intermediate revisions by the same user not shown) | |||
| Line 5: | Line 5: | ||
local full_query_arg = frame.args["full_query"] | local full_query_arg = frame.args["full_query"] | ||
local page_names_array = mw.text.split(pages_only_arg, ",") | |||
for i = 1, #page_names_array do | |||
page_names_array[i] = mw.text.trim(page_names_array[i]) | |||
end | |||
local concatenated_string = "<ul><li>Elements of page_names_array:</li>" | |||
for i, v in ipairs(page_names_array) do | |||
concatenated_string = concatenated_string .. "<li>" .. i .. ": " .. v .. "</li>" | |||
end | |||
concatenated_string = concatenated_string .. "</ul>" | |||
local | local query_output_tbl_0 = {} | ||
for | for i, page_name in ipairs(page_names_array) do | ||
match = mw.ustring.match(full_query_arg, page_name .. "%s" .. "%b()") | |||
if match == nil then | |||
-- do nothing | |||
else | |||
query_output_tbl_0[page_name] = match | |||
end | |||
end | end | ||
local | local query_output_tbl = {} | ||
for i, page_name in ipairs( | for i, page_name in ipairs(page_names_array) do | ||
match = mw.ustring.match(full_query_arg, page_name .. "%s" .. "(%b())") | match = mw.ustring.match(full_query_arg, page_name .. "%s" .. "(%b())") | ||
-- if for some reason (for example, there is an unmatched "(" in the text for one of the fields) no match was found for one of the pages, | -- if for some reason (for example, there is an unmatched "(" in the text for one of the fields) no match was found for one of the pages, | ||
| Line 33: | Line 42: | ||
query_output_tbl[page_name] = match | query_output_tbl[page_name] = match | ||
end | end | ||
end | |||
local check_for_unmatched_parentheses = "" | |||
local comparison_length = mw.ustring.len("(" .. full_query_arg .. ")") | |||
local checkmatch = mw.ustring.match("(" .. full_query_arg .. ")", "^%b()$") | |||
local length_checkmatch = 0 | |||
if checkmatch ~= nill then | |||
check_for_unmatched_parentheses = "full_query_arg is OK" | |||
length_checkmatch = mw.ustring.len(checkmatch) | |||
else | |||
check_for_unmatched_parentheses = 'full_query_arg has unmatched ")" or "(".' | |||
checkmatch = "no match found" | |||
end | end | ||
local concatenated_string_2 = "<ul>" | |||
local concatenated_string_2 = "<ul><li>Elements of query_output_tbl</li>" | |||
for k, v in pairs(query_output_tbl) do | for k, v in pairs(query_output_tbl) do | ||
| Line 42: | Line 66: | ||
concatenated_string_2 = concatenated_string_2 .. "</ul>" | concatenated_string_2 = concatenated_string_2 .. "</ul>" | ||
return concatenated_string .. concatenated_string_2 | -- see if the length of the concatenated query_ouput_table is the same as the original full_query_arg | ||
local concatenated_full_query_tbl_0 = "" | |||
for k, v in pairs(query_output_tbl_0) do | |||
concatenated_full_query_tbl_0 = concatenated_full_query_tbl_0 .. v .. ", " | |||
end | |||
concatenated_full_query_tbl_0 = mw.ustring.sub(concatenated_full_query_tbl_0, 1, -3) | |||
local length_concatenated_full_query_tbl_0 = 0 | |||
for k, v in pairs(query_output_tbl_0) do | |||
length_concatenated_full_query_tbl_0 = length_concatenated_full_query_tbl_0 + mw.ustring.len(v) + 2 | |||
end | |||
length_concatenated_full_query_tbl_0 = length_concatenated_full_query_tbl_0 - 2 | |||
local length_match_advisory = "" | |||
local concatenated_length = mw.ustring.len(concatenated_full_query_tbl_0) | |||
local original_length = mw.ustring.len(full_query_arg) | |||
if concatenated_length == original_length then | |||
length_match_advisory = "length of the concatenated query_ouput_table_0 is the same as the original full_query_arg" | |||
else | |||
length_match_advisory = "length of the concatenated query_ouput_table_0 is NOT the same as the original full_query_arg" | |||
end | |||
return "<ul><li>" .. pages_only_arg .. "</ul></li>" .. concatenated_string .. "<ul><li>" .. full_query_arg .."</li></ul>" .. "<ul><li>" .. check_for_unmatched_parentheses .. "</li><li>" .. "Length of checkmatch: " .. length_checkmatch .. "</li><li>" .. "Comparison: " .. comparison_length .. "</li><li>" .. "checkmatch: " .. checkmatch .. "</li><li>".. "</li></ul>" .. concatenated_string_2 .. "<ul><li>" .. length_match_advisory .. "</li><li>" .. "Original length: " .. original_length .. "</li><li>" .. "Concatenated length: " .. concatenated_length .. "</li><li>" .. "Calculated length of concatenated table: " .. length_concatenated_full_query_tbl_0 .. "</li></ul>" | |||
Latest revision as of 17:18, 5 December 2025
Documentation for this module may be created at Module:Process Query Output 3/doc
local p = {}
function p.processData(frame)
local pages_only_arg = frame.args["pages_only"]
local full_query_arg = frame.args["full_query"]
local page_names_array = mw.text.split(pages_only_arg, ",")
for i = 1, #page_names_array do
page_names_array[i] = mw.text.trim(page_names_array[i])
end
local concatenated_string = "<ul><li>Elements of page_names_array:</li>"
for i, v in ipairs(page_names_array) do
concatenated_string = concatenated_string .. "<li>" .. i .. ": " .. v .. "</li>"
end
concatenated_string = concatenated_string .. "</ul>"
local query_output_tbl_0 = {}
for i, page_name in ipairs(page_names_array) do
match = mw.ustring.match(full_query_arg, page_name .. "%s" .. "%b()")
if match == nil then
-- do nothing
else
query_output_tbl_0[page_name] = match
end
end
local query_output_tbl = {}
for i, page_name in ipairs(page_names_array) do
match = mw.ustring.match(full_query_arg, page_name .. "%s" .. "(%b())")
-- if for some reason (for example, there is an unmatched "(" in the text for one of the fields) no match was found for one of the pages,
-- the page is listed and a note indicates the missing data:
if match == nil then
query_output_tbl[page_name] = '<span class="error-advisory">Data for page [[' .. page_name .. "]] could not be added to the list.</span>"
else
query_output_tbl[page_name] = match
end
end
local check_for_unmatched_parentheses = ""
local comparison_length = mw.ustring.len("(" .. full_query_arg .. ")")
local checkmatch = mw.ustring.match("(" .. full_query_arg .. ")", "^%b()$")
local length_checkmatch = 0
if checkmatch ~= nill then
check_for_unmatched_parentheses = "full_query_arg is OK"
length_checkmatch = mw.ustring.len(checkmatch)
else
check_for_unmatched_parentheses = 'full_query_arg has unmatched ")" or "(".'
checkmatch = "no match found"
end
local concatenated_string_2 = "<ul><li>Elements of query_output_tbl</li>"
for k, v in pairs(query_output_tbl) do
concatenated_string_2 = concatenated_string_2 .. "<li>" .. k .. ": " .. v .. "</li>"
end
concatenated_string_2 = concatenated_string_2 .. "</ul>"
-- see if the length of the concatenated query_ouput_table is the same as the original full_query_arg
local concatenated_full_query_tbl_0 = ""
for k, v in pairs(query_output_tbl_0) do
concatenated_full_query_tbl_0 = concatenated_full_query_tbl_0 .. v .. ", "
end
concatenated_full_query_tbl_0 = mw.ustring.sub(concatenated_full_query_tbl_0, 1, -3)
local length_concatenated_full_query_tbl_0 = 0
for k, v in pairs(query_output_tbl_0) do
length_concatenated_full_query_tbl_0 = length_concatenated_full_query_tbl_0 + mw.ustring.len(v) + 2
end
length_concatenated_full_query_tbl_0 = length_concatenated_full_query_tbl_0 - 2
local length_match_advisory = ""
local concatenated_length = mw.ustring.len(concatenated_full_query_tbl_0)
local original_length = mw.ustring.len(full_query_arg)
if concatenated_length == original_length then
length_match_advisory = "length of the concatenated query_ouput_table_0 is the same as the original full_query_arg"
else
length_match_advisory = "length of the concatenated query_ouput_table_0 is NOT the same as the original full_query_arg"
end
return "<ul><li>" .. pages_only_arg .. "</ul></li>" .. concatenated_string .. "<ul><li>" .. full_query_arg .."</li></ul>" .. "<ul><li>" .. check_for_unmatched_parentheses .. "</li><li>" .. "Length of checkmatch: " .. length_checkmatch .. "</li><li>" .. "Comparison: " .. comparison_length .. "</li><li>" .. "checkmatch: " .. checkmatch .. "</li><li>".. "</li></ul>" .. concatenated_string_2 .. "<ul><li>" .. length_match_advisory .. "</li><li>" .. "Original length: " .. original_length .. "</li><li>" .. "Concatenated length: " .. concatenated_length .. "</li><li>" .. "Calculated length of concatenated table: " .. length_concatenated_full_query_tbl_0 .. "</li></ul>"
end
return p