Saltu al enhavo

Modulo:AutoDescriptionState

El Vikinovaĵoj, libera retgazeto

Dokumentado por ĉi tiu modulo povas esti kreata ĉe Modulo:AutoDescriptionState/dokumentado

--[[
------------------------------------------
--             AutoDescriptionState
-- Modulo por plenigi kategoriojn de ŝtatoj. 
------------------------------------------
--]]

local Dates = require("Modulo:Dates")
local Declension = require("Modulo:Declension")
local Langs = require("Modulo:Langs")
local MathTonumber = require("Modulo:Math/tonumber")
local ReturnGendered = require("Modulo:ReturnGendered")
local SerializeTable = require("Modulo:SerializeTable")
local Math = require("Modulo:Math")

local AutoDescriptionState={}

-- Нам необходимо сформировать и вернуть три переменных
local description = "" -- уточнение (то, что в скобочках после имени, например, на языке оригинала, годы жизни и т.п.)
local details = "" -- строка описания
local categories = "[[Kategorio:Ŝtatoj laŭ alfabeto]]" -- категории

-- Промежуточный масив сущностей, в который помещаются результаты парсинга перед формированием описания
local entitiesArray = {P21 = "", P39 = "", P69 = "", P101 = {}, P101Q ="", P108 = "", P108Q = "", 
 P166="", P184="", P185="", P463 = {}, P463Q = "", P509 = "", P512 = "", P551="", P571 = "", 
 P576 = "", P800="", P802="", P1196="", P1344="",
 erdosNumber = "", male = "", female = "", langName="", nativeName="", 
 placeOfBirth="", countryOfBirth="", placeOfDeath="", countryOfDeath="", 
 occupations = "", dayB="", monthB="", yearB="", dayD="", monthD="", yearD="", 
 occupation={}, idOccupation={}, upOccupation={}, citizenship={}, employer={}, 
 influencedBy={}, edu={}, eduStart={}, eduEnd={}, docAdvisor={}, docStud={}, stu={}, 
 pup={}, moth="", father="", residence={}, residenceEnd={}, 
 residenceSt={}, sibling={}, award={}, awardPIT={}, awardTW={}, awardPM={}, participantOf={}, 
 notableWork={}, workLocation={}, academicDegree={}, academicDegreeDate={}, academicDegreeF={}, 
 academicDegreeEdu={}, positionHeld={},positionHeldStart={},positionHeldEnd={},positionHeldPG={},
 positionHeldPT={},positionHeldReplace={},positionHeldReplaceBy={}}

-- Точка входа
function AutoDescriptionState.launch(entity)
 local successLaunchParsing, errCodeParsing, successLaunchForming, errCodeForming -- Признак успешного завершения и сообщения об ошибке парсинга и форминга соответственно
 successLaunchParsing, errCodeParsing = pcall(function() AutoDescriptionState.parsing(entity) end) -- Парсим карточку Викиданных, тестируя функцию парсинга на ошибки.
 if successLaunchParsing then successLaunchForming, errCodeForming = pcall(function() AutoDescriptionState.forming() end) end -- формируем переменные, тестируя функцию форминга на ошибки
 if not successLaunchParsing or not successLaunchForming then
  categories = categories .. "[[Kategorio:Paĝoj kun eraro en modulo]][[Kategorio:Paĝoj kun eraro en modulo AutoDescriptionState]]"
  if errCodeParsing then categories = categories .. "[[Kategorio:Paĝoj kun eraro:" .. errCodeParsing .. "]]" end
  if errCodeForming then categories = categories .. "[[Kategorio:Paĝoj kun eraro:" .. errCodeForming .. "]]" end
 end
 return details, description, categories
end	

-- Последовательно проходим свойства в карточке викиданных, для формирования массива сущностей entitiesArray
function AutoDescriptionState.parsing(entity)
	entitiesArray["P571"]=AutoDescriptionState.parseP571(entity)
	entitiesArray["P576"]=AutoDescriptionState.parseP576(entity)
	AutoDescriptionState.parseP19(entity)
	AutoDescriptionState.parseP20(entity)
	AutoDescriptionState.parseP21(entity)
	AutoDescriptionState.parseP22(entity)
	AutoDescriptionState.parseP25(entity)
	entitiesArray["P39"]=AutoDescriptionState.parseP39(entity)
	entitiesArray["P69"]=AutoDescriptionState.parseP69(entity)
	AutoDescriptionState.parseP101(entity)
	entitiesArray["P106"]=AutoDescriptionState.parseP106(entity)
	AutoDescriptionState.parseP108(entity)
	entitiesArray["P166"]=AutoDescriptionState.parseP166(entity)
	entitiesArray["P184"]=AutoDescriptionState.parseP184(entity)
	entitiesArray["P185"]=AutoDescriptionState.parseP185(entity)
	entitiesArray["P463Q"]=AutoDescriptionState.parseP463(entity)
	entitiesArray["P509"]=AutoDescriptionState.parseP509(entity)
	entitiesArray["P512"]=AutoDescriptionState.parseP512(entity)
	entitiesArray["P551"]=AutoDescriptionState.parseP551(entity)
	entitiesArray["P800"]=AutoDescriptionState.parseP800(entity)
	entitiesArray["P802"]=AutoDescriptionState.parseP802(entity)
	entitiesArray["P1196"]=AutoDescriptionState.parseP1196(entity)
	entitiesArray["P1344"]=AutoDescriptionState.parseP1344(entity)
	entitiesArray["P1705"]=AutoDescriptionState.parseP1705(entity)
	entitiesArray["P2021"]=AutoDescriptionState.parseP2021(entity)
end

function AutoDescriptionState.forming()
 if(entitiesArray.langName ~= "" or entitiesArray["P571"] ~= "" or entitiesArray["P576"] ~= "") then	
   details = details .. "(" 
   if(entitiesArray.langName ~= "") then  details = details ..   Langs.launch(entitiesArray.langName, entitiesArray.nativeName) .. "; " end
   if(entitiesArray["P571"] ~= "" and entitiesArray["P576"] ~= "") then details = details .. "[[" .. entitiesArray["P571"] .. " ]]"	
   elseif (entitiesArray["P571"] ~= "") then details = details .. "fondita en [[" .. entitiesArray["yearB"] .. " ]]"	
   end	
   if(entitiesArray["placeOfBirth"] ~= "") then  details = details .. ", [[" .. entitiesArray["placeOfBirth"] .. "]]" end 
   if(entitiesArray["P571"] ~= "" and entitiesArray["P576"] ~= "") then details = details .. "  — [[" .. entitiesArray["P576"] .. " ]]" 	
   elseif (entitiesArray["P576"] ~= "") then details = details .. "aboligita la [[" .. entitiesArray["P576"] .. " ]]" 
   end
   if(entitiesArray["placeOfDeath"] ~= "") then  details = details .. ",  [[" .. entitiesArray["placeOfDeath"] .. "]]" end
   if(entitiesArray["countryOfDeath"] ~= "") then  details = details .. ", [[" .. entitiesArray["countryOfDeath"] .. "]]" end 
   details = details .. ")"
 end

 if (entitiesArray["occupation"][1] ~= "") then
 	for ki, vi in pairs (entitiesArray.occupation) do
     	if(ki=="1") then 
         if(entitiesArray["P21"] == "vira") then 
          description = description .. vi .. " "
         elseif (ReturnGendered.launch(vi, entitiesArray["P21"], 2) ~= "") then 
          description = description .. ReturnGendered.launch(vi, entitiesArray["P21"], 2) .. " " 
         end
     	else
     		p=true
     		for i=1, (ki-1), 1 do
     			if (entitiesArray.occupation and entitiesArray.occupation[i] and string.find(vi, entitiesArray.occupation[i])) then 
     				p=false
     			end
     		end	
     		if(p~=false) then
     			if(entitiesArray["P21"] == "vira") then description = description ..  "[[" ..  vi .. "]]" .. ", " 
     			else
     			 local rg = ReturnGendered.launch(vi, entitiesArray["P21"], 2)
     			 if (rg ~= nil and rg ~= "") then description = description ..  "[[" .. rg .. "]]" .. ", "  end  
     			end
     		end
     	end	
    end	
    description=description:sub(1, #description - 2)
    description = description .. ". " 
 end
 if (entitiesArray["P101"][1] ~= "" and string.find(entitiesArray.P101Q, "Q")) then
 	description = description .. " <br><b>Okupiĝis pri</b> "
 	for ki, vi in pairs (entitiesArray.P101) do
     	if(Declension.declineWord(vi, 6) ~= "Logical error Declension.declineWord(arg): word not found") then description = description .. "[[" .. vi .. "|" .. Declension.declineWord(vi, 6) .. "]], "   
     	else description = description .. "[[" .. vi ..  "]], " end
    end	
    description=description:sub(1, #description - 2)
    description = description .. ". " 
 end	
 if(entitiesArray["P463Q"] ~= "") then
   description = description .. "<br><b>Lando-membro de:</b> "
   for ki, vi in pairs (entitiesArray.P463) do
  	description = description .. "[[" .. vi ..  "]], "
   end	
   description=description:sub(1, #description - 2)
   description = description .. ". "
 end	
 if(entitiesArray["P69"] == "edu") then 
 	local i=1
 	description = description .. "<br><b>Edukeco:</b> "
 	for ki, vi in pairs (entitiesArray.edu) do
 		description = description .. "[[" .. vi ..  "]]"  
 		if(entitiesArray.eduStart[i] ~= "None") then description = description .. " de " .. "[[" .. entitiesArray.eduStart[i] .. " jaro]]" end
 		if(entitiesArray.eduEnd[i] ~= "None") then description = description .. " ĝis ".. "[[" .. entitiesArray.eduEnd[i] .. " jaro]]" end
 		i=i+1
 		description = description .. ", "
 	end	
    description=description:sub(1, #description - 2)
    description=description..". "
 end
 if(entitiesArray["P512"] == "full") then
 	local len=0
 	for k, v in pairs (entitiesArray.academicDegree) do
 		len=len+1
 	end	
 	if (len>1) then  description = description .. "Sciencaj rangoj: "
 	else description = description .. "<br><b>Scienca rango:</b> " end
 	for k, v in pairs (entitiesArray.academicDegree) do
 		description = description .. v
 		if (entitiesArray.academicDegreeF[k] ~= "None" or entitiesArray.academicDegreeDate[k] ~= "None" or entitiesArray.academicDegreeEdu[k] ~= "None") then 
 			description = description .. " ("
 			if(entitiesArray.academicDegreeDate[k] ~= "None") then 
 				description = description .. "[[" .. entitiesArray.academicDegreeDate[k] .. " jaro]]"
 				if(entitiesArray.academicDegreeF[k] ~= "None") then description = description .. "; [[" .. entitiesArray.academicDegreeF[k] .. "]]"	end
 				if(entitiesArray.academicDegreeEdu[k] ~= "None") then description = description .. "; [[" .. entitiesArray.academicDegreeEdu[k] .. "]]"	end
 			elseif(entitiesArray.academicDegreeF[k] ~= "None") then 	
 				description = description .. "[[" .. entitiesArray.academicDegreeF[k] .. "]]"
 				if(entitiesArray.academicDegreeEdu[k] ~= "None") then description = description .. "; [[" .. entitiesArray.academicDegreeEdu[k] .. "]]"	end
 			elseif(entitiesArray.academicDegreeEdu[k] ~= "None") then description = description .. "[[" .. entitiesArray.academicDegreeEdu[k] .. "]]"	end
 			description = description .. ")"
 		end	
 		description = description .. ", "
 	end	
    description=description:sub(1, #description - 2)
    description=description..". " 
 end	
 if (entitiesArray["employer"][1] ~= "" and string.find(entitiesArray.P108Q, "Q")) then
 	description = description .. "<br><b>Laborloko:</b> "
 	for ki, vi in pairs (entitiesArray.employer) do
 		description = description .. "[[" .. vi ..  "]], " 
    end	
    description=description:sub(1, #description - 2)
    description = description .. ". " 
 end
 if(entitiesArray["P184"] == "full") then
 	description = description .. "<br><b>Scienca gvidanto:</b> "
 	for ki, vi in pairs (entitiesArray.docAdvisor) do
 		description = description .. "[[" .. vi ..  "]], "
 	end	
    description=description:sub(1, #description - 2)
    description=description..". "
 end	
 if(entitiesArray["P185"] == "full") then
 	local len = 0
 	for ki, vi in pairs (entitiesArray.docStud) do
 		len=ki
 	end	
 	if(len>1) then  description = description .. "Postdiplomaj studanтoj: "
    else description = description .. "Postdiploma studanтo: " end
 	for ki, vi in pairs (entitiesArray.docStud) do
 		description = description .. "[[" .. vi ..  "]], "
 	end	
    description=description:sub(1, #description - 2)
    description=description..". "
 end	
 if(entitiesArray["P802"] == "full") then
 	local len = 0
 	for ki, vi in pairs (entitiesArray.stu) do
 		len=ki
 	end	
 	if(len>1) then  description = description .. "Studantoj: "
    else description = description .. "Studanto: " end
 	for ki, vi in pairs (entitiesArray.stu) do
 		description = description .. "[[" .. vi ..  "]], "
 	end	
    description=description:sub(1, #description - 2)
    description=description..". "
 end	
 if(entitiesArray["moth"] ~= "") then 	description = description .. "<br><b>Patrino:</b> [[" .. entitiesArray["moth"] .. "]]. " end	
 if(entitiesArray["father"] ~= "") then 	description = description .. "<b>Patro:</b> [[" .. entitiesArray["father"] .. "]]. " end	
 if(entitiesArray["P551"] == "full") then
 	local len = 0
 	for k, v in pairs (entitiesArray.residence) do
 		len=len+1
 	end	
 	if(len>1) then  description = description .. "<br><b>Loĝlokoj:</b> "
    else description = description .. "<br><b>Loĝloko:</b> " end
 	for k, v in pairs (entitiesArray.residence) do
 		description = description .. "[[" .. v ..  "]]"
 		if(entitiesArray.residenceSt[k] ~= "NoNe") then description = description .. " de " .. "[[" .. entitiesArray.residenceSt[k] .. " jaro]]" end
 		if(entitiesArray.residenceEnd[k] ~= "NoNe") then description = description .. " ĝis ".. "[[" .. entitiesArray.residenceEnd[k] .. " jaro]]" end
 		description = description .. ", "
 	end	
    description=description:sub(1, #description - 2)
    description=description..". " 
 end	
 if(entitiesArray["P1344"] == "full") then
 	description = description .. "<br><b>Partoprenis en:</b> "
 	for k, v in pairs (entitiesArray.participantOf) do
 		description = description .. "[[" .. v ..  "]], "
 	end	
    description=description:sub(1, #description - 2)
    description=description..". " 
 end	
 if(entitiesArray["P166"] == "full") then
 	description = description .. "<br><b>Premioj kaj honorigoj:</b> "
 	for k, v in pairs (entitiesArray.award) do
 		description = description .. "[[" .. v ..  "]]"
 		if(entitiesArray.awardPIT[k]~="") then description = description .. " ([[" .. entitiesArray.awardPIT[k] .. " jaro]]" end
 		if(entitiesArray.awardTW[k]~="") then description = description .. "; kune kun:" .. entitiesArray.awardTW[k] end
 		if(entitiesArray.awardPM[k]~="") then description = description .. "; premia fonduso: " .. entitiesArray.awardPM[k] end
 		if(entitiesArray.awardPIT[k]~="") then description = description .. ")" end
 		description = description .. ", "
 	end	
    description=description:sub(1, #description - 2)
    description=description..". " 
 end		
 if(entitiesArray["P800"] == "full") then
 	description = description .. "<br><b>Elistaraj verkoj:</b> "  
 	for k, v in pairs (entitiesArray.notableWork) do
 		description = description .. "«[[" .. v ..  "]]», "
 	end	
    description=description:sub(1, #description - 2)
    description=description..". " 
 end	
 if (entitiesArray["P39"] == "full") then
 	local len=0
 	for k, v in pairs (entitiesArray.positionHeld) do
 		len=len+1
 	end	
 	if (len>1) then  description = description .. "<br><b>Okupitaj postenoj:</b> "
 	else description = description .. "<br><b>Okupita posteno:</b> " end	
    for k, v in pairs (entitiesArray.positionHeld) do
    	description = description .. v 
    	if(entitiesArray.positionHeldStart[k] ~= "None") then description = description .. " de [[" .. entitiesArray.positionHeldStart[k] .. " jaro]]" end
    	if(entitiesArray.positionHeldEnd[k] ~= "None") then description = description .. " ĝis [[" .. entitiesArray.positionHeldEnd[k] .. " jaro]]" end
    	if(entitiesArray.positionHeldPG[k] ~= "None" and entitiesArray.positionHeldPG[k] ~= nil) then description = description .. ": «[[" .. entitiesArray.positionHeldPG[k] .. "]]»" end
    	if(entitiesArray.positionHeldReplace[k] ~= "None") then description = description .. " post [[" .. entitiesArray.positionHeldReplace[k] .. "]]" end
    	if(entitiesArray.positionHeldReplaceBy[k] ~= "None") then description = description .. " antaŭ [[" .. entitiesArray.positionHeldReplaceBy[k] .. "]]" end
    	description = description .. "; " 
    end
    description=description:sub(1, #description - 2)
    description=description..". " 
 end	
 
 if(entitiesArray["P571"] ~= "") then 
 	if(entitiesArray["dayB"] ~= nil and (string.find(entitiesArray["monthB"], "senco nekonata") == nil) and entitiesArray["dayB"] ~= "" and entitiesArray["monthB"] ~= "") then categories = categories .. " [[Kategorio:Ŝtatoj, fonditaj en " .. entitiesArray["yearB"] .. "]]"
 	elseif (entitiesArray["monthB"] ~= "") then categories = categories .. " [[Kategorio:Ŝtatoj, fonditaj la " .. Declension.declineWord(entitiesArray.monthB, 1) .. " " .. entitiesArray.yearB .. "]]" end
 end
 if(entitiesArray["P576"] ~= "") then categories = categories .. " [[Kategorio:Ŝtatoj, aboligitaj la " .. entitiesArray["P576"] .. "]]" end
 end 
 if(entitiesArray["dayD"] ~= "" and entitiesArray["dayD"] ~= nil) then categories = categories .. " [[Kategorio:Ŝtatoj, aboligitaj la " .. entitiesArray["dayD"] .. "-a " .. entitiesArray["monthD"] .. "]]" end 
 if(entitiesArray["yearD"] ~= "" and entitiesArray["yearD"] ~= nil) then categories = categories .. " [[Kategorio:Ŝtatoj, aboligitaj en " .. entitiesArray["yearD"] .. "]]" end 
 if(entitiesArray["upOccupation"][1] ~= "") then
   local p=false
   local q=false
   for ki, vi in pairs (entitiesArray.upOccupation) do
     if (vi ~= "bin") then 
 		if(Declension.declineWord(vi, 7) == "Logical error Declension.declineWord(arg): word not found") then 
 			p=true 
 			categories = categories .. "[[Kategorio:Okupo:" .. vi .. "j]]"  
 		else categories = categories .. "[[Kategorio:" .. Declension.declineWord(vi, 7) .. " laŭ alfabeto]]" end
 	    if (Declension.declineWord(entitiesArray["countryOfBirth"], 1) == "Logical error Declension.declineWord(arg): word not found") then q=true
 	    elseif (Declension.declineWord(vi, 7) ~= "Logical error Declension.declineWord(arg): word not found") then categories = categories .. " [[Kategorio:" .. Declension.declineWord(vi, 7) .. " " .. Declension.declineWord(entitiesArray["countryOfBirth"], 1).. "]]" end
 	    if(entitiesArray.yearB ~= "" and Declension.declineWord(vi, 7) ~= "Logical error Declension.declineWord(arg): word not found") then categories = categories .. "[[Kategorio:" .. Declension.declineWord(vi, 7) .. " de " .. Math.roman((entitiesArray.yearB:match('%d%d') + "1")) .. " jarcento]]" end
 	    if(entitiesArray.yearD ~= "" and Declension.declineWord(vi, 7) ~= "Logical error Declension.declineWord(arg): word not found") then categories = categories .. "[[Kategorio:" .. Declension.declineWord(vi, 7) .. " de " .. Math.roman((entitiesArray.yearD:match('%d%d') + "1")) .. " jarcento]]" end 
     end
   end
   if (p == true) then categories = categories .. "[[Kategorio:Profesioj sen deklinacio]]" end
   if (q == true) then categories = categories .. "[[Kategorio:Landoj sen deklinacio]]" end
 end
 if(entitiesArray["P463Q"] ~= "") then
   local p=false
   for ki, vi in pairs (entitiesArray.P463) do
   	if(Declension.declineWord(vi, 2) == "Logical error Declension.declineWord(arg): word not found") then 
   		p=true  
   		categories = categories .. "[[Kategorio:" .. vi .. " (partoprenantoj)]]"
   	else categories = categories .. "[[Kategorio:Partoprenantoj de " .. vi .. "]]" end
   end
   if (p == true) then categories = categories .. "[[Kategorio:Organizaĵoj sen deklinacio]]" end
 end	
 if(entitiesArray["P69"] == "edu") then
   local p=false
   for ki, vi in pairs (entitiesArray.edu) do
   	if(Declension.declineWord(vi, 2) == "Logical error Declension.declineWord(arg): word not found") then 
   		p=true  
   		categories = categories .. "[[Kategorio:Finlernintoj de " .. vi .. "]]" end
   end
 end
 if(entitiesArray["P551"] == "full") then
   local p=false
   for ki, vi in pairs (entitiesArray.residence) do
   	if(Declension.declineWord(vi, 2) == "Logical error Declension.declineWord(arg): word not found") then 
   		p=true  
   		categories = categories .. "[[Kategorio:Loĝloko:" .. vi .. " ]]"
   	else categories = categories .. "[[Kategorio:Loĝantoj " .. Declension.declineWord(vi, 2) .. "]]" end
   end
   if (p == true) then categories = categories .. "[[Kategorio:Urboj sen deklinacio]]" end
 end
 if(entitiesArray["P166"] == "full") then
   local p=false
   for ki, vi in pairs (entitiesArray.award) do
   	if(Declension.declineWord(vi, 2) == "Logical error Declension.declineWord(arg): word not found") then 
   		p=true  
   		categories = categories .. "[[Kategorio:" .. vi .. " (honorigitaj)]]"
   	else categories = categories .. "[[Kategorio:Honorigitaj " .. Declension.declineWord(vi, 2) .. "]]" end
   end
   if (p == true) then categories = categories .. "[[Kategorio:Honorigoj sen deklinacio]]" end
 end
 if(entitiesArray["P1344"] == "full") then
   local p=false
   for ki, vi in pairs (entitiesArray.participantOf) do
   	if(Declension.declineWord(vi, 2) == "Logical error Declension.declineWord(arg): word not found") then 
   		p=true  
   		categories = categories .. "[[Kategorio:" .. vi .. " (partoprenantoj)]]"
   	else categories = categories .. "[[Kategorio:Partoprenantoj de " .. vi .. "]]" end
   end
   if (p == true) then categories = categories .. "[[Kategorio:Aranĝoj sen deklinacio]]" end
 end

function AutoDescriptionState.parseP19(entity)
 	local values=entity:formatPropertyValues("P19",mw.wikibase.entity.claimRanks).value
 	if(values ~= "") then entitiesArray["placeOfBirth"]=values end
 	local q
 	local p19Statements=mw.wikibase.getBestStatements(entity:getId(), 'P19' )
	for ki, vi in pairs (p19Statements) do
		q = vi['mainsnak']['datavalue']['value']['id']
	end
	if q== nil then 
		for ki, vi in pairs (p19Statements) do
		  q = vi['references']['mainsnak']['datavalue']['value']['id']
	    end
	end
 	if(q ~= nil) then local p17Statements=mw.wikibase.getBestStatements(q, 'P17' ) 
 	local i=1	
 	local country=""
 	local year=MathTonumber.integerModule(entitiesArray["yearB"])
	for ki, vi in pairs (p17Statements) do
 	    local start=""
 	    local enD=""
		if (i == 1) then country=mw.wikibase.getLabel(vi['mainsnak']['datavalue']['value']['id']) 
        else
        	if(vi['qualifiers'] ~= nil) then
        		if((vi['qualifiers']['P576'] ~= nil)) then enD=MathTonumber.integerModule(vi['qualifiers']['P576'][1]['datavalue']['value']['time']) end
        		if((vi['qualifiers']['P580'] ~= nil)) then start=MathTonumber.integerModule(vi['qualifiers']['P580'][1]['datavalue']['value']['time']) end
        	else country=mw.wikibase.getLabel(vi['mainsnak']['datavalue']['value']['id']) end
        	if(enD ~= "" and (enD-year)>0) then 
        		if(start ~= "") then
        			if(year-start > 0) then country=mw.wikibase.getLabel(vi['mainsnak']['datavalue']['value']['id']) end
        		else country=mw.wikibase.getLabel(vi['mainsnak']['datavalue']['value']['id']) end	
            end
        end
		i=i+1
	end	
	entitiesArray["countryOfBirth"] = entitiesArray["countryOfBirth"] .. country
	end
	local p19Statements=entity:getAllStatements("P19")
	for ki, vi in pairs (p19Statements) do
		if(vi['qualifiers'] ~= nil and vi['qualifiers']['P17'] ~= nil) then entitiesArray["countryOfBirth"] = mw.wikibase.getLabel(vi['qualifiers']['P17'][1]['datavalue']['value']['id']) end
	end	
end  

function AutoDescriptionState.parseP20(entity)
 	local values=entity:formatPropertyValues("P20",mw.wikibase.entity.claimRanks).value
 	if(values ~= "") then entitiesArray["placeOfDeath"]=values end
 	local q
 	local p20Statements=mw.wikibase.getBestStatements(entity:getId(), 'P20' )
	for ki, vi in pairs (p20Statements) do
		if(vi['mainsnak'] ~= nil and vi['mainsnak']['datavalue'] ~= nil) then 
			q = vi['mainsnak']['datavalue']['value']['id']
		end
	end
	if q== nil then 
		for ki, vi in pairs (p20Statements) do
		  q = vi['references']['mainsnak']['datavalue']['value']['id']
	    end
	end
    if(q ~= nil) then local p17Statements=mw.wikibase.getBestStatements(q, 'P17' )
 	local i=1	
 	local country=""
 	local year=MathTonumber.integerModule(entitiesArray["yearD"])
	for ki, vi in pairs (p17Statements) do
 	    local start=""
 	    local enD=""
		if (i == 1) then country=mw.wikibase.getLabel(vi['mainsnak']['datavalue']['value']['id']) 
        else
        	if(vi['qualifiers'] ~= nil) then
        		if((vi['qualifiers']['P576'] ~= nil)) then enD=MathTonumber.integerModule(vi['qualifiers']['P576'][1]['datavalue']['value']['time']) end
        		if((vi['qualifiers']['P580'] ~= nil)) then start=MathTonumber.integerModule(vi['qualifiers']['P580'][1]['datavalue']['value']['time']) end
        	else country=mw.wikibase.getLabel(vi['mainsnak']['datavalue']['value']['id']) end
        	if(enD ~= "" and (year-enD)<0) then 
        		if(start ~= "") then
        			if(year-start > 0) then country=mw.wikibase.getLabel(vi['mainsnak']['datavalue']['value']['id']) end
        		else country=mw.wikibase.getLabel(vi['mainsnak']['datavalue']['value']['id']) end	
            end
        end
		i=i+1
	end	
	entitiesArray["countryOfDeath"] = country
	end
	local p20Statements=entity:getAllStatements("P20")
	for ki, vi in pairs (p20Statements) do
		if(vi['qualifiers'] ~= nil and vi['qualifiers']['P17']  ~= nil) then entitiesArray["countryOfDeath"] = mw.wikibase.getLabel(vi['qualifiers']['P17'][1]['datavalue']['value']['id']) end
	end	
end  

function AutoDescriptionState.parseP21(entity)
 	local values=entity:formatPropertyValues("P21",mw.wikibase.entity.claimRanks).value
 	entitiesArray["P21"]=values
 	if (values == "vira") then male="1"
 	elseif (values == "ina") then female="1" end
end  

function AutoDescriptionState.parseP22(entity)
 	local values=entity:formatPropertyValues("P22",mw.wikibase.entity.claimRanks).value
 	if(values ~= nil) then entitiesArray["father"]=values
 	else entitiesArray["father"]="" end
end  

function AutoDescriptionState.parseP25(entity)
 	local values=entity:formatPropertyValues("P25",mw.wikibase.entity.claimRanks).value
 	if(values ~= nil) then entitiesArray["moth"]=values
 	else entitiesArray["moth"]="" end
end  

function AutoDescriptionState.parseP39(entity)
	local p39Statements=entity:getAllStatements("P39")
 	local value=""
 	for k, v in pairs (p39Statements) do
 		entitiesArray.positionHeld[k]=mw.wikibase.getLabel(v['mainsnak']['datavalue']['value']['id']) 
 		entitiesArray.positionHeldStart[k]="None"
 		entitiesArray.positionHeldEnd[k]="None"
 		entitiesArray.positionHeldPG[k]="None"
 		entitiesArray.positionHeldPT[k]="None"
 		entitiesArray.positionHeldReplace[k]="None"
 		entitiesArray.positionHeldReplaceBy[k]="None"
    	if(v['qualifiers'] ~= nil) then
    		if(v['qualifiers'] ~= nil and v['qualifiers']['P580'] ~= nil 
    		   and v['qualifiers']['P580'][1] ~= nil and v['qualifiers']['P580'][1]['datavalue'] ~= nil 
    		   and v['qualifiers']['P580'][1]['datavalue']['value']['time'] ~= nil) 
    		then entitiesArray.positionHeldStart[k]=MathTonumber.integerModule(v['qualifiers']['P580'][1]['datavalue']['value']['time']) 
    		else entitiesArray.positionHeldStart[k]="None" end
    	    if(v['qualifiers'] ~= nil
    	       and v['qualifiers']['P576'] ~= nil
    	       and v['qualifiers']['P576'][1] ~= nil
    	       and v['qualifiers']['P576'][1]['datavalue'] ~= nil
    	       and v['qualifiers']['P576'][1]['datavalue']['value'] ~= nil
    	       and v['qualifiers']['P576'][1]['datavalue']['value']['time'] ~= nil
    	       and v['qualifiers']['P576'][1]['snaktype'] ~= nil -- Что это и следующая строка и зачем в этом запросе?
    	       and v['qualifiers']['P576'][1]['snaktype'] ~= "novalue") 
    	     then entitiesArray.positionHeldEnd[k]=MathTonumber.integerModule(v['qualifiers']['P576'][1]['datavalue']['value']['time'])
    		 else entitiesArray.positionHeldEnd[k]="None" end
    	    if(v['qualifiers']['P4100'] ~= nil and v['qualifiers']['P4100'][1] ~= nil and v['qualifiers']['P4100'][1]['datavalue'] ~= nil and v['qualifiers']['P4100'][1]['datavalue']['value']['id']~=nil and v['qualifiers']['P4100'][1]['datavalue']['value']['id']~="") 
    	     then entitiesArray.positionHeldPG[k]=mw.wikibase.getLabel(v['qualifiers']['P4100'][1]['datavalue']['value']['id'])
    		 else entitiesArray.positionHeldPG[k]="None" end
    	    if(v['qualifiers']['P2937'] ~= nil) 
    	     then entitiesArray.positionHeldPT[k]=mw.wikibase.getLabel(v['qualifiers']['P2937'][1]['datavalue']['value']['id'])
    		 else entitiesArray.positionHeldPG[k]="None" end
    	    if(v['qualifiers']['P1365'] ~= nil and v['qualifiers']['P1365'][1] ~= nil and v['qualifiers']['P1365'][1]['datavalue'] ~= nil and v['qualifiers']['P1365'][1]['datavalue']['value'] ~= nil) 
    	     then entitiesArray.positionHeldReplace[k]=mw.wikibase.getLabel(v['qualifiers']['P1365'][1]['datavalue']['value']['id'])
    		 else entitiesArray.positionHeldReplace[k]="None" end
    	    if(v['qualifiers']['P1366'] ~= nil and v['qualifiers']['P1366'][1] ~= nil and v['qualifiers']['P1366'][1]['datavalue'] ~= nil and v['qualifiers']['P1366'][1]['datavalue']['value'] ~= nil) 
    	     then entitiesArray.positionHeldReplaceBy[k]=mw.wikibase.getLabel(v['qualifiers']['P1366'][1]['datavalue']['value']['id'])
    		 else entitiesArray.positionHeldReplaceBy[k]="None" end
    	end	
    	value=v['mainsnak']['datavalue']['value']['id']
 	end	
    if(string.find(value, "Q")) then return "full" 
    else return "" end
end  

function AutoDescriptionState.parseP69(entity)
	local p69Statements=entity:getAllStatements("P69")
 	local i=1
 	local value=""
    for ki, vi in pairs (p69Statements) do
    	if(vi['mainsnak'] ~= nil and vi['mainsnak']['datavalue']  ~= nil and vi['mainsnak']['datavalue']['value']  ~= nil and vi['mainsnak']['datavalue']['value']['id']  ~= nil) then
    	 entitiesArray.edu[i]=mw.wikibase.getLabel(vi['mainsnak']['datavalue']['value']['id']) 
 	    end	
    	if(vi['qualifiers'] ~= nil) then
    		if(vi['qualifiers']['P580'] ~= nil and vi['qualifiers']['P580'][1] ~= nil and vi['qualifiers']['P580'][1]['datavalue'] ~= nil 
    		   and vi['qualifiers']['P580'][1]['datavalue']['value'] ~= nil and vi['qualifiers']['P580'][1]['datavalue']['value']['time'] ~= nil) 
    		then 
    		 entitiesArray.eduStart[i]=MathTonumber.integerModule(vi['qualifiers']['P580'][1]['datavalue']['value']['time'])
    		else entitiesArray.eduStart[i]="None" end
    		if(vi['qualifiers']['P576'] ~= nil and vi['qualifiers']['P576'][1] ~= nil and vi['qualifiers']['P576'][1]['datavalue'] ~= nil
    		   and vi['qualifiers']['P576'][1]['datavalue']['value'] ~= nil and vi['qualifiers']['P576'][1]['datavalue']['value']['time'] ~= nil) 
    		then 
    		  entitiesArray.eduEnd[i]=MathTonumber.integerModule(vi['qualifiers']['P576'][1]['datavalue']['value']['time'])
    		else entitiesArray.eduEnd[i]="None" end
    	else entitiesArray.eduStart[i]="None" entitiesArray.eduEnd[i]="None" end 
    	i=i+1
    	if(vi['mainsnak'] ~= nil and vi['mainsnak']['datavalue']  ~= nil and vi['mainsnak']['datavalue']['value']  ~= nil and vi['mainsnak']['datavalue']['value']['id']  ~= nil) then
    	 value=vi['mainsnak']['datavalue']['value']['id'] 
 	    end	
    end
    if(string.find(value, "Q")) then return "edu"
    else return "" end
end  

function AutoDescriptionState.parseP101(entity)
 	local p101Statements=entity:getAllStatements("P101")
 	local i=1
    for ki, vi in pairs (p101Statements) do
    	entitiesArray.P101[i]= mw.wikibase.getLabel(vi['mainsnak']['datavalue']['value']['id']) 
    	entitiesArray.P101Q=vi['mainsnak']['datavalue']['value']['id']
    	i=i+1
    end
end  

function AutoDescriptionState.parseP106(entity)
 local p106Statements = entity:getAllStatements("P106")
 local i=1
 for ki, vi in pairs (p106Statements) do
   entitiesArray.occupation[i]= mw.wikibase.getLabel(vi['mainsnak']['datavalue']['value']['id']) 
   entitiesArray.idOccupation[i]= vi['mainsnak']['datavalue']['value']['id'] 
   i=i+1
 end
 i=1
 for ki, vi in pairs (entitiesArray.occupation) do
   local j=1
   local p279Statements=mw.wikibase.getBestStatements(entitiesArray.idOccupation[i], 'P279' )
	for kj, vj in pairs (p279Statements) do
		entitiesArray["upOccupation"][i] = mw.wikibase.getLabel(vj['mainsnak']['datavalue']['value']['id']) 
		for kz, vz in pairs (entitiesArray.occupation) do
			if(vz==entitiesArray["upOccupation"][i]) then entitiesArray["upOccupation"][i]="bin" end
		end	
	end	
	if (entitiesArray["upOccupation"][i] == "okupo" or entitiesArray["upOccupation"][i] == "persono") then entitiesArray["upOccupation"][i]="bin" end
	if (entitiesArray["upOccupation"][i] == "ludanto") then entitiesArray["upOccupation"][i]="sportsmeno" end 
   i=i+1
 end	
end  

function AutoDescriptionState.parseP108(entity)
 local p108Statements = entity:getAllStatements("P108")
 local i=1
 for ki, vi in pairs (p108Statements) do
 	if vi['mainsnak']['datavalue'] == nil then
   -- do nothing and go to the next iteration
  else
   entitiesArray.employer[i]= mw.wikibase.getLabel(vi['mainsnak']['datavalue']['value']['id'])
   entitiesArray.P108Q=vi['mainsnak']['datavalue']['value']['id']
   i=i+1
  end
 end
end

function AutoDescriptionState.parseP166(entity)
 local p166Statements = entity:getAllStatements("P166")
 local value=""
 for k, v in pairs (p166Statements) do
 	entitiesArray.award[k]=mw.wikibase.getLabel(v['mainsnak']['datavalue']['value']['id']) 
    value=v['mainsnak']['datavalue']['value']['id']
    entitiesArray.awardPIT[k]=""
    entitiesArray.awardTW[k]=""
    entitiesArray.awardPM[k]=""
    if(v['qualifiers'] ~= nil) then
    	if(v['qualifiers']['P1706'] ~= nil) then
    		local p1706Statements = v['qualifiers']['P1706']
    		for ki, vi in pairs (p1706Statements) do
    			entitiesArray.awardTW[k]=entitiesArray.awardTW[k] .. " [[" .. mw.wikibase.getLabel(vi['datavalue']['value']['id']) .. "]]" 
    		end	
    	end	
    	if(v['qualifiers']['P585'] ~= nil and v['qualifiers']['P585'][1] ~= nil
           and v['qualifiers']['P585'][1]['datavalue'] ~= nil and v['qualifiers']['P585'][1]['datavalue']['value'] ~= nil
           and v['qualifiers']['P585'][1]['datavalue']['value']['time'] ~= nil) then 
         entitiesArray.awardPIT[k] = MathTonumber.integerModule(v['qualifiers']['P585'][1]['datavalue']['value']['time']) 
        end	
    	if(v['qualifiers']['P2121'] ~= nil and v['qualifiers']['P2121'][1] ~= nil
           and v['qualifiers']['P2121'][1]['datavalue'] ~= nil and v['qualifiers']['P2121'][1]['datavalue']['value'] ~= nil
           and v['qualifiers']['P2121'][1]['datavalue']['value']['amount'] ~= nil) then 
         entitiesArray.awardPM[k] = MathTonumber.integerModule(v['qualifiers']['P2121'][1]['datavalue']['value']['amount']) 
        end
    end	
 end
 if(string.find(value, "Q")) then return "full"
 else return "" end
end  

function AutoDescriptionState.parseP184(entity)
 local p184Statements = entity:getAllStatements("P184")
 local i=1
 local value=""
 for ki, vi in pairs (p184Statements) do
   entitiesArray.docAdvisor[i]=mw.wikibase.getLabel(vi['mainsnak']['datavalue']['value']['id']) 
   value=vi['mainsnak']['datavalue']['value']['id']
   i=i+1
 end
 if(string.find(value, "Q")) then return "full"
 else return "" end
end  

function AutoDescriptionState.parseP185(entity)
 local p185Statements = entity:getAllStatements("P185")
 local i=1
 local value=""
 for ki, vi in pairs (p185Statements) do
   entitiesArray.docStud[i]=mw.wikibase.getLabel(vi['mainsnak']['datavalue']['value']['id']) 
   value=vi['mainsnak']['datavalue']['value']['id']
   i=i+1
 end
 if(string.find(value, "Q")) then return "full"
 else return "" end
end 

function AutoDescriptionState.parseP463(entity)
  local p463Statements = entity:getAllStatements("P463")
  local i=1
  for ki, vi in pairs (p463Statements) do
  	entitiesArray.P463[i]= mw.wikibase.getLabel(vi['mainsnak']['datavalue']['value']['id']) 
  	entitiesArray.P463Q=vi['mainsnak']['datavalue']['value']['id'] 
  	i=i+1
  end	
  if(string.find(entitiesArray.P463Q, "Q")) then return entitiesArray.P463Q 
  else return "" end
end  

function AutoDescriptionState.parseP509(entity)
 local value = entity:formatPropertyValues("P509",mw.wikibase.entity.claimRanks).value
 if(value ~= "") then return value
 else return "" end
end  

function AutoDescriptionState.parseP512(entity)
  local p512Statements = entity:getAllStatements("P512")
  local value = ""
  local i=1
  for k, v in pairs (p512Statements) do
  	entitiesArray.academicDegree[i]=mw.wikibase.getLabel(v['mainsnak']['datavalue']['value']['id'])
  	entitiesArray.academicDegreeDate[i]="None"
  	entitiesArray.academicDegreeF[i]="None"
  	entitiesArray.academicDegreeEdu[i]="None"
  	if(v['qualifiers'] ~= nil) then
  		if(v['qualifiers']['P101'] ~= nil) then entitiesArray.academicDegreeF[k]=mw.wikibase.getLabel(v['qualifiers']['P101'][1]['datavalue']['value']['id'])
  		else entitiesArray.academicDegreeF[k]="None" end
  		if(v['qualifiers']['P69'] ~= nil) then entitiesArray.academicDegreeEdu[k]=mw.wikibase.getLabel(v['qualifiers']['P69'][1]['datavalue']['value']['id'])
  		else entitiesArray.academicDegreeEdu[k]="None" end
  		if(v['qualifiers']['P813'] ~= nil) then entitiesArray.academicDegreeDate[k]=v['qualifiers']['P813'][1]['datavalue']['value']['time']
  		else entitiesArray.academicDegreeDate[k]="None" end
  		if(v['qualifiers']['P585'] ~= nil) then entitiesArray.academicDegreeDate[k]=MathTonumber.integerModule(v['qualifiers']['P585'][1]['datavalue']['value']['time'])
  		elseif (entitiesArray.academicDegreeDate[k] == "None") then entitiesArray.academicDegreeDate[k]="None" end
  	end	
  	value=v['mainsnak']['datavalue']['value']['id']
  	i=i+1
  end	
  if(string.find(value, "Q")) then return "full" 
  else return "" end
end  

function AutoDescriptionState.parseP551(entity)
  local p551Statements = entity:getAllStatements("P551")
  local value = ""
  local i=1
  for k, v in pairs (p551Statements) do
  	entitiesArray.residence[i]=mw.wikibase.getLabel(v['mainsnak']['datavalue']['value']['id']) 
  	entitiesArray.residenceSt[i]="NoNe"
  	entitiesArray.residenceEnd[i]="NoNe"
  	if(v['qualifiers'] ~= nil) then
  		if(v['qualifiers']['P576'] ~= nil and v['qualifiers']['P576'][1] ~= nil 
  		   and v['qualifiers']['P576'][1]['datavalue'] ~= nil and v['qualifiers']['P576'][1]['datavalue']['value'] ~= nil 
  		   and v['qualifiers']['P576'][1]['datavalue']['value']['time'] ~= nil) then 
         entitiesArray.residenceEnd[i]=MathTonumber.integerModule(v['qualifiers']['P576'][1]['datavalue']['value']['time']) 
  		else entitiesArray.residenceEnd[i]="NoNe" end
  		if(v['qualifiers']['P580'] ~= nil and v['qualifiers']['P580'][1] ~= nil
           and v['qualifiers']['P580'][1]['datavalue'] ~= nil and v['qualifiers']['P580'][1]['datavalue']['value'] ~= nil
           and v['qualifiers']['P580'][1]['datavalue']['value']['time'] ~= nil) then 
         entitiesArray.residenceSt[i]=MathTonumber.integerModule(v['qualifiers']['P580'][1]['datavalue']['value']['time']) 
  		else entitiesArray.residenceSt[i]="NoNe" end
  	end	
  	value=v['mainsnak']['datavalue']['value']['id']
  	i=i+1
  end	
  if(string.find(value, "Q")) then return "full" 
  else return "" end
end  

function AutoDescriptionState.parseP571(entity)
 local valuesP=entity:formatPropertyValues("P571", { mw.wikibase.entity.claimRanks.RANK_PREFERRED }).value
 local valuesN=entity:formatPropertyValues("P571", { mw.wikibase.entity.claimRanks.RANK_NORMAL }).value
 local valuesC=entity:formatPropertyValues("P571",mw.wikibase.entity.claimRanks).value
 local values=""
 if(valuesP ~= nil) then values=valuesP end
 if(values == "" and valuesN ~= nil) then values=valuesN end
 if(values == "" and valuesC ~= nil) then values=valuesC end
 if(values ~= "") then 
 	entitiesArray["dayB"]=values:match"(%d+)[-/.%s]" 
 	entitiesArray["monthB"]=string.gsub(values, '[^a-z]', '' )
 	if(string.find(values, "februaro")) then entitiesArray["monthB"]="februaro" 
 	elseif (string.find(values, "januaro")) then  entitiesArray["monthB"]="januaro" 
 	elseif (string.find(values, "marto")) then  entitiesArray["monthB"]="marto"
 	elseif (string.find(values, "aprilo")) then  entitiesArray["monthB"]="aprilo" 
 	elseif (string.find(values, "jun.")) then  entitiesArray["monthB"]="junio" 
 	elseif (string.find(values, "jun")) then  entitiesArray["monthB"]="junio" 
 	elseif (string.find(values, "junio")) then  entitiesArray["monthB"]="junio" 
 	elseif (string.find(values, "julio")) then  entitiesArray["monthB"]="julio" 
 	elseif (string.find(values, "aŭgusto")) then  entitiesArray["monthB"]="aŭgusto" 
 	elseif (string.find(values, "septembro")) then  entitiesArray["monthB"]="septembro" 
 	elseif (string.find(values, "oktobro")) then  entitiesArray["monthB"]="oktobro" 
 	elseif (string.find(values, "novembro")) then  entitiesArray["monthB"]="novembro" 
 	elseif (string.find(values, "decembro")) then  entitiesArray["monthB"]="decembro" 
 	elseif (string.find(values, "senco ne klaras")) then  entitiesArray["dayB"]=""  entitiesArray["monthB"]=""  entitiesArray["yearB"]="" 	
    end
 	entitiesArray["yearB"]=values:match(' %d*%d%d')
 	if(#values <= 4) then
 		entitiesArray["dayB"]=""
 		entitiesArray["monthB"]=""
 		entitiesArray["yearB"]=values
 	elseif(entitiesArray["yearB"] ~= nil) then entitiesArray["yearB"]=entitiesArray["yearB"]:sub(2,#entitiesArray["yearB"]) end	
 	local result_data = ""
 	if entitiesArray["dayB"] ~= nil and entitiesArray["dayB"] ~= "" then result_data = result_data .. entitiesArray["dayB"] .. " " end
 	if entitiesArray["monthB"] ~= nil and entitiesArray["monthB"] ~= "" then result_data = result_data .. entitiesArray["monthB"] .. " " end
 	if entitiesArray["yearB"] ~= nil and entitiesArray["yearB"] ~= "" then result_data = result_data .. entitiesArray["yearB"] .. " " end
 	return result_data
 else return ""
 end
end  

function AutoDescriptionState.parseP576(entity)
 local valuesP=entity:formatPropertyValues("P576", { mw.wikibase.entity.claimRanks.RANK_PREFERRED }).value
 local valuesN=entity:formatPropertyValues("P576", { mw.wikibase.entity.claimRanks.RANK_NORMAL }).value
 local valuesC=entity:formatPropertyValues("P576",mw.wikibase.entity.claimRanks).value
 local values=""
 if(valuesP ~= nil) then values=valuesP end
 if(values == "" and valuesN ~= nil) then values=valuesN end
 if(values == "" and valuesC ~= nil) then values=valuesC end
 if(values ~= "") then
 	entitiesArray["dayD"]=values:match"(%d+)[-/.%s]"
 	entitiesArray["monthD"]=string.gsub(values, '[^a-z]', '' )
 	if(string.find(values, "februaro")) then entitiesArray["monthD"]="februaro"  
 	elseif (string.find(values, "novembro")) then  entitiesArray["monthD"]="novembro" 
 	elseif (string.find(values, "septembro")) then  entitiesArray["monthD"]="septembro" 
 	elseif (string.find(values, "aprilo")) then  entitiesArray["monthD"]="aprilo" 
 	elseif (string.find(values, "julio")) then  entitiesArray["monthD"]="julio" 
 	elseif (string.find(values, "marto")) then  entitiesArray["monthD"]="marto"
 	elseif (string.find(values, "junio")) then  entitiesArray["monthD"]="junio" 
 	elseif (string.find(values, "decembro")) then  entitiesArray["monthD"]="decembro" 
 	elseif (string.find(values, "januaro")) then  entitiesArray["monthD"]="januaro" 
 	elseif (string.find(values, "aŭgusto")) then  entitiesArray["monthD"]="aŭgusto"
 	elseif (string.find(values, "oktobro")) then  entitiesArray["monthD"]="oktobro" 
	elseif (string.find(values, "senco ne klaras")) then  entitiesArray["dayD"]=""  entitiesArray["monthD"]=""  entitiesArray["yearD"]="" 
    end
 	entitiesArray["yearD"]=values:match(' %d*%d%d')
 	if(#values <= 4) then
 		entitiesArray["dayD"]=""
 		entitiesArray["monthD"]=""
 		entitiesArray["yearD"]=values
 	elseif(entitiesArray["yearD"] ~= nil) then entitiesArray["yearD"]=entitiesArray["yearD"]:sub(2,#entitiesArray["yearD"]) 
 	end	
 	return values   
 else return ""
 end
end

function AutoDescriptionState.parseP800(entity)
  local p800Statements = entity:getAllStatements("P800")
  local i=1
  local value=""
  for ki, vi in pairs (p800Statements) do
  	entitiesArray.notableWork[i]= mw.wikibase.getLabel(vi['mainsnak']['datavalue']['value']['id']) 
  	value=vi['mainsnak']['datavalue']['value']['id'] 
  	i=i+1
  end	
  if(string.find(value, "Q")) then return "full"
  else return "" end
end  

function AutoDescriptionState.parseP802(entity)
  local p802Statements = entity:getAllStatements("P802")
  local i=1
  local value=""
  for ki, vi in pairs (p802Statements) do
  	entitiesArray.stu[i]= mw.wikibase.getLabel(vi['mainsnak']['datavalue']['value']['id']) 
  	value=vi['mainsnak']['datavalue']['value']['id'] 
  	i=i+1
  end	
  if(string.find(value, "Q")) then return "full"
  else return "" end
end

function AutoDescriptionState.parseP1196(entity)
 local value = entity:formatPropertyValues("P1196",mw.wikibase.entity.claimRanks).value
 if(value ~= "") then return value
 else return "" end
end

function AutoDescriptionState.parseP1344(entity)
 local p1344Statements = entity:getAllStatements("P1344")
 local i=1
 local value=""
 for ki, vi in pairs (p1344Statements) do
   entitiesArray.participantOf[i]=mw.wikibase.getLabel(vi['mainsnak']['datavalue']['value']['id']) 
   value=vi['mainsnak']['datavalue']['value']['id']
   i=i+1
 end
 if(string.find(value, "Q")) then return "full"
 else return "" end
end  

function AutoDescriptionState.parseP1705(entity)
 local P1705Statements = entity:getAllStatements("P1705")	
 for ki, vi in pairs (P1705Statements) do
 	if (vi['mainsnak']['datavalue']['value']['language']) then entitiesArray.langName=vi['mainsnak']['datavalue']['value']['language'] end
 	if (vi['mainsnak']['datavalue']['value']['text']) then entitiesArray.nativeName=vi['mainsnak']['datavalue']['value']['text'] end
 end	
end  

function AutoDescriptionState.parseP2021(entity)
 local value = entity:formatPropertyValues("P2021",mw.wikibase.entity.claimRanks).value
 if(value ~= "") then return value
 else return "" end
end

return AutoDescriptionState