Tämä moduuli on osittain suojattu muutoksilta.

Moduuli:Puuttuvat Wikidata-ominaisuudet

Wikipediasta
Siirry navigaatioon Siirry hakuun


local p = {}
props={"P31", "P17", "P131",  "P279", "P6375", "P669", "P281", "P625" }

--local wd = require( 'Module:Fr:Interface Wikidata' ).fromLua

-- Print p as json
local function dumpJson(p)
    return mw.text.jsonEncode(p)
end

-- Read arguments as flat array
local function parseArgs(frame)
	local args = {}
	for key, value in pairs(frame:getParent().args) do args[key] = value end
	for key, value in pairs(frame.args) do args[key] = value end
	return args
end

function p.testIfEntityExists(frame)
   local entity_id = frame.args.entity or "";

   if entity_id == "" then
       return mw.wikibase.getEntityIdForCurrentPage();
   elseif mw.wikibase.entityExists(entity_id) then
       return entity_id 
   end

   return ""
end

local function testPostalCode(entity_id, s)
   local postal_code = wd.formatStatements{ entity = entity_id, property = "P281", link="-"}
   if postal_code then
      if string.find(s, postal_code) then
           return true
      end
   end
   return false
end 


local function testProp(entity_id, prop)
   local claims=mw.wikibase.getBestStatements(entity_id, prop)
   for p, claim in pairs(claims) do
      return true
   end
   return false
end

function p.listDebugProps(frame)
   ret=""
   local lang = mw.getContentLanguage()

   for pp, prop in pairs(props) do
      local catName = "Artikkelit joista puuttuu " .. prop .."-Wikidata ominaisuus"
      local articleCount = lang:formatNum( mw.site.stats.pagesInCategory(catName, 'pages') )
      ret=ret .. "* [[:Luokka:".. catName.. "]]" .. " (" .. articleCount .. ")\n"
   end
   local catName="Artikkelit, joista puuttuu Wikidata-kohde"
   local articleCount = lang:formatNum( mw.site.stats.pagesInCategory(catName, 'pages') )
   ret=ret .. "* [[:Luokka:".. catName.. "]]" .. " (" .. articleCount .. ")\n"

   return ret
end

function p.showProps(frame)
   local wd = require( 'Module:Fr:Interface Wikidata' ).fromLua

   args=parseArgs(frame)
   local entity_id = args['entity_id'] or mw.wikibase.getEntityIdForCurrentPage()
   local ret=""

   for pp, prop in pairs(props) do
      local s = ""
      if prop=="P625" then
         s="P625 skipped (bug)"
      else
         s=wd.formatStatements{ entity = entity_id, property = prop, link="-"}
      end
      if s then
          propLabel = mw.wikibase.getLabel( prop )
          ret=ret .. "* '''" .. propLabel .. "''': ".. s .."\n"
      end
   end
   return ret
end

function p.testProps(frame)
   args=parseArgs(frame)
   local entity_id = args['entity_id'] or mw.wikibase.getEntityIdForCurrentPage()
   ret=""

   if not entity_id or entity_id=="" then
       return "[[luokka:artikkelit, joista puuttuu Wikidata-kohde]]"
   end
  
   props_found={}
   for pp, prop in pairs(props) do
      props_found[prop]=false
   end

   for pp, prop in pairs(props) do
      if testProp(entity_id, prop) then
         props_found[prop]=true
      end
   end

   for pp, prop in pairs(props) do
      if not props_found[prop] then
          -- Add category for missing property for street and postal number only if an address is defined

          if (prop=="P669" or prop=="P281") and not props_found["P6375"] then
--
          elseif prop=="P279" then
             if not props_found["P31"] then
                ret=ret .. "[[Luokka:Artikkelit joista puuttuu " .. prop .."-Wikidata ominaisuus]]"
             end
          else
             ret=ret .. "[[Luokka:Artikkelit joista puuttuu " .. prop .."-Wikidata ominaisuus]]"
          end
      end
   end

   return ret

--   local country_wd = wd.formatStatements{ entity = entity_id, property = "P17", link="-"}
--   local adm_wd = wd.formatStatements{ entity = entity_id, property = "P131", link="-"}
--   local location_wd = wd.formatStatements{ entity = entity_id, property = "P276", link="-"}

--   local address_wd = wd.formatStatements{ entity = entity_id, property = "P6375", link="-"}
--   local street_wd = wd.formatStatements{ entity = entity_id, property = "P669", link="-"}
--   local postal_code = wd.formatStatements{ entity = entity_id, property = "P281", link="-"}
end
   
return p