вікізьвесткі/P6087

Модуль для адлюстраваньня ўласьцівасьці Вікізьвестак d:Property:P6087 (галоўны трэнэр спартовай каманды).

 
Дакумэнтацыя модулю Дакумэнтацыя модулю]

Асноўная функцыя модулю formatPropertyP6087 вяртае трэнэрскую кар’еру ў выглядзе шаблёну {{Спартовая кар’ера}}. Тып аб’ектаў (напрыклад, толькі футбольныя клюбы, ці толькі хакейныя) можна задаць праз парамэтар teamEntity (на ўваход падаюцца элемэнты Вікізьвестак праз коску, напрыклад, для футбольных клюбаў і зборных — teamEntity=Q476028,Q28140340,Q51481377,Q94579592,Q6979593).

Выклік модулю адбываецца праз шаблён {{Вікізьвесткі/p6087}}.

Выкарыстоўваецца ў шаблёне {{Футбаліст2}} (праз падшаблён {{Футбаліст2/Кар’ера}}.
local p = {} local categoryLinksToEntitiesWithMissingLocalLanguageLabel = '[[Катэгорыя:Вікіпэдыя:Артыкулы з элемэнтамі зь Вікізьвестак, якія патрабуюць перакладу]]'; local categoryLinksToEntitiesWithMissingLabel = '[[Катэгорыя:Вікіпэдыя:Артыкулы з элемэнтамі зь Вікізьвестак, якія патрабуюць подпісу]]'; local contentLanguageCode = mw.getContentLanguage():getCode();  local function min( prev, next ) if ( prev == nil ) then return next; elseif ( prev > next ) then return next; else return prev; end end  local function max( prev, next ) if ( prev == nil ) then return next; elseif ( prev < next ) then return next; else return prev; end end  local function getTimeBoundariesFromQualifiers( context, statement, qualifierId ) -- only support exact date so far, but need improvment local left = nil; local right = nil; if ( statement.qualifiers and statement.qualifiers[qualifierId] ) then for _, qualifier in pairs( statement.qualifiers[qualifierId] ) do local boundaries = context.parseTimeBoundariesFromSnak( qualifier ); if ( not boundaries ) then return nil; end left = min( left, boundaries[1] ); right = max( right, boundaries[2] ); end end  if ( not left or not right ) then return nil; end  return { left, right }; end  local function getParentsInBoundariesSnakImpl( context, entity, boundaries, propertyIds )     local WDS = require('Модуль:Сьцьверджаньні Вікізьвестак') local results = {}; if entity.claims then for _, propertyId in ipairs( propertyIds ) do local filteredClaims = WDS.filter( entity.claims, propertyId .. '[rank:preferred, rank:normal]' ); if filteredClaims then for _, claim in pairs( filteredClaims ) do local startBoundaries = getTimeBoundariesFromQualifiers( context, claim, 'P580' ); local endBoundaries = getTimeBoundariesFromQualifiers( context, claim, 'P582' );  if ( (startBoundaries == nil or ( startBoundaries[2] <= boundaries[1])) and (endBoundaries == nil or ( endBoundaries[1] >= boundaries[2]))) then table.insert( results, claim.mainsnak ); end  end end  if #results > 0 then break; end end end  return results; end  local function getParentsInBoundariesSnakImplNotStrong( context, entity, boundaries, propertyIds )     local WDS = require('Модуль:Сьцьверджаньні Вікізьвестак') local results = {}; if entity.claims then for _, propertyId in ipairs( propertyIds ) do local filteredClaims = WDS.filter( entity.claims, propertyId .. '[rank:preferred, rank:normal]' ); if filteredClaims then for _, claim in pairs( filteredClaims ) do local startBoundaries = getTimeBoundariesFromQualifiers( context, claim, 'P580' ); local endBoundaries = getTimeBoundariesFromQualifiers( context, claim, 'P582' );  if ( (startBoundaries == nil or ( startBoundaries[1] <= boundaries[1])) and (endBoundaries == nil or ( endBoundaries[2] >= boundaries[2]))) then table.insert( results, claim.mainsnak ); end  end end  if #results > 0 then break; end end end  return results; end  -- get current of historic name of place function getLabel2( context, entity, boundaries) if not entity then return nil; end local lang = mw.language.getContentLanguage(); local langCode = lang:getCode(); local returnLangCode = langCode;  -- name from label -- TODO: lang:getFallbackLanguages() local label = nil; label, returnLangCode = mw.wikibase.getLabelWithLang( entity.id );  -- name from properties local results = getParentsInBoundariesSnakImpl( context, entity, boundaries, { 'P1813[language:' .. langCode .. ']', 'P1448[language:' .. langCode .. ']', 'P1705[language:' .. langCode .. ']' } );         if #results == 0 then        results = getParentsInBoundariesSnakImplNotStrong( context, entity, boundaries, { 'P1813[language:' .. langCode .. ']', 'P1448[language:' .. langCode .. ']',   'P1705[language:' .. langCode .. ']'   } );         end  for r, result in pairs( results ) do if result.datavalue and result.datavalue.value and result.datavalue.value.text then label = result.datavalue.value.text; returnLangCode = langCode; break; end end  return label, returnLangCode; end  local function formatEntityId( context, entityId, options ) -- атрыманьне лякалізаванай назвы     local entity = mw.wikibase.getEntity(entityId);     local label = nil;     local labelLanguageCode = nil;     if options.teamDate then       local boundaries = context.parseTimeBoundariesFromSnak(options.teamDate)       label, labelLanguageCode = getLabel2( context, entity, boundaries)     end     if label == nil then       if ( options.text and options.text ~= '' ) then           label = options.text       else    label, labelLanguageCode = mw.wikibase.getLabelWithLang( entityId );        end     end      -- вызначэньне адпаведнай паказванаму элемэнту катэгорыі local category = '' options['category'] = 'P6112' if ( options['category'] ) then local WDS = require('Модуль:Сьцьверджаньні Вікізьвестак'); local claims = WDS.filter( entity.claims, options['category'] ); if ( claims ) then for _, claim in pairs( claims ) do if ( claim.mainsnak and claim.mainsnak and claim.mainsnak.datavalue and claim.mainsnak.datavalue.type == "wikibase-entityid" ) then local catEntityId =  'Q' .. claim.mainsnak.datavalue.value["numeric-id"]; local catEntity = mw.wikibase.getEntity( catEntityId ); if ( catEntity and catEntity:getSitelink() ) then category = '[[' .. catEntity:getSitelink() .. ']]'; end end end end end  -- атрыманьне спасылкі па ідэнтыфікатары     local link = mw.wikibase.sitelink( entityId )     if link then         if label then if ( contentLanguageCode ~= labelLanguageCode ) then             return '[[' .. link .. '|' .. label .. ']]' .. categoryLinksToEntitiesWithMissingLocalLanguageLabel .. category;             else             return '[[' .. link .. '|' .. label .. ']]' .. category;             end         else             return '[[' .. link .. ']]' .. category;         end     end      if label then     if ( contentLanguageCode ~= labelLanguageCode ) then       category = category .. categoryLinksToEntitiesWithMissingLocalLanguageLabel     end         -- чырвоная спасылка         -- TODO: разабрацца, чаму не заўсёды ёсьць options.frame         if not mw.title.new( label ).exists and options.frame then             return '[[' .. label .. ']][[:d:' .. entityId .. '|[d]]]' .. category;         end      -- TODO: перанесьці да праверкі на існаваньне артыкула local sup = ''; if ( not options.format or options.format ~= 'text' ) and entityId ~= 'Q6581072' and entityId ~= 'Q6581097' -- TODO: перапісаць на format=text then sup = '[[:d:' .. entityId .. '|[d]]]' end          -- аднайменны артыкул ужо існуе — выводзіцца тэкст і спасылка на Вікізьвесткі         return label .. sup .. category     end     -- паведамленьне аб адсутнасьці лякалізаванай назвы     -- not good, but better than nothing     return '[[:d:' .. entityId .. '|' .. entityId .. ']]?' .. categoryLinksToEntitiesWithMissingLabel .. category; end  local function orderByDate( teamClaims )    local orderedTeams = {}    while (#teamClaims > 0) do      local j = 1      local firstClaim = teamClaims[1]      for i=2,#teamClaims,1 do        if (teamClaims[i].qualifiers and teamClaims[i].qualifiers.P580 and firstClaim.qualifiers and firstClaim.qualifiers.P580) then          if (teamClaims[i].qualifiers.P580[1].datavalue.value.time < firstClaim.qualifiers.P580[1].datavalue.value.time) then            firstClaim = teamClaims[i]            j = i          else             if (teamClaims[i].qualifiers.P580[1].datavalue.value.time == firstClaim.qualifiers.P580[1].datavalue.value.time and  teamClaims[i].qualifiers and teamClaims[i].qualifiers.P582 and firstClaim.qualifiers and firstClaim.qualifiers.P582) then              if (firstClaim.qualifiers.P1642 or teamClaims[i].qualifiers.P1642) then                if (teamClaims[i].qualifiers.P582[1].datavalue.value.time > firstClaim.qualifiers.P582[1].datavalue.value.time) then                  firstClaim = teamClaims[i]                  j = i                end              else                if (teamClaims[i].qualifiers.P582[1].datavalue.value.time < firstClaim.qualifiers.P582[1].datavalue.value.time) then                  firstClaim = teamClaims[i]                  j = i                end              end            end          end        else          if (teamClaims[i].qualifiers and teamClaims[i].qualifiers.P582 and firstClaim.qualifiers and firstClaim.qualifiers.P580) then            if (teamClaims[i].qualifiers.P582[1].datavalue.value.time <= firstClaim.qualifiers.P580[1].datavalue.value.time) then              firstClaim = teamClaims[i]              j = i            end          else            if (teamClaims[i].qualifiers and teamClaims[i].qualifiers.P582 and firstClaim.qualifiers and firstClaim.qualifiers.P582) then              if (teamClaims[i].qualifiers.P582[1].datavalue.value.time < firstClaim.qualifiers.P582[1].datavalue.value.time) then                firstClaim = teamClaims[i]                j = i              end            else              if (teamClaims[i].qualifiers and teamClaims[i].qualifiers.P580 and firstClaim.qualifiers and firstClaim.qualifiers.P582) then                if (teamClaims[i].qualifiers.P580[1].datavalue.value.time < firstClaim.qualifiers.P582[1].datavalue.value.time) then                  firstClaim = teamClaims[i]                  j = i                end              end            end          end        end      end      table.insert(orderedTeams, firstClaim)      table.remove(teamClaims, j)   end   return orderedTeams end  local function parseISO8601Year(str) local pattern = "(%-?%d+)%-(%d+)%-(%d+)T" local Y, M, D = mw.ustring.match( str, pattern ) return tonumber(Y) end  local function formatFootballCareer( context, options, statement )     local snak = '|'      if (statement.qualifiers and statement.qualifiers.P580 and statement.qualifiers.P582) then         if (statement.qualifiers.P580[1].datavalue          and statement.qualifiers.P582[1].datavalue          and parseISO8601Year(statement.qualifiers.P580[1].datavalue.value.time) == parseISO8601Year(statement.qualifiers.P582[1].datavalue.value.time)) then         snak  = snak ..  parseISO8601Year(statement.qualifiers.P580[1].datavalue.value.time)     else          if (statement.qualifiers.P580[1].datavalue) then         snak  = snak .. parseISO8601Year(statement.qualifiers.P580[1].datavalue.value.time)           end          if (statement.qualifiers.P580[1].datavalue or statement.qualifiers.P582[1].datavalue) then         snak = snak .. '—'           end          if (statement.qualifiers.P582[1].datavalue) then           snak  = snak .. parseISO8601Year(statement.qualifiers.P582[1].datavalue.value.time)           end        end     else        if (statement.qualifiers and statement.qualifiers.P580) then           snak  = snak .. parseISO8601Year(statement.qualifiers.P580[1].datavalue.value.time) .. '—{{0|4}}'        else          if (statement.qualifiers and statement.qualifiers.P582) then             snak = snak .. '{{0|4}}—' .. parseISO8601Year(statement.qualifiers.P582[1].datavalue.value.time)          end        end     end     snak = snak .. ' | '      if (statement.qualifiers and statement.qualifiers.P582) then     options.teamDate = statement.qualifiers.P582[1]     end      snak = snak .. formatEntityId( context, "Q" .. statement.mainsnak.datavalue.value['numeric-id'], options ) .. ' | '      return snak end  function p.formatPropertyP6087( context, options, statement ) 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 out = '{{Спартовая кар’ера'      for i, claim in ipairs(orderByDate(claims)) do       local team = mw.wikibase.getEntityObject( "Q" .. claim.mainsnak.datavalue.value['numeric-id'] )       local WDS = require('Модуль:Сьцьверджаньні Вікізьвестак')       local teamClaims = team.claims       if ( options.teamEntity ) then          teamClaims = WDS.filter(team.claims, 'P31[' .. options.teamEntity .. ']')       end       if (teamClaims[1]) then         local formattedStatement = formatFootballCareer( context, options, claim )         out = out .. formattedStatement        end     end     out = out .. '}}'  mw.log(out)      return options.frame:preprocess(out) end  return p 

Tags:

d:Property:P6087

🔥 Trending searches on Wiki Беларуская (тарашкевіца):

.mmЧорны кот (арганізацыя)Полк імя Кастуся Каліноўскага.frВыруДжозэф Рабінэт БайдэнАтэны.ruПершая Ўстаўная граматаМантывілЎЛацінкаЖамойцьІгнат ДамейкаGoogleКарл V МудрыЖалезаГабрэіНобэлеўская прэмія ў галіне літаратуры1853Нямецкая моваЯзэп ЛёсікЯн ЧачотБог.mk.cg.td1905Партыя аматараў піваНадвор’е.suАльтэрнатыўны рокВясна (цэнтар).bzЗавайцьКлуж-НапокаМанчэстэр Сіці.alАнаплязма2008.aw38.kpФЗьвяздаРасейская моваГадуцішкіВільбутФранцішак Багушэвіч.euЧасьціцаОйча наш.bfМінейка (імя).mcГанус (імя).ckНароўляСанкт-ПецярбургБарбароўМараньнёнŠyba 481918PdfЗлучаныя Штаты Амэрыкі1304Гісторыя ад заснаваньня гораду.toЭліза Ажэшка🡆 More