Module:ZZProbe: Difference between revisions

From Bodhicitta
(probe)
 
(probe)
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]]',
local variants = {
'?QuoteSource#-=QuoteSource',
{ label = 'plain',  po = '?QuoteSource=V' },
'?SegmentOrder#=SegmentOrder',
{ label = 'hash',  po = '?QuoteSource#=V' },
limit = 5000
{ label = 'hashmin',po = '?QuoteSource#-=V' },
}
}
if not q then return 'QUERY NIL' end
for _, v in ipairs(variants) do
local names, n = {}, 0
local q = mw.smw.ask{
for _, row in ipairs(q) do
'[[' .. SSC_PREFIX .. ']][[SegmentFormat::Quote]]',
local s = row.QuoteSource
v.po,
if type(s) ~= 'table' then s = { s } end
'?SegmentOrder#=O',
for _, src in ipairs(s) do
limit = 60
local pg = src
}
if type(pg) == 'table' then pg = pg.fulltext end
local got = 0
if type(pg) == 'string' then pg = mw.text.trim(pg) end
if q then
if type(pg) == 'string' and pg ~= '' then n = n + 1; names[pg] = true end
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 end
end
end
end
table.insert(out, v.label .. '=' .. got .. '/' .. (q and #q or 0))
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

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 = {}
	local variants = {
		{ label = 'plain',  po = '?QuoteSource=V' },
		{ label = 'hash',   po = '?QuoteSource#=V' },
		{ label = 'hashmin',po = '?QuoteSource#-=V' },
	}
	for _, v in ipairs(variants) do
		local q = mw.smw.ask{
			'[[' .. SSC_PREFIX .. ']][[SegmentFormat::Quote]]',
			v.po,
			'?SegmentOrder#=O',
			limit = 60
		}
		local got = 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 end
			end
		end
		table.insert(out, v.label .. '=' .. got .. '/' .. (q and #q or 0))
	end
	return table.concat(out, '  ')
end
return p