Modül:Wikidata/P512

Vikipedi, özgür ansiklopedi
Modül belgelemesi[oluştur]
local p = {}

function p.formatAcademicDegree( context, options )
	if ( not context ) then error( 'context not specified' ); end;
	if ( not options ) then error( 'options not specified' ); end;
	if ( not options.entity ) then error( 'options.entity missing' ); end;
 
    local claims = context.selectClaims( options, options.property );
    if (claims == nil) then
        return ''
    end
    
    local blackList = p.getPreviousDegrees( claims )
    local formattedClaims = {}
 
    for i, claim in ipairs(claims) do
    	if (claim.mainsnak.datavalue and not blackList[claim.mainsnak.datavalue.value['numeric-id']]) then
	        local formattedStatement = context.formatStatement( options, claim )

	        if (formattedStatement) then
	            formattedStatement = '<span class="wikidata-claim"' .. 
		            ' data-wikidata-property-id="' .. 
		            string.upper( options.property ) .. 
		            '" data-wikidata-claim-id="' .. 
		            claim.id .. '">' ..
		            formattedStatement .. '</span>'

	            if (claim.qualifiers) then
	            	formattedStatement = formattedStatement .. 
	            		p.formatQualifier( context, options, claim.qualifiers.P585 )
	            end
	            formattedStatement = formattedStatement .. 
	            	p.formatCorrespondingCategory( claim )

	            table.insert( formattedClaims, formattedStatement )
	        end
	    end
    end
 
    return mw.text.listToText( formattedClaims, options.separator, options.conjunction );	
end

function p.formatQualifier( context, options, qualifiers )
	if (qualifiers~=nil and qualifiers[1] ~= nil) then
		return ' (' .. context.formatSnak( options, qualifiers[1] ) .. ')'
	end
	
	return ''
end

function p.getPreviousDegrees( claims )
	local correspondingCandidates = {
		[16698078] = 19610224, 
		[17281188] = 19610186, 
		[17281187] = 19610187, 
		[17281186] = 19610193, 
		[16698080] = 19610195, 
		[16698082] = 19610197, 
		[17281180] = 18523814, 
		[12101789] = 18523811, 
		[16698084] = 19610200, 
		[17281165] = 19610203, 
		[17281161] = 19610206, 
		[12101787] = 4212319,  
		[17281156] = 19610208, 
		[17281153] = 19610210, 
		[17281152] = 19610212, 
		[17281125] = 18071588, 
		[17281115] = 19610228, 
		[17281097] = 18002832, 
		[17281087] = 19603970, 
		[17281084] = 19603972, 
		[17281079] = 19610312, 
		[17281072] = 17744738, 
		[18745564] = 19610320  
	}
	
	local previousElements = {}
	for i, claim in ipairs(claims) do
		if(claim.mainsnak.datavalue) then
			local entityId = claim.mainsnak.datavalue.value['numeric-id']
			if (entityId) then
				if correspondingCandidates[entityId] then
					previousElements[correspondingCandidates[entityId]] = true
				end
			end
		end
	end
	return previousElements
end

function p.formatCorrespondingCategory (claim)
	if ( not claim ) then return '' end;
	if ( not claim.mainsnak ) then return '' end;
	
	if claim.mainsnak.datavalue.value['numeric-id'] == 752297 then return '' end
	
	local label = mw.wikibase.label("Q" .. claim.mainsnak.datavalue.value['numeric-id'])
	if not label then label = '' end
		
	local result, changes = string.gsub(label, "doktor ", "Kateqoriya:Doktor ")
	if (changes == 1) then
		return '[[' .. result .. ']]'
	end
	
	result, changes = string.gsub(label, "namizəd ", "Kateqoriya:Namizədlər ")
	if (changes == 1) then
		return '[[' .. result .. ']]'
	end
	
	return ''
end

return p