<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://stockhub.co/index.php?action=history&amp;feed=atom&amp;title=Module%3ASandbox%2FJeblad%2FNLG</id>
	<title>Module:Sandbox/Jeblad/NLG - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://stockhub.co/index.php?action=history&amp;feed=atom&amp;title=Module%3ASandbox%2FJeblad%2FNLG"/>
	<link rel="alternate" type="text/html" href="https://stockhub.co/index.php?title=Module:Sandbox/Jeblad/NLG&amp;action=history"/>
	<updated>2026-05-24T21:00:29Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.5</generator>
	<entry>
		<id>https://stockhub.co/index.php?title=Module:Sandbox/Jeblad/NLG&amp;diff=145599&amp;oldid=prev</id>
		<title>imported&gt;Primefac: Primefac moved page Module:NLG to Module:Sandbox/Jeblad/NLG without leaving a redirect: per TFD</title>
		<link rel="alternate" type="text/html" href="https://stockhub.co/index.php?title=Module:Sandbox/Jeblad/NLG&amp;diff=145599&amp;oldid=prev"/>
		<updated>2019-11-17T04:05:22Z</updated>

		<summary type="html">&lt;p&gt;Primefac moved page &lt;a href=&quot;/index.php?title=Module:NLG&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;Module:NLG (page does not exist)&quot;&gt;Module:NLG&lt;/a&gt; to &lt;a href=&quot;/research/Module:Sandbox/Jeblad/NLG&quot; title=&quot;Module:Sandbox/Jeblad/NLG&quot;&gt;Module:Sandbox/Jeblad/NLG&lt;/a&gt; without leaving a redirect: per &lt;a href=&quot;https://en.wikipedia.org/wiki/Templates_for_discussion/Log/2019_November_5&quot; class=&quot;extiw&quot; title=&quot;wikipedia:Templates for discussion/Log/2019 November 5&quot;&gt;TFD&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;local nlg = {}&lt;br /&gt;
&lt;br /&gt;
--- Create the intersection of two tag sets&lt;br /&gt;
local function intersection( a, b )&lt;br /&gt;
	local check = {}&lt;br /&gt;
	for _,v in ipairs(a) do&lt;br /&gt;
		check[v] = true&lt;br /&gt;
	end&lt;br /&gt;
	local found = {}&lt;br /&gt;
	for _,v in ipairs(b) do&lt;br /&gt;
		if check[v] then&lt;br /&gt;
			found[1+#found] = v&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	return found&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local classes = {}&lt;br /&gt;
-- this should probably in a separate module&lt;br /&gt;
local layout = {&lt;br /&gt;
	[&amp;#039;lead-in&amp;#039;] = 0,&lt;br /&gt;
	[&amp;#039;history&amp;#039;] = 50,&lt;br /&gt;
	[&amp;#039;geography&amp;#039;] = 60,&lt;br /&gt;
	[&amp;#039;politics&amp;#039;] = 70,&lt;br /&gt;
	[&amp;#039;early-life&amp;#039;] = 30,&lt;br /&gt;
	[&amp;#039;death&amp;#039;] = 40,&lt;br /&gt;
	[&amp;#039;legacy&amp;#039;] = 50,&lt;br /&gt;
	[&amp;#039;bibliography&amp;#039;] = 60,&lt;br /&gt;
	[&amp;#039;notes&amp;#039;] = 70,&lt;br /&gt;
	[&amp;#039;footnotes&amp;#039;] = 70,&lt;br /&gt;
	[&amp;#039;references&amp;#039;] = 80,&lt;br /&gt;
	[&amp;#039;literature&amp;#039;] = 90,&lt;br /&gt;
	[&amp;#039;external-links&amp;#039;] = 100,&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
local function createFromClass(t)&lt;br /&gt;
	return classes[t.class] and classes[t.class](t)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function createFromWeight(t)&lt;br /&gt;
	local max = -100&lt;br /&gt;
	local constructor = nil&lt;br /&gt;
	local class = nil&lt;br /&gt;
	for _,v in pairs(classes) do&lt;br /&gt;
		local weight = v.weight(t)&lt;br /&gt;
		if weight&amp;gt;max then&lt;br /&gt;
			max = weight&lt;br /&gt;
			constructor = v&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	return constructor and constructor(t)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function create(t)&lt;br /&gt;
	return createFromClass(t) or createFromWeight(t)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--- Table acting as a baseclass for Plan&lt;br /&gt;
local Plan = {}&lt;br /&gt;
Plan.__index = Plan&lt;br /&gt;
&lt;br /&gt;
classes.plan = Plan&lt;br /&gt;
&lt;br /&gt;
setmetatable(Plan, {&lt;br /&gt;
	__call = function(cls, ...)&lt;br /&gt;
		local self = setmetatable({}, cls)&lt;br /&gt;
		self:_init(...)&lt;br /&gt;
		return self&lt;br /&gt;
	end,&lt;br /&gt;
})&lt;br /&gt;
&lt;br /&gt;
--- Initialiser for the Plan class&lt;br /&gt;
-- @param t table holding additional data&lt;br /&gt;
function Plan:_init( t )&lt;br /&gt;
	self._data = t&lt;br /&gt;
	self._active = true&lt;br /&gt;
	self._position = 0&lt;br /&gt;
	if self._data.class == nil then&lt;br /&gt;
		self._class = self:class()&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--- Get nudge&lt;br /&gt;
-- @return number&lt;br /&gt;
function Plan:nudge()&lt;br /&gt;
	for k,v in pairs(layout) do&lt;br /&gt;
	return self._class or self._data.class or &amp;#039;plan&amp;#039;&lt;br /&gt;
	end&lt;br /&gt;
	return&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--- Get class&lt;br /&gt;
-- @return string&lt;br /&gt;
function Plan:class()&lt;br /&gt;
	return self._class or self._data.class or &amp;#039;plan&amp;#039;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--- Is status active?&lt;br /&gt;
-- @return boolean&lt;br /&gt;
function Plan:isActive()&lt;br /&gt;
	return self._active&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--- Activate status&lt;br /&gt;
-- @return boolean&lt;br /&gt;
function Plan:activate()&lt;br /&gt;
	self._active = true&lt;br /&gt;
	return self._active&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--- Deactivate status&lt;br /&gt;
-- @return boolean&lt;br /&gt;
function Plan:deactivate()&lt;br /&gt;
	self._active = false&lt;br /&gt;
	return self._active&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--- Weight of the given class viewed as a possible Plan instance&lt;br /&gt;
-- @param t table holding data used during test&lt;br /&gt;
function Plan.weight( t )&lt;br /&gt;
	local weight = 0&lt;br /&gt;
	if not t then&lt;br /&gt;
		return weight&lt;br /&gt;
	end&lt;br /&gt;
	weight = weight + (t.class == &amp;#039;plan&amp;#039; and 100 or 0)&lt;br /&gt;
	weight = weight + (t.tags and 10 or 0)&lt;br /&gt;
	weight = weight + (t.preconditions and 10 or 0)&lt;br /&gt;
	weight = weight + (t.postconditions and 10 or 0)&lt;br /&gt;
	return weight&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--- Get the spawned tags by optionally filtering out a subset&lt;br /&gt;
-- @param id(s) from the tagset&lt;br /&gt;
-- @return table of Tags, otherwise empty table&lt;br /&gt;
function Plan:tags(...)&lt;br /&gt;
	local args = {...}&lt;br /&gt;
	if #args == 0 then&lt;br /&gt;
		return self._data.tags or {}&lt;br /&gt;
	else&lt;br /&gt;
		return intersection({...}, self._data.tags)&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--- Get the preconditions&lt;br /&gt;
-- @return table of Expressions, otherwise empty table&lt;br /&gt;
function Plan:preconditions()&lt;br /&gt;
	return self._data.preconditions or {}&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--- Get the postconditions&lt;br /&gt;
-- @return table of Expressions, otherwise empty table&lt;br /&gt;
function Plan:postconditions()&lt;br /&gt;
	return self._data.postconditions or {}&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--- Table acting as a subclass for Document&lt;br /&gt;
local Document = {}&lt;br /&gt;
Document.__index = Document&lt;br /&gt;
&lt;br /&gt;
classes.document = Document&lt;br /&gt;
&lt;br /&gt;
setmetatable(Document, {&lt;br /&gt;
  __index = Plan,&lt;br /&gt;
  __call = function (cls, ...)&lt;br /&gt;
    local self = setmetatable({}, cls)&lt;br /&gt;
    self:_init(...)&lt;br /&gt;
    return self&lt;br /&gt;
  end,&lt;br /&gt;
})&lt;br /&gt;
&lt;br /&gt;
--- Initialiser for the Document class&lt;br /&gt;
-- @param t table holding additional data&lt;br /&gt;
function Document:_init( t )&lt;br /&gt;
  Plan._init(self, t)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--- Get class&lt;br /&gt;
-- @return string&lt;br /&gt;
function Document:class()&lt;br /&gt;
	return self._class or self._data.class or &amp;#039;document&amp;#039;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--- Weight of the given class viewed as a possible Document instance&lt;br /&gt;
-- @param t table holding data used during test&lt;br /&gt;
function Document.weight( t )&lt;br /&gt;
	local weight = 0&lt;br /&gt;
	if not t then&lt;br /&gt;
		return weight&lt;br /&gt;
	end&lt;br /&gt;
	weight = weight + 0.9*Plan.weight(t)&lt;br /&gt;
	weight = weight + (t.class == &amp;#039;document&amp;#039; and 100 or 0)&lt;br /&gt;
	weight = weight + (t.constituent and 10 or 0)&lt;br /&gt;
	weight = weight + (t.title and 10 or 0)&lt;br /&gt;
	return weight&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--- Get the title&lt;br /&gt;
-- @return any if found, otherwise nil&lt;br /&gt;
function Document:title()&lt;br /&gt;
	return self._data.title&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--- Get the constituents&lt;br /&gt;
-- @return table of Plan, otherwise empty table&lt;br /&gt;
function Document:constituents()&lt;br /&gt;
	return self._data.constituents or {}&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--- Get the activeConstituents&lt;br /&gt;
-- @return table of Plan, otherwise empty table&lt;br /&gt;
function Document:constituents()&lt;br /&gt;
	local found = {}&lt;br /&gt;
	for _,v in ipairs(self._data.constituents or {}) do&lt;br /&gt;
		found[1+#found] = v&lt;br /&gt;
	end&lt;br /&gt;
	return found&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--- Table acting as a subclass for Constituent&lt;br /&gt;
local Constituent = {}&lt;br /&gt;
Constituent.__index = Constituent&lt;br /&gt;
&lt;br /&gt;
classes.constituent = Constituent&lt;br /&gt;
&lt;br /&gt;
setmetatable(Constituent, {&lt;br /&gt;
  __index = Plan,&lt;br /&gt;
  __call = function (cls, ...)&lt;br /&gt;
    local self = setmetatable({}, cls)&lt;br /&gt;
    self:_init(...)&lt;br /&gt;
    return self&lt;br /&gt;
  end,&lt;br /&gt;
})&lt;br /&gt;
&lt;br /&gt;
--- Initialiser for the Constituent class&lt;br /&gt;
-- @param t table holding additional data&lt;br /&gt;
function Constituent:_init( t )&lt;br /&gt;
  Plan._init(self, t)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--- Get class&lt;br /&gt;
-- @return string&lt;br /&gt;
function Constituent:class()&lt;br /&gt;
	return self._class or self._data.class or &amp;#039;constituent&amp;#039;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
--- Weight of the given class viewed as a possible Constituent instance&lt;br /&gt;
-- @param t table holding data used during test&lt;br /&gt;
function Constituent.weight( t )&lt;br /&gt;
	local weight = 0&lt;br /&gt;
	if not t then&lt;br /&gt;
		return weight&lt;br /&gt;
	end&lt;br /&gt;
	weight = weight + 0.9*Plan.weight(t)&lt;br /&gt;
	weight = weight + (t.class == &amp;#039;constituent&amp;#039; and 100 or 0)&lt;br /&gt;
	weight = weight + (t.nucleus and 10 or 0)&lt;br /&gt;
	weight = weight + (t.satelite and 10 or 0)&lt;br /&gt;
	weight = weight + (t.constituents and 10 or 0)&lt;br /&gt;
	weight = weight + (t.relation and 10 or 0)&lt;br /&gt;
	return weight&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
if 1 or _G[&amp;#039;_BDD&amp;#039;] then&lt;br /&gt;
	nlg[&amp;#039;filter&amp;#039;] = filter&lt;br /&gt;
	nlg[&amp;#039;create&amp;#039;] = create&lt;br /&gt;
	nlg[&amp;#039;createFromClass&amp;#039;] = createFromClass&lt;br /&gt;
	nlg[&amp;#039;createFromWeight&amp;#039;] = createFromWeight&lt;br /&gt;
	nlg[&amp;#039;Plan&amp;#039;] = Plan&lt;br /&gt;
	nlg[&amp;#039;Document&amp;#039;] = Document&lt;br /&gt;
	nlg[&amp;#039;Constituent&amp;#039;] = Constituent&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
nlg.load = function(...)&lt;br /&gt;
	local constituents = {}&lt;br /&gt;
	for _,v in ipairs({...}) do&lt;br /&gt;
		local data = nil&lt;br /&gt;
		local title = &amp;#039;Module:NLG/&amp;#039; .. v&lt;br /&gt;
		if pcall(function() data = mw.loadData( title ) end) and data then&lt;br /&gt;
			for _,w in ipairs(data) do&lt;br /&gt;
				constituents[1+#constituents] = create(w)&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	local root = Document({&lt;br /&gt;
		[&amp;#039;class&amp;#039;] = &amp;#039;document&amp;#039;,&lt;br /&gt;
		[&amp;#039;constituents&amp;#039;] = constituents&lt;br /&gt;
	})&lt;br /&gt;
	return root&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return nlg&lt;/div&gt;</summary>
		<author><name>imported&gt;Primefac</name></author>
	</entry>
</feed>