Jump to content

Module:User:IsomorphycSandbox/data tables interface

From Wiktionary, the free dictionary


local export = {}

--local base_location = "Module:data tables"
local base_location = "Module:data tables"
local metadata = mw.loadData(base_location.."/metadata")
local shard_location_base = metadata["shard_location_base"][1] --"Module:data tables/data"
local shards = metadata["shards"]
local tables = metadata["tables"] --{"grc_RLBG_lemma_to_index", "grc_RWoodhouse_lemma_to_headwords", "grc_RWoodhouse_lemma_to_infinitives", "la_RMA_index_to_phrases", "grc_RCunliffe_lemma_to_index", "la_RMA_lemmas_no_collision_to_ix_phrase" }

function load_tables_unsharded()
	function maybe_mw_load(x)
		local success, val = pcall(function() return mw.loadData(x) end)
 		if success then return val else return nil end	end
	local unsharded, i = {}, 0
    while #unsharded == i do
      local val = maybe_mw_load(shard_location_base.."Unsharded"..tostring(i))  ---shard_location_base
      if val ~= nil then 
      	unsharded[#unsharded+1] = val end
      i = i + 1
    end
    return unsharded
end

local unsharded = load_tables_unsharded()

function export.hello()
	return unsharded[1]
end

function print_table(t,d)
	s = {"Table:<br/>"}
	for i,x in pairs(t) do 
		s[#s+1]=tostring(i)
		s[#s+1]=": "
		if type(x[1]) == "table" then 
			s[#s+1] = print_table(x, ",") 
		else 
			for j,y in pairs(x) do
				s[#s+1]=y
				s[#s+1]=", " 
			end
			s[#s] = ""
		end
		s[#s+1]=d
	end
	return table.concat(s)
end

function export.print_freezer()
	return "Array test:<br/>"..print_table(require("Module:data tables").load_table("freezer"), "<br/>")
end

function export.test_array()
	return "Array test:<br/>"..print_table(require("Module:data tables").index_table_all("la_RMA_index_to_phrases", {"1", "2", "3", "4", "5", "6"}), "<br/>")
end

function export.list_tables()
	return "Tables in "..base_location..": <br/>"..table.concat(require(base_location).list_tables(),"<br/>")
end

function export.index(frame)
	--ix = mw.loadData("Module:R:Cunliffe/data")
	local args = frame:getParent().args
	local title = args['w'] or mw.title.getCurrentTitle().text
	local F = require("Module:data tables")
	local lbg, cunliffe = "grc_RLBG_lemma_to_index", "grc_R:Cunliffe_lemma_to_index"
	n = F.index_table(lbg, title)
	if n then
		return ("[http://stephanus.tlg.uci.edu/cunliffe/#eid="..n[1].."&context=lsj "..title.."] in ")
	else
		return ""
	end
end

return export