Difference between revisions of "Module:CountryAdjectiveDemonym"

From blackwiki
Jump to navigation Jump to search
blackwiki>MusikBot II
m (Protected "Module:CountryNameDemonym": High-risk template or module (more info) ([Edit=Require autoconfirmed or confirmed access] (indefinite)))
blackwiki>BrownHairedGirl
(separate demonyms from adjectives)
Line 1: Line 1:
local CountryNameDemonym = { }
+
local CountryAdjectiveDemonym = { }
  
local CountryNameDemonymDataLoaded = false
+
local CountryAdjectiveDemonymDataLoaded = false
  
local CountryNameDemonymNameCounter = 0
+
local countryAdjectivesToNounsTable = { }
 +
local countryNounsToAdjectivesTable  = { }
  
local countryAdjectivesToNounsTable = {
+
local countryDemonymsToNounsTable = { }
}
+
local countryNounsToDemonymsTable = { }
local countryNounstoAdjectivesTable = {
 
}
 
  
local countriesPrefixedByTheTable = {
+
local countriesPrefixedByTheTable = { }
}
 
  
function CountryNameDemonymDoLoadData()
+
function CountryAdjectiveDemonymDoLoadData()
 
countriesPrefixedByTheTable = mw.loadData( 'Module:CountryNameDemonym/the' )
 
countriesPrefixedByTheTable = mw.loadData( 'Module:CountryNameDemonym/the' )
countryNounstoAdjectivesTable = mw.loadData( 'Module:CountryNameDemonym/adjectives' )
+
countryNounsToAdjectivesTable = mw.loadData( 'Module:CountryNameDemonym/adjectives' )
local myCounter = 0
+
countryNounsToDemonymsTable = mw.loadData( 'Module:CountryNameDemonym/Demonyms' )
local myNoun, myAdj
+
local myNoun, myAdjective
for myNoun, myAdj in pairs(countryNounstoAdjectivesTable) do
+
countryAdjectivesToNounsTable[myAdj] = myNoun
+
-- first, load the adjectives table
myCounter = myCounter + 1
+
for myNoun, myAdjective in pairs(countryNounsToAdjectivesTable) do
 +
countryAdjectivesToNounsTable[myAdjective] = myNoun
 
end
 
end
CountryNameDemonymNameCounter = myCounter
+
 
CountryNameDemonymDataLoaded = true
+
-- Now load the denomyms table
return myCounter
+
local myDemonym
 +
for myNoun, myDemonym in pairs(countryNounsToDemonymsTable) do
 +
countryDemonymsToNounsTable[myDemonym] = myNoun
 +
end
 +
CountryAdjectiveDemonymDataLoaded = true
 +
return
 
end
 
end
  
Line 33: Line 37:
 
-- then return that prefix
 
-- then return that prefix
 
-- Otherwise just return an empty string
 
-- Otherwise just return an empty string
function CountryNameDemonym.countryPrefixThe(frame)
+
function CountryAdjectiveDemonym.countryPrefixThe(frame)
 
local s = frame.args[1]
 
local s = frame.args[1]
if not CountryNameDemonymDataLoaded then
+
if not CountryAdjectiveDemonymDataLoaded then
CountryNameDemonymDoLoadData()
+
CountryAdjectiveDemonymDoLoadData()
 
end
 
end
 
if (countriesPrefixedByTheTable[s] == true) then
 
if (countriesPrefixedByTheTable[s] == true) then
Line 45: Line 49:
  
  
function CountryNameDemonym.getCountryFromDemonym(frame)
+
function CountryAdjectiveDemonym.getCountryFromAdjective(frame)
 
local s = frame.args[1]
 
local s = frame.args[1]
if not CountryNameDemonymDataLoaded then
+
if not CountryAdjectiveDemonymDataLoaded then
CountryNameDemonymDoLoadData()
+
CountryAdjectiveDemonymDoLoadData()
 
end
 
end
 
local retval = countryAdjectivesToNounsTable[s]
 
local retval = countryAdjectivesToNounsTable[s]
Line 58: Line 62:
  
  
function CountryNameDemonym.getDemonymFromCountry(frame)
+
function CountryAdjectiveDemonym.getCountryFromDemonym(frame)
 +
local s = frame.args[1]
 +
if not CountryAdjectiveDemonymDataLoaded then
 +
CountryAdjectiveDemonymDoLoadData()
 +
end
 +
local retval = countryDemonymsToNounsTable[s]
 +
if retval == nil then
 +
retval = countryAdjectivesToNounsTable[s]
 +
end
 +
if retval == nil then
 +
return ""
 +
end
 +
return retval
 +
end
 +
 
 +
 
 +
function CountryAdjectiveDemonym.getAdjectiveFromCountry(frame)
 +
local s = frame.args[1]
 +
if not CountryAdjectiveDemonymDataLoaded then
 +
CountryAdjectiveDemonymDoLoadData()
 +
end
 +
local retval = countryNounsToAdjectivesTable[s]
 +
if retval == nil then
 +
return ""
 +
end
 +
return retval
 +
end
 +
 
 +
 
 +
function CountryAdjectiveDemonym.getDemonymFromCountry(frame)
 
local s = frame.args[1]
 
local s = frame.args[1]
if not CountryNameDemonymDataLoaded then
+
if not CountryAdjectiveDemonymDataLoaded then
CountryNameDemonymDoLoadData()
+
CountryAdjectiveDemonymDoLoadData()
 +
end
 +
local retval
 +
retval = countryNounsToDemonymsTable[s]
 +
if retval == nil then
 +
retval = countryNounsToAdjectivesTable[s]
 
end
 
end
local retval = countryNounstoAdjectivesTable[s]
 
 
if retval == nil then
 
if retval == nil then
 
return ""
 
return ""
Line 70: Line 107:
 
end
 
end
  
function CountryNameDemonym.stripThe(frame)
+
 
 +
function CountryAdjectiveDemonym.stripThe(frame)
 
local s = frame.args[1]
 
local s = frame.args[1]
 
if s == nil then
 
if s == nil then
Line 83: Line 121:
  
  
return CountryNameDemonym
+
return CountryAdjectiveDemonym

Revision as of 22:25, 7 October 2019

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

local CountryAdjectiveDemonym = { }

local CountryAdjectiveDemonymDataLoaded = false

local countryAdjectivesToNounsTable = { }
local countryNounsToAdjectivesTable  = { }

local countryDemonymsToNounsTable = { }
local countryNounsToDemonymsTable  = { }

local countriesPrefixedByTheTable = { }

function CountryAdjectiveDemonymDoLoadData()
	countriesPrefixedByTheTable = mw.loadData( 'Module:CountryNameDemonym/the' )
	countryNounsToAdjectivesTable = mw.loadData( 'Module:CountryNameDemonym/adjectives' )
	countryNounsToDemonymsTable = mw.loadData( 'Module:CountryNameDemonym/Demonyms' )
	local myNoun, myAdjective
	
	-- first, load the adjectives table
	for myNoun, myAdjective in pairs(countryNounsToAdjectivesTable) do
		countryAdjectivesToNounsTable[myAdjective] = myNoun
	end

	-- Now load the denomyms table
	local myDemonym
	for myNoun, myDemonym in pairs(countryNounsToDemonymsTable) do
		countryDemonymsToNounsTable[myDemonym] = myNoun
	end
	CountryAdjectiveDemonymDataLoaded = true
	return
end


-- ############### Publicly accesible functions #######################

-- if the country name is prefixed by "the" in running text,
-- then return that prefix
-- Otherwise just return an empty string
function CountryAdjectiveDemonym.countryPrefixThe(frame)
	local s = frame.args[1]
	if not CountryAdjectiveDemonymDataLoaded then
		CountryAdjectiveDemonymDoLoadData()
	end
	if (countriesPrefixedByTheTable[s] == true) then
		return "the "
	end
	return ""
end


function CountryAdjectiveDemonym.getCountryFromAdjective(frame)
	local s = frame.args[1]
	if not CountryAdjectiveDemonymDataLoaded then
		CountryAdjectiveDemonymDoLoadData()
	end
	local retval = countryAdjectivesToNounsTable[s]
	if retval == nil then
		return ""
	end
	return retval
end


function CountryAdjectiveDemonym.getCountryFromDemonym(frame)
	local s = frame.args[1]
	if not CountryAdjectiveDemonymDataLoaded then
		CountryAdjectiveDemonymDoLoadData()
	end
	local retval = countryDemonymsToNounsTable[s]
	if retval == nil then 
		retval = countryAdjectivesToNounsTable[s]
	end
	if retval == nil then
		return ""
	end
	return retval
end


function CountryAdjectiveDemonym.getAdjectiveFromCountry(frame)
	local s = frame.args[1]
	if not CountryAdjectiveDemonymDataLoaded then
		CountryAdjectiveDemonymDoLoadData()
	end
	local retval = countryNounsToAdjectivesTable[s]
	if retval == nil then
		return ""
	end
	return retval
end


function CountryAdjectiveDemonym.getDemonymFromCountry(frame)
	local s = frame.args[1]
	if not CountryAdjectiveDemonymDataLoaded then
		CountryAdjectiveDemonymDoLoadData()
	end
	local retval
	retval = countryNounsToDemonymsTable[s]
	if retval == nil then
		retval = countryNounsToAdjectivesTable[s]
	end
	if retval == nil then
		return ""
	end
	return retval
end


function CountryAdjectiveDemonym.stripThe(frame)
	local s = frame.args[1]
	if s == nil then
		return ""
	end
	if mw.ustring.match( s, "^[T]he Gambia$") ~= nil then
		return s
	end
	local stripped = mw.ustring.gsub(s, "^[tT]he ", "")
	return stripped
end


return CountryAdjectiveDemonym