وحدة:Wikidata2/tax

من ويكيبيديا، الموسوعه الحره

يمكن إنشاء صفحة توثيق الوحدة في وحدة:Wikidata2/tax/شرح

-- This module implements [[template:تصنيف كائن/تصنيف علمي ويكي بيانات]].

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

local Cash2 = {}
local colors = {
	['Q808'] = '#dfc3e8',	 -- فيروس
	['Q10872'] = '#e6d3d3',	-- عتائق
	['Q10876'] = '#d3e0dd',	-- بكتيريا
	['Q10892'] = '#e6dfa3',	-- طلائعيات
	['Q862296'] = '#c8e8a7',  -- اسناخ 
	['Q756'] = '#bae0ba',	-- نبات
	['Q764'] = '#d0eef7', -- فطر
	['Q729'] = '#ebebbc', -- حيوان
	['Q855740'] = '#e2d5f2',	--جذراوات
	['Q1205126'] = '#ebdcbe',	-- قمعيات 
	['Q473809'] = '#f7d1b5',	--متموريات
	--[''] = '#f0e0d1',	  -- غير محدد	
	[''] = '',
}

local taxP105= {
	['Q7432'] = 'نوع',
	['Q34740'] = 'جنس',
	['Q68947'] = 'نويع',
	['Q35409'] = 'فصيله',
	['Q767728'] = 'ضرب',
	['Q2455704'] = 'فصيلات',
	['Q22666877'] = 'فوق النطاق [[تصنيف:صفحات بها بيانات ويكي بيانات|P105]]',
	['Q227936'] = 'قبيله',
	['Q3238261'] = 'جنيس',
	['Q3181348'] = 'قسم',
	['Q36602'] = 'رتبه',
	['Q2136103'] = 'فصيله عليا',
	['Q3965313'] = 'عميره',
	['Q5867959'] = 'رتيبه',
	['Q37517'] = 'طائفه',
	['Q279749'] = 'شكل',
	['Q3025161'] = 'سلسله',
	['Q5998839'] = 'قسيم',
	['Q5867051'] = 'طويئفه',
	['Q2889003'] = 'تحت رتبه',
	['Q5868144'] = 'رتبه عليا',
	['Q4886'] = 'مستنبت نباتى',
	['Q38348'] = 'شعبه',
	['Q3825509'] = 'شكل خاص',
	['Q1153785'] = 'شعيبه',
	['Q334460'] = 'شعبه',
	['Q4150646'] = 'مجموعه',
	['Q2007442'] = 'صنيف فرعي',
	['Q14817220'] = 'قبيله عليا',
	['Q10861426'] = 'قسم',
	['Q3504061'] = 'عماره',
	['Q3491997'] = 'كتيبه',
	['Q855769'] = 'سلاله',
	['Q3978005'] = 'شعبه عليا',
	['Q2752679'] = 'عويلم',
	['Q6311258'] = 'رتبه صغرى',
	['Q13198444'] = 'السلسليه',
	['Q36732'] = 'مملكه',
	['Q21559275'] = 'فوق القسم',
	['Q2361851'] = 'شعبه فرعيه',
	['Q2981883'] = 'اترابيه',
	['Q10861375'] = 'قسيم',
	['Q3150876'] = 'مملكه فرعيه',
	['Q630771'] = 'ضريب',
	['Q6541077'] = 'اباشه',
	['Q21074316'] = 'رتبه متوسطه',
	['Q6054425'] = 'اترابيه عليا',
	['Q42621'] = 'تهجين الاحياء',
	['Q6054237'] = 'رتبه ضخمه',
	['Q6462265'] = 'رتبه كبرى',
	['Q7506274'] = 'رتبه متوسطه',
	['Q10296147'] = 'فصيله إضافيه',
	['Q19858692'] = 'مملكه عليا',
	['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
	---------------------------
	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
	coo = taxcolours2( value_id , options)
	lll = formatEntityId( value_id , options ).value
	return gettax( value_id , coo ,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] ,"#f7f7f7", "test" , frame.args) 
end

return p