વિભાગ:પરિવારો

વિકિકોશમાંથી

This module is used to retrieve and manage Wiktionary's various language families and the information associated with them. See વિક્શનરી:પરિવારો for more information.

This module provides access to other modules. To access the information from within a template, see Module:પરિવારો/ઢાંચાઓ.

The information itself is stored in Module:પરિવારો/આંકડા. This module should not be used directly by any other module, the data should only be accessed through the functions provided by Module:families.

Finding and retrieving families[ફેરફાર કરો]

The module exports a number of functions that are used to find families.

getFamilyByCode[ફેરફાર કરો]

getFamilyByCode(code)

Finds the family whose code matches the one provided. If it exists, it returns a Family object representing the family. Otherwise, it returns nil.

Family objects[ફેરફાર કરો]

A Family object is returned from one of the functions above. It is a Lua representation of a family and the data associated with it. It has a number of methods that can be called on it, using the : syntax. For example:

local m_families = require("Module:પરિવારો")
local fam = m_families.getFamilyByCode("ine")
local name = lang:getCanonicalName()
-- "name" will now be "Indo-European"

Family:getCode[ફેરફાર કરો]

:getCode()

Returns the family code of the family. Example: "ine" for the Indo-European languages.

Family:getCanonicalName[ફેરફાર કરો]

:getCanonicalName()

Returns the canonical name of the family. This is the name used to represent that language family on Wiktionary, and is guaranteed to be unique to that family alone. Example: "Indo-European" for the Indo-European languages.

Family:getAllNames[ફેરફાર કરો]

:getAllNames()

Returns a table of all names that the family is known by, including the canonical name. The names are not guaranteed to be unique, sometimes more than one family is known by the same name. Example: {"Slavic", "Slavonic"} for the Slavic languages.

Family:getFamily[ફેરફાર કરો]

:getFamily()

Returns a Family object for the parent family that the family is a part of.

Family:getCategoryName[ફેરફાર કરો]

:getCategoryName()

Returns the name of the main category of that family. Example: "Germanic languages" for the Germanic languages, whose category is at શ્રેણી:જાર્મનિક ભાષાઓ.


local export = {}

local Family = {}

function Family:getRawData()
    return self._rawData
end

function Family:getCode()
    return self._code
end

function Family:getCanonicalName()
    return self._rawData.names[1]
end

function Family:getAllNames()
    return self._rawData.names
end

function Family:getFamily()
	return export.getFamilyByCode(self._rawData.family)
end

function Family:getCategoryName()
	local name = self._rawData.names[1]
	
	-- If the name already has "languages" in it, don't add it.
	if name:find("[Ll]anguages$") then
		return name
	else
		return name .. " languages"
	end
end

Family.__index = Family

--[[	The object cache implements memoisation, and is used to avoid duplication
		of objects. If you request the same family code twice, you should also get
		the same object twice, not two different objects with identical data.
		It might also speed things up a bit.	--]]
local object_cache = {}

function export.getFamilyByCode(code)
	if object_cache[code] then
		return object_cache[code]
	end
	
    local rawData = mw.loadData("Module:પરિવારો/આંકડા")[code]
    
    if rawData then
    	local object = setmetatable({ _rawData = rawData, _code = code }, Family)
    	object_cache[code] = object
        return object
    else
        return nil
    end
end

return export