Module:ZZProbe: Difference between revisions

From Bodhicitta
(probe)
 
(probe)
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
local p = {}
local p = {}
local SSC_PREFIX = '~Translation Memory:016-Tsadra-SSC-Root/*'
local SSC_PREFIX = '~Translation Memory:016-Tsadra-SSC-Root/*'
local function firstValue(v) if type(v)=='table' then return v[1] end return v end
function p.main()
function p.main()
local q = mw.smw.ask{
local out = {}
'[[' .. SSC_PREFIX .. ']][[SegmentFormat::Quote]]',
for _, lim in ipairs({ 50, 200, 500, 1000, 5000 }) do
'?QuoteSource#-=QuoteSource',
local q = mw.smw.ask{
'?SegmentOrder#=SegmentOrder',
'[[' .. SSC_PREFIX .. ']][[SegmentFormat::Quote]]',
limit = 5000
'?QuoteSource#-=V',
}
'?SegmentOrder#=O',
if not q then return 'QUERY NIL' end
limit = lim
local names, n = {}, 0
}
for _, row in ipairs(q) do
local got, names = 0, {}
local s = row.QuoteSource
if q then
if type(s) ~= 'table' then s = { s } end
for _, row in ipairs(q) do
for _, src in ipairs(s) do
local s = row.V
local pg = src
if type(s) == 'table' then s = s[1] end
if type(pg) == 'table' then pg = pg.fulltext end
if type(s) == 'table' then s = s.fulltext end
if type(pg) == 'string' then pg = mw.text.trim(pg) end
if type(s) == 'string' and s ~= '' then got = got + 1; names[s] = true end
if type(pg) == 'string' and pg ~= '' then n = n + 1; names[pg] = true end
end
end
end
local d = 0
for _ in pairs(names) do d = d + 1 end
table.insert(out, 'lim' .. lim .. ': rows=' .. (q and #q or 0) .. ' vals=' .. got .. ' distinct=' .. d)
end
end
local keys = {}
return table.concat(out, ' | ')
for k in pairs(names) do table.insert(keys, k) end
table.sort(keys)
-- now the SECOND query, exactly as p.main does it
local pages = mw.smw.ask{
'[[' .. table.concat(keys, '||') .. ']]',
'?#-=Page',
'?Display title of=Title',
limit = 500
}
return '#rows=' .. #q .. ' values=' .. n .. ' distinct=' .. #keys ..
' || secondQuery=' .. (pages and #pages or 'NIL')
end
end
return p
return p

Latest revision as of 14:27, 21 September 2026

Documentation for this module may be created at Module:ZZProbe/doc

local p = {}
local SSC_PREFIX = '~Translation Memory:016-Tsadra-SSC-Root/*'
function p.main()
	local out = {}
	for _, lim in ipairs({ 50, 200, 500, 1000, 5000 }) do
		local q = mw.smw.ask{
			'[[' .. SSC_PREFIX .. ']][[SegmentFormat::Quote]]',
			'?QuoteSource#-=V',
			'?SegmentOrder#=O',
			limit = lim
		}
		local got, names = 0, {}
		if q then
			for _, row in ipairs(q) do
				local s = row.V
				if type(s) == 'table' then s = s[1] end
				if type(s) == 'table' then s = s.fulltext end
				if type(s) == 'string' and s ~= '' then got = got + 1; names[s] = true end
			end
		end
		local d = 0
		for _ in pairs(names) do d = d + 1 end
		table.insert(out, 'lim' .. lim .. ': rows=' .. (q and #q or 0) .. ' vals=' .. got .. ' distinct=' .. d)
	end
	return table.concat(out, ' | ')
end
return p