Module:ZZProbe

From Bodhicitta
Revision as of 14:27, 21 September 2026 by Jeremi (talk | contribs) (probe)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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

local p = {}
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()
	local q = mw.smw.ask{
		'[[' .. SSC_PREFIX .. ']][[SegmentFormat::Quote]]',
		'?QuoteSource#-=QuoteSource',
		'?SegmentOrder#=SegmentOrder',
		limit = 5000
	}
	if not q then return 'QUERY NIL' end
	local names, n = {}, 0
	for _, row in ipairs(q) do
		local s = row.QuoteSource
		if type(s) ~= 'table' then s = { s } end
		for _, src in ipairs(s) do
			local pg = src
			if type(pg) == 'table' then pg = pg.fulltext end
			if type(pg) == 'string' then pg = mw.text.trim(pg) end
			if type(pg) == 'string' and pg ~= '' then n = n + 1; names[pg] = true end
		end
	end
	local keys = {}
	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
return p