Moduuli:Osoite, sijainti ja kunta

Wikipediasta
Siirry navigaatioon Siirry hakuun



local p = {}

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

local function testKatuTieKujaTori(s)
    local needles = { "katu", "tie", "kuja", "tori", "polku" }
    for pp, needle in pairs(needles) do
        if string.find(s, needle) then
           return true
        end
    end 
    return false
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 


function p.testSijainti(frame)
   args=parseArgs(frame)
   local entity_id = args['entity_id'] or mw.wikibase.getEntityIdForCurrentPage()
   local osoite = args['osoite'] or ""
   local sijainti = args['sijainti'] or ""

   if testKatuTieKujaTori(sijainti) then
       return ""
   end

   if testPostalCode(entity_id, sijainti) then
       return ""
   end

   return osoite

--   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