Module:Etablissement

De ESCR
Aller à la navigation Aller à la recherche

La documentation pour ce module peut être créée à Module:Etablissement/doc

local p = {}

--[[ For test
frame = mw.getCurrentFrame() -- Get a frame object
newFrame = frame:newChild{ -- Get one with args
	title = 'Dupond Bertrand' ,
	 args = {
		iri = 'https://data.escr.fr/wiki/Lycée_Le_Corbusier' ,
		["label"] = 'Lycée Le Corbusier' ,
		["titre"] = 'Le Corbusier' ,
		["activité"] = 'Lycée' ,
		["adresse"] = '88 Rue de Villiers, 78300 Poissy' ,
		["latitude"] = '48.923503',
		["longitude"] = '2.026752',
		["site Web"] = 'http://www.lyc-lecorbusier-poissy.ac-versailles.fr',
		["demo"] = '1'
	    }
}
mw.log(p.infobox( newFrame ) )
--]]

function p.infobox(f)
    local capiunto = require 'capiunto'
    local linkedwiki = require 'linkedwiki'
    
	linkedwiki.setCurrentFrame(mw.getCurrentFrame())
	
    -- init the prefix
    local escr = 'https://data.escr.fr/wiki/Data:'
    
    local rdf = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'
    local rdfs = 'http://www.w3.org/2000/01/rdf-schema#'
    local geo = 'http://www.opengis.net/ont/geosparql#'
    
    local xsd = 'http://www.w3.org/2001/XMLSchema#'
    local wdt = 'http://www.wikidata.org/prop/direct/'
    local wd = 'http://www.wikidata.org/entity/'
    local p = 'http://www.wikidata.org/prop/'
    local pq = 'http://www.wikidata.org/prop/qualifier/'
    local ps = 'http://www.wikidata.org/prop/statement/'

    local dateFormat = "d M Y"

    local subject = f.args.iri or linkedwiki.getCurrentIRI();  --find the iri of the current page

    local object = linkedwiki.new(subject,"https://data.escr.fr/data")

   if linkedwiki.isEmpty(f.args['demo']) then
	    --object:setDebug(true)
	    object:removeSubject() -- delete all triples of this subject
		-- Save the data in the infobox in a knowledge base
	    mw.log(object:addPropertyWithIri(rdf .. 'type', escr .. 'Etablissement'))
	    
	    if f.args["activité"] == "Lycée" then mw.log(object:addPropertyWithIri(rdf .. 'type', escr .. 'Etablissement'..'#Lycée'))
    	elseif f.args["activité"] == "Université" then mw.log(object:addPropertyWithIri(rdf .. 'type', escr .. 'Etablissement'..'#Université'))
    	elseif f.args["activité"] == "Ecole supérieure" then mw.log(object:addPropertyWithIri(rdf .. 'type', escr .. 'Etablissement'..'#EcoleSupérieure'))
    	end
    	
    	mw.log(object:addPropertyString(rdfs .. 'label', f.args['label']))
    	mw.log(object:addProperty( escr .. 'Etablissement'..'#géolocalisation', 'Point('..f.args['longitude']..' '..f.args['latitude']..')', geo .. 'wktLiteral', ''))
    	mw.log(object:addPropertyWithIri( escr .. 'Etablissement'..'#siteWeb', f.args['site Web']))
  
    end

    --Make infobox with capiunto
    local infobox = capiunto.create({
        --bodyStyle = 'width : 50px',
        -- bodyClass = 'gregoriusPape',
        title = f.args['activité'],
        -- top = objWikidata:checkString(rdfs .. 'label', f.args.Titre),
        top = f.args.titre,
        topStyle = 'background: #dfedff;  font-size: 1.4em; padding: 15px;'
    })

    infobox:addWikitext(f.args['adresse'])
    infobox:addRow('géolocalisation', f.args['latitude']..','..f.args['longitude'])
    infobox:addRow('site Web', f.args['site Web'])
    return infobox
end

return p