모듈:ArtworkInfo

local p = {}
local entity = mw.wikibase.getEntityObject()
function p.getLabel(frame)
local lang = frame.args1 or 'ko'
	local id = mw.wikibase.getEntityIdForCurrentPage()
	local label = mw.wikibase.getLabelByLang( id , lang )
	return label
end
function p.startTime(qid , key)
	local valueTable = entity.claimsqid
	local startTime = valueTablekey.qualifiers.P5801.datavalue.value.time
	startTime = string.match(startTime, '+(%d+)-')
	return startTime
end
function p.endTime(qid , key)
	local valueTable = entity.claimsqid
	local endTime = valueTablekey.qualifiers.P5821.datavalue.value.time
	endTime = string.match(endTime, '+(%d+)-')
	return endTime
end
function p.pointInTime(qid , key)
	local valueTable = entity.claimsqid
	
	if valueTablekey.qualifiers == nil then
		return nil
	elseif valueTablekey.qualifiers'P585' == nil then
		return nil
	end
	
	local pointInTime = valueTablekey.qualifiers.P5851.datavalue.value.time
	
	pointInTime = string.match(pointInTime, '+(%d+)-')
	return pointInTime
end
function p.listOfOwners(frame)
	local qid = frame.args1
	local valueTable = entity.claimsqid
	local str
	local i = 1
local startTime, endTime
	if valueTable == nil then
		return nil
	end
	for key in ipairs(valueTable) do
		
		if valueTablekey.mainsnak.datavalue == nil then
			return nil
		end		
		
		local id = valueTablekey.mainsnak.datavalue.value.id
		local koCheck, item = mw.wikibase.getLabelByLang( id, 'ko' )
		local koPage = mw.wikibase.getSitelink(id)
		local pointInTime = p.pointInTime(qid , key)
		if item == nil then
			item = mw.wikibase.getLabel( id )
		end
		
		if item ~= nil then
		if i == 1 then 
if valueTablekey.qualifiers then			
			   if (valueTablekey.qualifiers.P580 and valueTablekey.qualifiers.P582) then 
					startTime = p.startTime(qid , key)
					endTime = p.endTime(qid , key)
					if (koCheck ~= nil) and (koPage ~= nil)  then
						str = string.format("%s(%d~%d)", koPage, item, startTime, endTime)
					else
						str = string.format("%s(%d~%d)", id, item, startTime, endTime)
					end
			   elseif valueTablekey.qualifiers.P580 then
					startTime = p.startTime(qid , key)
					if (koCheck ~= nil) and (koPage ~= nil)  then
						str = string.format("%s(%d~)", koPage, item, startTime)
					else
						str = string.format("%s(%d~)", id, item, startTime)
					end
				elseif valueTablekey.qualifiers.P582 then
					endTime = p.endTime(qid , key)
					if (koCheck ~= nil) and (koPage ~= nil)  then
				    	str = string.format("%s(~%d)", koPage, item, endTime)
				    else
				    	str = string.format("%s(~%d)", id, item, endTime)
				    end
				else
					if (koCheck ~= nil) and (koPage ~= nil)  then
						str = "' .. item .. 
					else
						str = "' .. item .. 
					end
	end
			elseif pointInTime ~= nil then
				if (koCheck ~= nil) and (koPage ~= nil)  then
						str = string.format("%s (%d)", koPage, item, pointInTime)
					else
						str = string.format("%s (%d)", id, item, pointInTime)
					end
			else 
				if (koCheck ~= nil) and (koPage ~= nil)  then
					str = "' .. item .. 
				else
					str = "' .. item .. 
				end
			end
		else
	       if valueTablekey.qualifiers then	
				if (valueTablekey.qualifiers.P580 and valueTablekey.qualifiers.P582) then 
					startTime = p.startTime(qid , key)
					endTime = p.endTime(qid , key)
					if (koCheck ~= nil) and (koPage ~= nil)  then
						item = string.format("%s(%d~%d)", koPage, item, startTime, endTime)
					else
						item = string.format("%s(%d~%d)", id, item, startTime, endTime)
					end
					str = string.format("%s%s", str, item)
				elseif valueTablekey.qualifiers.P580 then
					startTime = p.startTime(qid , key)
					if (koCheck ~= nil) and (koPage ~= nil)  then
						item = string.format("%s(%d~)", koPage, item, startTime)
					else
						item = string.format("%s(%d~)", id, item, startTime)
					end
					str = string.format("%s%s", str, item)
				elseif valueTablekey.qualifiers.P582 then
					endTime = p.endTime(qid , key)
					if (koCheck ~= nil) and (koPage ~= nil)  then
						item = string.format("%s(~%d)", koPage, item, endTime)
					else
						item = string.format("%s(~%d)", id, item, endTime)
					end
					str = string.format("%s%s", str, item)
				else
					if (koCheck ~= nil) and (koPage ~= nil)  then
						str = string.format("%s%s", str, koPage, item)
					else
						str = string.format("%s%s", str, id, item)
					end
				end
			elseif pointInTime ~= nil then
				if (koCheck ~= nil) and (koPage ~= nil)  then
					item = string.format("%s (%d)", koPage, item, pointInTime)
				else
					item = string.format("%s (%d)", id, item, pointInTime)
				end
				str = string.format("%s%s", str, item)
			else
				if (koCheck ~= nil) and (koPage ~= nil)  then
					str = string.format("%s%s", str, koPage, item)
				else
					str = string.format("%s%s", str, id, item)
				end
			end
		end
		
		i = i + 1
		
		end
	end
return str
end
function p.meterialUsed()
	local valueTable = entity.claims'P186'
	local str = 
	local str1 = 
	local str2 = 
	for key in ipairs(valueTable) do
		local id = valueTablekey.mainsnak.datavalue.value.id
		local label = mw.wikibase.getLabel(id)
		if valueTablekey.qualifiers then
			local qualifiers = valueTablekey.qualifiers
			for qkey in pairs(qualifiers) do
				if qualifiersqkey1.datavalue.value.id == 'Q861259' then 
					if str1 ==  then
						str1 = label
					else
					str1 = string.format("%s %s", str1, label)
					end
				end
			end
		else
			if str1 ==  then
				str2 = label
			else
				str2 = string.format("%s %s", str2, label)
			end
		end
	end
	if str1 ==  then
		str = str2
	else
		str = string.format("%s에 %s", str1, str2)
	end
return str
end
function p.getFilename(frame)
	
	local property
	
	if frame.args1 == nil then
		property = 'P18'
	else
		property = frame.args1
	end
	local valueTable = entity.claimsproperty
	local name
	name = valueTable1.mainsnak.datavalue.value
return name
end
function p.getLists(frame)
	local property = frame.args1
	local valueTable = entity.claimsproperty
	local str = 
	local i = 1
	local num = frame.args'num'
	
	if valueTable == nil then
		return nil
	end
	for key in ipairs(valueTable) do
		local id = valueTablekey.mainsnak.datavalue.value.id
		local check, item = mw.wikibase.getLabelByLang( id, 'ko' )
		local page = mw.wikibase.getSitelink(id)
		
		if item == nil then
			item = mw.wikibase.getLabel( id )
		end
		
		if item ~= nil then 
		if i == 1 then
			if (check ~= nil) and (page ~= nil)  then
				str =  .. item .. 
			else
				str =  .. item .. 
			end
		else
			if (check ~= nil) and (page ~= nil) then
				str = str .. ', ' .. item .. 
			else
				str = str .. ', '  .. item .. 
			end
		end
		
		i = i + 1
		
		if num ~= nil and num == (i - 1) then
			break	
		end
		
		end
	end
	return str
end
function p.getNotableWorks()
	local property = 'P800'
	local valueTable = entity.claimsproperty
	local str = 
	local i = 1
	
	if valueTable == nil then
		return nil
	end
	for key in ipairs(valueTable) do
		local id = valueTablekey.mainsnak.datavalue.value.id
		local koCheck, item = mw.wikibase.getLabelByLang( id, 'ko' )
		local koPage = mw.wikibase.getSitelink(id)
		
		if item == nil then
			item = mw.wikibase.getLabel( id )
		end
		
		if item ~= nil then 
		if i == 1 then
			if (koCheck ~= nil) and (koPage ~= nil)  then
				str =  .. item .. 
			else
				str =  .. item .. 
			end
		else
			if (koCheck ~= nil) and (koPage ~= nil) then
				str = str .. ', ' .. item .. 
			else
				str = str .. ', '  .. item .. 
			end
		end
		
		i = i+1
		
		end
	end
	return str
end
function p.getAwords()
	local property = 'P166'
	local valueTable = entity.claimsproperty
	local str = 
	local i = 1
	
	if valueTable == nil then
		return nil
	end
	
	for key in ipairs(valueTable) do
		local id = valueTablekey.mainsnak.datavalue.value.id
		local koCheck, item = mw.wikibase.getLabelByLang( id, 'ko' )
		local koPage = mw.wikibase.getSitelink(id)
		local pointInTime = p.pointInTime(property , key)
		
		
		if item == nil then
			item = mw.wikibase.getLabel( id )
		end
		
		if item ~= nil then 
		if i == 1 then
			if pointInTime == nil then
				if (koCheck ~= nil) and (koPage ~= nil)  then
				str =  .. item .. 
				else
				str =  .. item .. 
				end
				
			else 
				if (koCheck ~= nil) and (koPage ~= nil)  then
				str =  .. item .. ' (' .. pointInTime .. ')'
				else
				str =  .. item .. ' (' .. pointInTime .. ')'
				end
			end
		else
			if pointInTime == nil then
				if (koCheck ~= nil) and (koPage ~= nil) then
				str = str ..  .. item .. 
				else
				str = str ..   .. item .. 
				end
			else
				if (koCheck ~= nil) and (koPage ~= nil) then
				str = str ..  .. item .. ' (' .. pointInTime .. ')'
				else
				str = str ..   .. item .. ' (' .. pointInTime .. ')'
				end
			end
		end
		
		i = i+1
		
		end
	
		
	end
	return str
end
function p.getParents()
	local valueTable = entity.claims'P22'
	local valueTable2 = entity.claims'P25'
	local str = 
	
	if valueTable ~= nil then
		if not valueTable1.mainsnak.datavalue then
			return nil
		end
		
		local id = valueTable1.mainsnak.datavalue.value.id
		local koCheck, item = mw.wikibase.getLabelByLang( id, 'ko' )
		local koPage = mw.wikibase.getSitelink(id)
		
		if item == nil then
			item = mw.wikibase.getLabel( id )
		end
		
		if (item ~= nil) and (koCheck ~= nil) and (koPage ~= nil)  then
			str = string.format("%s(부)", koPage, item)
		elseif item ~= nil then
			str = string.format("%s(부)", id, item)
		end
		
		if valueTable2 ~= nil then
			id = valueTable21.mainsnak.datavalue.value.id
			koCheck, item = mw.wikibase.getLabelByLang( id, 'ko' )
			koPage = mw.wikibase.getSitelink(id)
			
			if item == nil then
			item = mw.wikibase.getLabel( id )
			end
			
			if item ~= nil then
				if (koCheck ~= nil) and (koPage ~= nil)  then
					item = string.format("%s(모)", koPage, item)
					str = string.format("%s%s", str, item)
				elseif item ~= nil then
					item = string.format("%s(모)", id, item)
					str = string.format("%s%s", str, item)
				end	
			end
		end
	elseif valueTable2 ~= nil then
		id = valueTable21.mainsnak.datavalue.value.id
		koCheck, item = mw.wikibase.getLabelByLang( id, 'ko' )
		koPage = mw.wikibase.getSitelink(id)
		
		if item == nil then
			item = mw.wikibase.getLabel( id )
		end
		
		if (item ~= nil) and (koCheck ~= nil) and (koPage ~= nil)  then
			str = string.format("%s(모)", koPage, item)
		elseif item ~= nil then
			str = string.format("%s(모)", id, item)
		end	
	end
	
	return str
	
end
function p.getRelatives(frame)
	
	local property
	if frame.args1 ~= nil then
		property = frame.args1
	else
		property = 'P1038'
	end
	local valueTable = entity.claimsproperty
	local str = 
	local i = 1
	
	if valueTable ~= nil then
	
		for key in ipairs(valueTable) do
	
			local id = valueTablekey.mainsnak.datavalue.value.id
			local koCheck, item = mw.wikibase.getLabelByLang( id, 'ko' )
			local koPage = mw.wikibase.getSitelink(id)
			local id2
			local typeOfKinship
			
			if valueTablekey.qualifiers ~= nil then 
				id2 = valueTablekey.qualifiers.P10391.datavalue.value.id
				typeOfKinship = mw.wikibase.getLabelByLang( id2, 'ko' )
			else
				typeOfKinship = nil
			end
		
			if item == nil then
			item = mw.wikibase.getLabel( id )
			end
		
			if item ~= nil then
		
				if i == 1 then
					
					if typeOfKinship ~= nil then
						if (koCheck ~= nil) and (koPage ~= nil)  then
						str = string.format("%s (%s)", koPage, item, typeOfKinship)
						else
						str = string.format("%s (%s)", id, item, typeOfKinship)
						end
					else
						if (koCheck ~= nil) and (koPage ~= nil)  then
						str = string.format("%s", koPage, item)
						else
						str = string.format("%s", id, item)
						end
					end
				else
					if typeOfKinship ~= nil then
						if (koCheck ~= nil) and (koPage ~= nil)  then
						str = string.format("%s%s (%s)", str, koPage, item, typeOfKinship)
						else
						str = string.format("%s%s (%s)",str, id, item, typeOfKinship)
						end
					else
						if (koCheck ~= nil) and (koPage ~= nil)  then
						str = string.format("%s%s", str, koPage, item)
						else
						str = string.format("%s%s", str, id, item)
						end
					end
				end
			end
			
			i = i + 1
			
		end
	end
	
	return str
	
end
function p.getGallery()
	
	local property = 'P800'
	local valueTable = entity.claimsproperty
	local str = 
	local i = 1
	
	if valueTable == nil then
		return nil
	end
	
	for key in ipairs(valueTable) do
		local id = valueTablekey.mainsnak.datavalue.value.id
		local koCheck, item = mw.wikibase.getLabelByLang( id, 'ko' )
		local koPage = mw.wikibase.getSitelink(id)
		
		if item == nil then
			item = mw.wikibase.getLabel( id )
		end
		
		local rawname = mw.wikibase.getEntityObject(id).claims'P18'
		if rawname ~= nil then
		
			local fileName = rawname1.mainsnak.datavalue.value
		
			if i == 1 then
				if (koCheck ~= nil) and (koPage ~= nil)  then
					str = string.format(""
	end
	return str
end
function p.getGalleryTest()
	
	local property = 'P800'
	local valueTable = entity.claimsproperty
	local str = 
	local i = 1
	
	if valueTable == nil then
		return nil
	end
	
	for key in ipairs(valueTable) do
		local id = valueTablekey.mainsnak.datavalue.value.id
		
		local rawname = mw.wikibase.getEntityObject(id).claims'P18'
		if rawname ~= nil then
		
			local fileName = rawname1.mainsnak.datavalue.value
		
		
			if item == nil then
			item = mw.wikibase.getLabel( id )
			end
		
			if i == 1 then
			
					str = fileName
			else
				
					str = str ..  .. fileName
			end
		
			i = i+1
		
		end
		
	end
	return str
end
return p