Modül:aile ağacı

Merhaba, buraya Modül:aile ağacı kelimesinin anlamını aramaya geldiniz. DICTIOUS'da Modül:aile ağacı kelimesinin tüm sözlük anlamlarını bulmakla kalmayacak, aynı zamanda etimolojisini, özelliklerini ve Modül:aile ağacı kelimesinin tekil ve çoğul olarak nasıl söylendiğini de öğreneceksiniz. Modül:aile ağacı kelimesi hakkında bilmeniz gereken her şey burada. Modül:aile ağacı kelimesinin tanımı, konuşurken veya metinlerinizi yazarken daha kesin ve doğru olmanıza yardımcı olacaktır. XXX'in ve diğer kelimelerin tanımını bilmek, kelime dağarcığınızı zenginleştirir ve size daha fazla ve daha iyi dilsel kaynaklar sağlar.
Modül belgelemesi

Bu modül Türkçe Vikisözlük'te bulunan Modül:diller, Modül:aileler, Modül:köken dilleri modüllerindeki verilerden yararlanarak bir dilin aile ağacını oluşturmak için kullanılır.

{{#invoke:aile ağacı|goster|dil kodu}}

  • İlk parametre dil kodudur.
  • |aile=1 (veya |2=) parametresini kullanırsanız proto diller, ailelerinden ayrı görünür. Standart olarak proto diller görünür, aileler görünmez.
  • |köken=1 (veya |3=) tüm köken dillerini gösteren parametredir. (bir "ebeveyn" dilin altında veya bir ailenin altında). Normalde gösterilmezler.
  • |protoailealtında=1 proto dilleri ailelerinin altlarında göstermek için kullanılır, ya da |aileprotoaltında=1 parametresi tam tersini yapmak için kullanılabilir.
  • |gizlenmiş=1 tüm ağacı gizlenmiş bir biçimde kullanmak içindir.


--[=[

Yazanlar: ], ], ], ]

--]=]

local p = {}

local regular_languages = require("Modül:diller/tümveri")
local families = require("Modül:aileler/veri")

-- Version of ] that chooses the language-
-- codiest code of several codes that have the same data. For instance,
-- it chooses "de-AT" over "Austrian German".
local etymology_languages = require("Modül:aile ağacı/köken dilleri")

local Array = require("Modül:dizi")

function p.find_subtree(t, code)
	for _, val in ipairs(t) do
		if val.ad == code then -- "name" is really code
			return { val }
		else
			local result = p.find_subtree(val, code)
			if result then
				return result
			end
		end
	end
end

local family_icon = "A"
local etymology_language_icon = "K"
local proto_language_icon = family_icon
local family_with_proto_language_icon = family_icon
local function format_node(code, is_protolanguage_or_has_protolanguage)
	local canonical_name, category_name, class, icon, tooltip
	if regular_languages then
		canonical_name = regular_languages 
		category_name = canonical_name
		class = "familytree-lang"
		if is_protolanguage_or_has_protolanguage then
			class = class .. ' familytree-protolang'
			icon = proto_language_icon
		end
	elseif etymology_languages then
		canonical_name = etymology_languages.asilAd
		class = "familytree-etymlang"
		icon = etymology_language_icon
		tooltip = "Köken dili"
	elseif families then
		canonical_name = families.asilAd
		category_name = canonical_name .. " dilleri"
		class = "familytree-family"
		if is_protolanguage_or_has_protolanguage then
			class = class .. ' familytree-hasprotolang'
			icon = family_with_proto_language_icon
		else
			icon = family_icon
		end
		tooltip = "Dil ailesi"
	end
	
	return '<span class="' .. class .. '" '
		.. (tooltip and 'title="' .. tooltip .. '"' or '') .. '>'
		.. '[[:Kategori:' .. (category_name or canonical_name) .. '|'
		.. canonical_name
		.. ' <span class="familytree-code">(' .. code .. ')</span>]]'
		.. (icon and ' <span class="familytree-icon">' .. icon .. '</span>' or '')
		.. '</span>'
end

-- If neither options.show_all_families or options.show_etymology_languages is
-- falsy, then this function does nothing.
local function filter_nested_data(nested_data, options, protolanguage_of, is_protolanguage)
	if not nested_data then -- ???
		return nil
	else
		local ad = nested_data.ad
		local first_child = nested_data
		
		-- This indicates that new_nested_data below should only be returned
		-- if it contains non-etymology languages.
		local check_for_non_etymology_children = false
		
		-- If `show_all_families` is false and this is a family and its only
		-- child is its proto-language, then replace the family with the
		-- proto-language.
		if options.hide_families_with_protolanguages and ad and families
		and first_child and not nested_data
		and protolanguage_of == first_child.ad then
			is_protolanguage = true
			return filter_nested_data(first_child, options, protolanguage_of, is_protolanguage)
		
		elseif options.hide_etymology_languages
		and etymology_languages then
			if nested_data then
				check_for_non_etymology_children = true
			else
				return nil
			end
		end
		
		local new_nested_data = { ad = ad }
		local i = 0
		for _, subtable in ipairs(nested_data) do
			subtable = filter_nested_data(subtable, options, protolanguage_of, is_protolanguage)
			if subtable then
				i = i + 1
				new_nested_data = subtable
			end
		end
		
		if not check_for_non_etymology_children or new_nested_data then
			return new_nested_data
		end
	end
end

local function make_node(code, is_protolanguage, protolanguage_of)
	return '</span> ' .. format_node(code,
		is_protolanguage or protolanguage_of ~= nil)
end

local function only_child_is_protolanguage(tree, options, protolanguage_of)
	return (options.family_under_protolanguage
		or options.protolanguage_under_family)
		and tree and protolanguage_of == tree.ad
end

p.are_all_children_etymology_languages = require "Modül:işlev".memoize(function (nested_data)
	if not nested_data then
		return nil
	end
	
	for _, child in ipairs(nested_data) do
		if not etymology_languages
		or p.are_all_children_etymology_languages(child) == false then
			return false
		end
	end
	
	return true
end)

local customcollapsible_id = 0
local no_break_space = "&nbsp;"
local level_separator = (no_break_space):rep(3)
local expandtext, collapsetext = "─", "┬"
local function make_tree(data, is_protolanguage, protolanguage_of, options, prefix)
	local result = Array()
	
	-- This tag is closed in the node generated by make_node.
	prefix = prefix or '<span class="familytree-linedrawing">'
	
	local branch = "├"
	local next_level = prefix .. "│" .. level_separator
	local length = #data
	for i, val in ipairs(data) do
		if i == length then
			branch = "└"
			next_level = prefix .. level_separator .. no_break_space
		end
		
		local code = val.ad
		local language_or_family_node =
			make_node(code, is_protolanguage, protolanguage_of)
		
		if not val then
			result:insert('<li>' .. prefix .. branch .. options.sterile_branch_text
				.. language_or_family_node .. '</li>')
		else
			customcollapsible_id = customcollapsible_id + 1
			
			result:insert('<li>' .. prefix .. branch
				.. '<span class="familytree-toggle mw-customtoggle-familytree'
				.. customcollapsible_id .. '">───┬</span>')
			
			-- name me!
			local flag = (options.family_under_protolanguage
				or options.protolanguage_under_family)
				and only_child_is_protolanguage(val, options, protolanguage_of)
			
			local top_node
			if flag then
				code = val.ad
				val = val
				
				top_node = make_node(code, is_protolanguage, protolanguage_of)
				if options.protolanguage_under_family then
					top_node, language_or_family_node =
						language_or_family_node, top_node
				end
			end
				
			local all_children_are_etymology_languages =
				p.are_all_children_etymology_languages(val)
			
			local collapsible_ul = '<ul class="mw-collapsible'
				.. (all_children_are_etymology_languages
					and ' familytree-only-etym-children'
					or '') .. '" '
				.. 'id="mw-customcollapsible-familytree' .. customcollapsible_id
				.. '" data-expandtext="' .. expandtext
				.. '" data-collapsetext="' .. collapsetext .. '">'
			
			if flag then
				result:insert(top_node
					.. collapsible_ul .. '<li>' .. prefix
					.. (i == length and no_break_space or "│")
					.. level_separator .. "│")
			end
			
			result:insert(language_or_family_node)
			
			if not flag then
				result:insert(collapsible_ul)
			end
			
			-- Can't get default collapsibility script to apply the data-expandtext
			-- and data-collapsetext attribute values to the custom toggle,
			-- so have to have a custom script do it.
			result:insert(make_tree(val, is_protolanguage, protolanguage_of, options, next_level))
			result:insert('</ul></li>')
		end
	end
	return result:concat()
end

local function get_number_parameter_in_range(args, arg, low, high)
	local val = args
	
	if val == "" or val == nil then
		val = nil
	else
		val = tonumber(val)
		if not (type(val) == "number"
		and 0 <= val and val <= 6) then
			error("Expected nothing or number between " .. low .. " and "
				.. high .. " in parameter |" .. arg .. "=.")
		end
	end
	
	return val
end

function p.goster(frame)
	local args = frame.args
	
	local descendants_of = args
	if descendants_of == "" then
		descendants_of = nil
	elseif not (regular_languages or families) then
		error("The language code " .. descendants_of
			.. " is not a valid non-etymology language or family.")
	end
	
	local to_boolean = require("Modül:yesno")
	
	-- Determines whether families that have proto-languages will be shown.
	local show_all_families = to_boolean(args or args.aile)
	
	-- Determines whether all etymology languages will be shown.
	local show_etymology_languages = to_boolean(args or args)
	
	-- help! parameter name too long!
	local sterile_branch_length = get_number_parameter_in_range(args, "sterile_branch_length", 0, 6)
	
	-- Determines whether (if all families are shown) a family will be shown
	-- on a line directly under and at the same level as its proto-language,
	-- or the proto-language on a line directly under and at the same level as
	-- its family.
	local family_under_protolanguage = to_boolean(args)
	local protolanguage_under_family = to_boolean(args)
	if family_under_protolanguage and protolanguage_under_family then
		error("Kindly choose between proto-language under family and family under proto-language.")
	end
	
	return p.print_children(descendants_of, {
		hide_families_with_protolanguages = not show_all_families,
		hide_etymology_languages = not show_etymology_languages,
		family_under_protolanguage = family_under_protolanguage,
		protolanguage_under_family = protolanguage_under_family,
		sterile_branch_length = sterile_branch_length,
		collapsed = require("Modül:yesno")(args)
	})
end

function p.print_children(descendants_of, options)
	local data = require("Modül:aile ağacı/toplanmış veri")
	local nested_data, protolanguage_of = data.nested, data.protolanguage_of
	
	if descendants_of then
		nested_data = p.find_subtree(nested_data, descendants_of)
	end
	
	-- Return nil instead of a tree with only the root node.
	if options.must_have_descendants and (#nested_data == 0 or nested_data and #nested_data == 0) then
		return nil
	end
	
	local is_protolanguage = {}
	if options.hide_families_with_protolanguages or options.hide_etymology_languages then
		nested_data = filter_nested_data(nested_data, {
			hide_families_with_protolanguages = options.hide_families_with_protolanguages,
			hide_etymology_languages = options.hide_etymology_languages,
		}, protolanguage_of, is_protolanguage)
	end
	
	if not nested_data or not next(nested_data) then
		return nil
	end
	
	local result = Array('<div class="familytree"><ul>')
	
	local tree_options = {
		sterile_branch_text = '<span class="familytree-branch">'
			.. ("─"):rep(options.sterile_branch_length or 4)
			.. '</span>',
		family_under_protolanguage = options.family_under_protolanguage,
		protolanguage_under_family = options.protolanguage_under_family,
	}
	
	local collapsetext, expandtext = 'Gizle', 'Göster'
	for i, subtable in ipairs(nested_data) do
		-- top language name
		result:insert('<li>')
		
		-- name me!
		local flag = (options.family_under_protolanguage
			or options.protolanguage_under_family)
			and only_child_is_protolanguage(subtable, options, protolanguage_of)
		local top_node = format_node(subtable.ad)
		local next_node
		
		if flag then
			subtable = subtable
			next_node = format_node(subtable.ad)
			if options.family_under_protolanguage then
				top_node, next_node = next_node, top_node
			end
		end
		
		result:insert(top_node)
		
		-- top toggle
		customcollapsible_id = customcollapsible_id + 1
		result:insert('<span class="familytree-toptoggle mw-customtoggle-familytree'
				.. customcollapsible_id .. '" style="display: none;">')
		result:insert(options.collapsed and expandtext or collapsetext)
		result:insert('</span>')
		
		if flag then
			result:insert('<li>')
			result:insert(next_node)
		end
		
		-- tree
		result:insert('<ul class="mw-collapsible')
		if options.collapsed then
			result:insert(' mw-collapsed')
		end
		result:insert('" id="mw-customcollapsible-familytree' .. customcollapsible_id)
		result:insert('" data-expandtext="' .. expandtext)
		result:insert('" data-collapsetext="' .. collapsetext .. '">')
		result:insert(make_tree(subtable, is_protolanguage, protolanguage_of, tree_options, nil))
		if flag then
			result:insert('</li>')
		end
		result:insert('</ul></li>')
	end
	
	result:insert('</ul></div>')
	result:insert(require("Module:TemplateStyles")("MediaWiki:Z_wikistyles.css"))
	
	return result:concat()
end

-- Mainly for testing.
function p.list_descendants_of_frame(frame)
	local parent = frame.args
	if not parent then
		error("Provide parent code in parameter 1.")
	end
	return table.concat(p.list_descendants_of(parent), "\n")
end

function p.list_descendants_of(parent)
	local subtree = p.find_subtree(require("Modül:aile ağacı/toplanmış veri").nested, parent)
	
	local function gather_descendant_codes(subtree, descendants)
		for _, lang in ipairs(subtree) do
			table.insert(descendants, lang.ad)
			gather_descendant_codes(lang, descendants)
		end
	end
	
	local codes = {}
	gather_descendant_codes(subtree, codes)
	table.sort(codes)
	return codes
end

return p