مۆدیوول:Wikidata2/tax

لە ئینسایکڵۆپیدیای ئازادی ویکیپیدیاوە
بەڵگەدارکردنی مۆدیوول[دروست بکە]
-- This module implements [[template:تصنيف كائن/تصنيف علمي ويكي بيانات]].

local p = {}
local Cash = require('Module:Wikidata2/tax/cash')

local Cash2 = {}
local colors = {
	['Q808'] = '#EE82EE',	 -- فيروس
	['Q10872'] = '#ECD2D2',	-- عتائق
	['Q10876'] = '#D3D3D3',	-- بكتيريا
	['Q10892'] = '#F0E68C',	-- طلائعيات
	['Q862296'] = '#ADEE3F',  -- أسناخ 
	['Q756'] = '#90EE90',	-- نبات
	['Q764'] = '#ADD8E6', -- فطر
	['Q729'] = '#D3D3A4', -- حيوان
	['Q855740'] = '#E1CCFC',	--جذراوات
	['Q1205126'] = '#E0D0B0',	-- قمعيات 
	['Q473809'] = '#FFC8A0',	--متموريات
	--[''] = '#FAF0E6',	  -- غير محدد	
	[''] = '',
}


local taxP105= {
	--[''] = 'النطاق',
	['Q22666877'] = 'فوق النطاق',
	['Q19858692'] = 'مملكة عليا',
	['Q36732'] = '[[مملكة (تصنيف)|مملكة]]',
	['Q38348'] = '[[شعبة (تصنيف)|شعبة]]',
	['Q37517'] = '[[طائفة (تصنيف)|طائفة]]',
	['Q36602'] = '[[رتبة (تصنيف)|رتبة]]',
	['Q35409'] = '[[فصيلة (تصنيف)|فصيلة]]',
	['Q34740'] = '[[جنس (تصنيف)|جنس]]',
	['Q7432'] = 'نوع',
	['Q2752679'] = 'عويلم',
	['Q3150876'] = 'مملكة فرعية',
	['Q3978005'] = '[[شعبة عليا (تصنيف)|شعبة عليا]]',
	['Q334460'] = 'شعبة',
	
	['Q1153785'] = '[[شعيبة (تصنيف)|شعيبة]]',
	['Q2361851'] = 'شعبة فرعية',
	['Q3504061'] = 'عمارة',
	['Q5867051'] = '[[طويئفة (تصنيف)|طويئفة]]',
	['Q2007442'] = 'صُنيف فرعي',
	['Q6054237'] = 'رتبة ضخمة',
	['Q5868144'] = '[[رتبة عليا (تصنيف)|رتبة عليا]]',
	['Q6462265'] = 'رتبة كبرى',
	['Q21074316'] = 'رتبة متوسطة',
	['Q7506274'] = 'رتبة متوسطة',
	['Q6311258'] = 'رتبة صغرى',
	['Q2889003'] = '[[تحت رتبة (تصنيف)|تحت رتبة]]',
	['Q5867959'] = '[[رتيبة (تصنيف)|رتيبة]]',
	['Q164280'] = '[[فصيلات (تصنيف)|فُصيلة]]',
	['Q2455704'] = '[[فصيلات (تصنيف)|فُصيلة]]',
	['Q68947'] = 'نويع',
	['Q2136103'] = '[[فصيلة عليا (تصنيف)|فصيلة عليا]]',
	['Q10296147'] = 'فصيلة إضافية',
	['Q767728'] = 'ضرب',
	['Q227936'] = '[[قبيلة (تصنيف)|قبيلة]]',
	['Q3238261'] = 'جُنيس',
	['Q3181348'] = 'قسم',
	['Q3965313'] = 'عميرة',
	['Q279749'] = 'شكل',
	['Q3025161'] = 'سلسلة',
	['Q5998839'] = 'قسيم',
	['Q4886'] = 'مستنبت نباتي',
	['Q3825509'] = 'شكل خاص',
	['Q4150646'] = 'مجموعة',
	['Q14817220'] = 'قبيلة عليا',
	['Q10861426'] = 'قسم',
	['Q3491997'] = 'كتيبة',
	['Q855769'] = 'سلالة',
	['Q13198444'] = 'السلسلية',
	['Q21559275'] = 'فوق القسم',
	['Q2981883'] = '[[أترابية (تصنيف)|أترابية]]',
	['Q10861375'] = 'قسيم',
	['Q630771'] = 'ضُريب',
	['Q6541077'] = '[[أباشة (تصنيف)|أباشة]]',
	['Q6054425'] = 'أترابية عليا',
	['Q42621'] = 'تهجين الأحياء',
	['Q4226087'] = 'أترابية فرعية',
	['Q26857882'] = 'المملكة الصغرى',
	['Q3798630'] = 'قبيلة فرعية',
	['Q3491996'] = 'نطاق فرعي',
 }
 
function add_Tracking_Category(prop,options)
	return addTrackingCategory(prop,options)
	--return prop
end

function foo(iid,formatting,p)
	if not iid or iid ==''  then return nil end
	so = nil
	st = formatStatements( {property = p , entityId = iid, enlabelcate='t', noref ='t', firstvalue='true',formatting=formatting})
	if st and st ~= '' then
		so = st
	end
	----------------
	return so
end

function GetP171id( id )
	if not id or id ==''  then return nil end
	----------------
	if Cash[id] and Cash[id]["P171"] and Cash[id]["P171"] ~= ""
	then
	    st = Cash[id]["P171"]
	else
	    st = formatStatements( {property ='P171' , entityId = id,rank='best', noref ='t', firstvalue='true',formatting="raw"})
		if not Cash2[id] then Cash2[id] = {} end
		if st and st ~= "" then 
		   Cash2[id]["P171"] = st
		end
	end
	return st
end

function taxcolours2( id , options)
	--local id = GetP171id( id )
	i = 0
	ccc = ""
	while ccc == "" and i < 30 do
		e = foo( id , "raw" , 'P105')
		if e and e ~= ''  then 
			if e == 'Q36732'  then
				if colors[id] and colors[id] ~= "" then
					ccc = colors[id]
				end
			end
		end
		id = GetP171id( id )
		i = i + 1
	end
	---------------------------
	if ccc == "" and options.colour and options.colour ~= "" 
	then 
		ccc = options.colour
	end
	---------------------------
	return ccc
	---------------------------
end

function taxonrank(iid)
	vvv = nil
	if not iid or iid ==''  then return nil end
	------------------------
	local rank_raw;
	local rank_lab;
	if Cash[iid] and Cash[iid]["P105"] and Cash[iid]["P105"] ~= "" then
	    rank_raw = Cash[iid]["P105"]
	else
	    rank_raw = formatStatements( {property ='P105' , entityId = iid, enlabelcate='t', noref ='t', firstvalue='true',formatting='raw'})
		if not Cash2[iid] then Cash2[iid] = {} end
		Cash2[iid]["P105"] = rank_raw
	end
	if not rank_raw or rank_raw ==''  then return nil end
	------------------------
	if taxP105[rank_raw] and taxP105[rank_raw] ~= "" then
		vvv = add_Tracking_Category(taxP105[rank_raw] ,{property='P105', entityId = iid,noicon='t'}) 
	else
		rank_lab = formatStatements( {property ='P105' , entityId = iid, enlabelcate='t', noref ='t', firstvalue='true',formatting=''})
		if rank_lab and rank_lab ~= ''  then  
			mw.log("Module:Wikidata2/tax: taxP105['" .. rank_raw ..  "'] = '" .. rank_lab .. "'" )
			vvv = add_Tracking_Category(rank_lab .. '' ,{property='P105', entityId = iid,noicon='t'}) 
		end
	end
	------------------------
	return vvv
end

function pro1(id)
	if not id or id ==''  then return nil end
	----------------
    id_r = formatStatements( {property ='P171' , entityId = id, enlabelcate='t', noref ='t', firstvalue='true',formatting='raw'})
	if id_r and id_r ~= "" then 
      if Cash[id_r] and Cash[id_r]["label"] and Cash[id_r]["label"] ~= "" 
      then
	      label = Cash[id_r]["label"]
	  else
	      label = formatStatements( {property ='P171' , entityId = id,enlabelcate='t',noref ='e', firstvalue='true'})
		  if not Cash2[id_r] then Cash2[id_r] = {} end
		  if label and label ~= "" then  Cash2[id_r]["label"] = label end
		end
	end
	return label
end

function dd(id, taxo_id )
	-- taxolabel : الكائن
	-- d : المرتبة التصنيفية
	if id and id ~= '' then 
		taxolabel = pro1( taxo_id )
		d = taxonrank(id)		   -- المرتبة التصنيفية
		----------------
		if not d or d == ''  then
			--d = foo( id , '' , 'P31' )
			--mw.log( "Module:Wikidata2/tax: foo[" .. id .. "] = " .. d)
			return nil 
		end
		----------------
		if taxolabel and taxolabel ~= '' then
			if d and d ~= '' 
				then 
					return	 d .. '||'..  taxolabel
				else 
					return taxolabel 
			end
		end
	end
end

function dd_old(id, taxolabel )
	-- taxolabel : الكائن
	-- d : المرتبة التصنيفية
	if id and id ~= '' then 
		d = taxonrank(id)		   -- المرتبة التصنيفية
		----------------
		if not d or d == '' 
			then return nil --'' -- nil 
		end
		----------------
		if taxolabel and taxolabel ~= '' then
			if d and d ~= '' 
				then 
					return	 d .. '||'..  taxolabel
				else 
					return taxolabel 
			end
		end
	end
end

function gettax( value_id ,coo, lll , options)
    local P = {}
    local number = 1
    local id_1 = value_id
    ----------
    P[0]    =   dd_old(value_id , lll )	
    ----------
    while number < 31 do
           s_id = GetP171id( id_1 )
           P[number] = dd(s_id ,  id_1 )
           id_1 = s_id
          number = number + 1
    end
	
	------------------------
	for k, v in pairs(Cash2) do
		if (v["P171"] and v["P171"] ~= "")  and ( v["P105"] and v["P105"] ~= "") then
			mw.log(  "Module:Wikidata2/tax: Cash['" .. k .. "']= {['P105'] = '" ..( v["P105"] or "" ).. "' , ['P171'] =  '" ..  (v["P171"] or "") .. "' , ['label'] =  '" ..  (v["label"] or "") .. "' }" )
		end
	end
	----------------
	ti =  '[[التصنيف العلمي]]'
	title =	 'colspan=\"2\" style=\"text-align: center;background-color:' ..coo..';" | ' .. add_Tracking_Category(ti ,options)
	
	head = '{| class="infobox biota" style="text-align: right; width: 200px; font-size: 100%%"'
	End = '}'
	----------------
	local taxon1 = {
		P[30]  or "" ,  P[29]  or "" ,  P[28]  or "" ,  
		P[27]  or "" ,  P[26]  or "" ,  P[25]  or "" ,  P[24]  or "" ,  
		P[23]  or "" ,  P[22]  or "" ,  P[21]  or "" ,  P[20]  or "" ,  
		P[19]  or "" ,  P[18]  or "" ,  P[17]  or "" ,  P[16]  or "" ,  
		P[15]  or "" ,  P[14]  or "" ,  P[13]  or "" ,  P[12]  or "" ,  
		P[11]  or "" ,  P[10]  or "" ,  P[9]  or "" ,  P[8]  or "" ,  
		P[7]  or ""   ,  P[6]  or ""   ,  P[5]  or "" ,  P[4]  or "" ,  
		P[3]  or ""   ,  P[2]  or ""   ,  P[1]  or "" ,  P[0]  or "" ,  
		}
	----------------
	local q = {}
	--table.insert( q,head	) 
	table.insert( q, title	)
	for i,j in ipairs( taxon1 ) do
		e = i..j
		if j and j ~= '' 
			then table.insert( q,j ) 
		end
	end	 
	----------------
	--table.insert( q,End	) 
	taxonSections = table.concat( q, "\n|-\n|")
	result = string.format([[%s
|-
!%s
|-
|%s
%s]], head, title, taxonSections, End )
	----------------

	return taxonSections --result
end

function p.tax( datavalue ,datatype , options)
	local value_id =   datavalue.value.id
	local colour = taxcolours2( value_id , options)
	local lll = formatEntityId( value_id , options ).value
	return gettax( value_id , colour ,lll, options)
end

function p.taxcolour( datavalue ,datatype , options)
   --return taxcolours(datavalue.value.id, options)
   return taxcolours2(datavalue.value.id, options)
end

function p.gg(frame)
	return gettax( frame.args[1] ,"#ffffff", "test" , frame.args) 
end

return p