Différences entre versions de « Module:LinkedWikiTestInfobox »

De Gregorius 3.0
Sauter à la navigation Sauter à la recherche
(Page créée avec « --[[ -- Debug console frame = mw.getCurrentFrame() -- Get a frame object newFrame = frame:newChild{ -- Get one with args title = 'Chain RamanEvolution' , args = {... »)
 
 
(4 versions intermédiaires par 2 utilisateurs non affichées)
Ligne 2 : Ligne 2 :
 
-- Debug console
 
-- Debug console
  
frame = mw.getCurrentFrame() -- Get a frame object
+
mw.log(p.tests() )
newFrame = frame:newChild{ -- Get one with args
 
title = 'Chain RamanEvolution' ,
 
args = {
 
    Title = 'Chain RamanEvolution' ,
 
    ['Pilote process'] = 'Sana Tfaili' ,
 
    Email = 'sana.tfaili@u-psud.fr' ,
 
    Website ='' ,
 
    Keywords = '[https://www.wikidata.org/wiki/Special:GoToLinkedPage/enwiki/Q862228 Raman spectroscopy]' ,
 
    Picture = 'http://www.horiba.com/typo3temp/pics/e2f0ca2913.jpg' ,
 
    Latitude = '48.7623' ,
 
    Longitude = '2.27359' ,
 
    Organisation = 'Lip(Sys)2'
 
    }
 
}
 
mw.log(p.infobox( newFrame ) )
 
 
]]
 
]]
  
 
local p = {}
 
local p = {}
  
function p.infobox(f)
+
function p.tests(f)
 +
local html = ''
 +
 
local capiunto = require 'capiunto'
 
local capiunto = require 'capiunto'
    local linkedwiki = require 'linkedwiki'
+
local linkedwiki = require 'linkedwiki'
    local linkedwiki2 = require 'linkedwiki'
+
local linkedwiki2 = require 'linkedwiki'
    local linkedwiki3 = require 'linkedwiki'
+
local linkedwiki3 = require 'linkedwiki'
    local linkedwiki4 = require 'linkedwiki'
+
local linkedwiki4 = require 'linkedwiki'
 +
local linkedwiki5 = require 'linkedwiki'
 +
    linkedwiki.setCurrentFrame(mw.getCurrentFrame()) -- added by hand
 +
    linkedwiki2.setCurrentFrame(mw.getCurrentFrame()) -- added by hand
 +
    linkedwiki3.setCurrentFrame(mw.getCurrentFrame()) -- added by hand
 +
    linkedwiki4.setCurrentFrame(mw.getCurrentFrame()) -- added by hand
 +
    linkedwiki5.setCurrentFrame(mw.getCurrentFrame()) -- added by hand
 
      
 
      
 
local endpointUpsud = 'https://opendata1.opendata.u-psud.fr/sparql'
 
local endpointUpsud = 'https://opendata1.opendata.u-psud.fr/sparql'
Ligne 37 : Ligne 30 :
 
   local xsd = 'http://www.w3.org/2001/XMLSchema#'
 
   local xsd = 'http://www.w3.org/2001/XMLSchema#'
 
   local test = 'http://LinkedWiki.org/'
 
   local test = 'http://LinkedWiki.org/'
 
+
   local wdt = 'http://www.wikidata.org/prop/direct/'  
 
 
   local html = ''
 
  
 
   html = html .."TEST : WITHOUT CONFIG only with an endpoint" .. '\n'
 
   html = html .."TEST : WITHOUT CONFIG only with an endpoint" .. '\n'
 
   linkedwiki.setEndpoint(endpointUpsud)
 
   linkedwiki.setEndpoint(endpointUpsud)
  linkedwiki.setDebug(true)
+
   
   -- linkedwiki.setSubject(linkedwiki.getCurrentIRI())
+
   --linkedwiki.setDebug(true)
 
 
 
    
 
    
 
   local subjectForTest = 'http://daap.eu/wiki/Lip(Sys)2/Chain_RamanEvolution'
 
   local subjectForTest = 'http://daap.eu/wiki/Lip(Sys)2/Chain_RamanEvolution'
 
     linkedwiki.setSubject(subjectForTest)
 
     linkedwiki.setSubject(subjectForTest)
 +
   
 +
  --linkedwiki.setDebug(true)
 
   html = html .."Subject :" .. subjectForTest  .. '\n'
 
   html = html .."Subject :" .. subjectForTest  .. '\n'
 
   html = html .."linkedwiki.getString(rdfs..'label') :" .. linkedwiki.getString(rdfs..'label')  .. '\n'
 
   html = html .."linkedwiki.getString(rdfs..'label') :" .. linkedwiki.getString(rdfs..'label')  .. '\n'
Ligne 60 : Ligne 52 :
 
    
 
    
 
   linkedwiki2.setEndpoint(endpointUpsud)
 
   linkedwiki2.setEndpoint(endpointUpsud)
   linkedwiki2.setDebug(true)
+
   --linkedwiki2.setDebug(true)
 
   linkedwiki2.setLang('fr')
 
   linkedwiki2.setLang('fr')
 
   local subjectForTest2 = 'http://daap.eu/wiki/Lip(Sys)2/Near-infrared_Spectroscopy'
 
   local subjectForTest2 = 'http://daap.eu/wiki/Lip(Sys)2/Near-infrared_Spectroscopy'
Ligne 82 : Ligne 74 :
 
     linkedwiki4.setConfig() --bydefault
 
     linkedwiki4.setConfig() --bydefault
 
    
 
    
   linkedwiki4.setDebug(true)
+
   --linkedwiki4.setDebug(true)
 
   linkedwiki4.setSubject(test..'Subject')
 
   linkedwiki4.setSubject(test..'Subject')
 
   html = html .."test..'property4'->http://LinkedWiki.org/iri :" .. linkedwiki4.addPropertyWithIri(test..'property4',test..'iri')  .. '\n'
 
   html = html .."test..'property4'->http://LinkedWiki.org/iri :" .. linkedwiki4.addPropertyWithIri(test..'property4',test..'iri')  .. '\n'
 
   html = html .."test..'property4' :" .. linkedwiki4.getValue(test..'property4')  .. '\n'
 
   html = html .."test..'property4' :" .. linkedwiki4.getValue(test..'property4')  .. '\n'
 
    
 
    
html = html .."test..'property5'-> \"\"\"text\"\"\" :" .. linkedwiki4.addPropertyWithLitteral(test..'property5', "text",nil,'')  .. '\n'
+
html = html .."test..'property5'-> \"\"\"text\"\"\" :" .. linkedwiki4.addPropertyWithLitteral(test..'property5', "text",nil,'')  .. '\n'
  html = html .."test..'property5 :" .. linkedwiki4.getValue(test..'property5')  .. '\n'
+
html = html .."test..'property5 :" .. linkedwiki4.getValue(test..'property5')  .. '\n'
html = html .."test..'property6'-> \"\"\"text\"\"\"@fr :" .. linkedwiki4.addPropertyWithLitteral(test..'property6', "text",nil)  .. '\n'
+
html = html .."test..'property6'-> \"\"\"text\"\"\"@fr :" .. linkedwiki4.addPropertyWithLitteral(test..'property6', "text",nil)  .. '\n'
  html = html .."test..'property6 :" .. linkedwiki4.getValue(test..'property6')  .. '\n'
+
html = html .."test..'property6 :" .. linkedwiki4.getValue(test..'property6')  .. '\n'
html = html .."test..'property7'-> \"\"\"text\"\"\"@fr :".. linkedwiki4.addPropertyWithLitteral(test..'property7', "text")  .. '\n'
+
html = html .."test..'property7'-> \"\"\"text\"\"\"@fr :".. linkedwiki4.addPropertyWithLitteral(test..'property7', "text")  .. '\n'
  html = html .."test..'property7 :" .. linkedwiki4.getValue(test..'property7')  .. '\n'
+
html = html .."test..'property7 :" .. linkedwiki4.getValue(test..'property7')  .. '\n'
html = html .."test..'property8'-> 2 :" .. linkedwiki4.addPropertyWithLitteral(test..'property8', 2,nil,'')  .. '\n'
+
html = html .."test..'property8'-> 2 :" .. linkedwiki4.addPropertyWithLitteral(test..'property8', 2,nil,'')  .. '\n'
  html = html .."test..'property8 :" .. linkedwiki4.getValue(test..'property8')  .. '\n'
+
html = html .."test..'property8 :" .. linkedwiki4.getValue(test..'property8')  .. '\n'
html = html .."test..'property9'-> 2.1 :" .. linkedwiki4.addPropertyWithLitteral(test..'property9', 2.1,nil,'')  .. '\n'
+
html = html .."test..'property9'-> 2.1 :" .. linkedwiki4.addPropertyWithLitteral(test..'property9', 2.1,nil,'')  .. '\n'
  html = html .."test..'property9 :" .. linkedwiki4.getValue(test..'property9')  .. '\n'
+
html = html .."test..'property9 :" .. linkedwiki4.getValue(test..'property9')  .. '\n'
html = html .."test..'property10'-> \"\"\"2.2\"\"\"^^<http://www.w3.org/2001/XMLSchema#decimal> :" .. linkedwiki4.addPropertyWithLitteral(test..'property10', "2.2",xsd.."decimal",'')  .. '\n'
+
html = html .."test..'property10'-> \"\"\"2.2\"\"\"^^<http://www.w3.org/2001/XMLSchema#decimal> :" .. linkedwiki4.addPropertyWithLitteral(test..'property10', "2.2",xsd.."decimal",'')  .. '\n'
  html = html .."test..'property10 :" .. linkedwiki4.getValue(test..'property10')  .. '\n'
+
html = html .."test..'property10 :" .. linkedwiki4.getValue(test..'property10')  .. '\n'
 
+
html = html .."Delete all properties of subject :" .. linkedwiki4.removeSubject()  .. '\n'
+
html = html .."Delete all properties of subject :" .. linkedwiki4.removeSubject()  .. '\n'
  html = html .."test..'property10 (empty is ok)" .. linkedwiki4.getValue(test..'property10')  .. '\n'
+
html = html .."test..'property10 (empty is ok)" .. linkedwiki4.getValue(test..'property10')  .. '\n'
 +
 +
html = html .."TEST : WITH CONFIG of Wikidata " .. '\n'
  
--[[  html = html .."linkedwiki4.getValue(test..'property2') :" .. linkedwiki4.getValue(test..'property2')  .. '\n'
 
  
   html = html .."linkedwiki4.setIri(test..'property3') :" .. linkedwiki4.addPropertyWithLitteral(test..'property3', "text" , xsd.."string") .. '\n'
+
   linkedwiki5.setConfig('http://www.wikidata.org')
   html = html .."linkedwiki4.getValue(test..'property3') :" .. linkedwiki4.getValue(test..'property3') .. '\n'
+
  --linkedwiki5.setDebug(true)
  ]]
+
   linkedwiki5.setSubject('http://www.wikidata.org/entity/Q132845')
 
    
 
    
 +
  local values = linkedwiki5.getValue(wdt..'P39')
 +
    local listValue = linkedwiki.explode(";",values)
 +
    for i, value in ipairs(listValue) do
 +
    html = html .."P39 -> :" .. value  .. '\n'
 +
    html = html .."P39 label -> :" .. linkedwiki5.getString(rdfs..'label',nil,value)  .. '\n'
 +
    end
 +
   
 
   return html
 
   return html
 
end
 
end
 
   
 
   
 
return p
 
return p

Version actuelle datée du 29 octobre 2021 à 09:29

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

--[[
-- Debug console

mw.log(p.tests() )
]]

local p = {}

function p.tests(f)
	local html = ''
	
	local capiunto = require 'capiunto'
	local linkedwiki = require 'linkedwiki'
	local linkedwiki2 = require 'linkedwiki'
	local linkedwiki3 = require 'linkedwiki'
	local linkedwiki4 = require 'linkedwiki'
	local linkedwiki5 = require 'linkedwiki'
    linkedwiki.setCurrentFrame(mw.getCurrentFrame()) -- added by hand
    linkedwiki2.setCurrentFrame(mw.getCurrentFrame()) -- added by hand
    linkedwiki3.setCurrentFrame(mw.getCurrentFrame()) -- added by hand
    linkedwiki4.setCurrentFrame(mw.getCurrentFrame()) -- added by hand
    linkedwiki5.setCurrentFrame(mw.getCurrentFrame()) -- added by hand
    
	local endpointUpsud = 'https://opendata1.opendata.u-psud.fr/sparql'
	
   local rdfs = 'http://www.w3.org/2000/01/rdf-schema#'
   local daapProp = 'http://daap.eu/wiki/Property:'
   local geo = 'http://www.w3.org/2003/01/geo/wgs84_pos#'
   local vcard = 'http://www.w3.org/2006/vcard/ns#'
   local xsd = 'http://www.w3.org/2001/XMLSchema#'
   local test = 'http://LinkedWiki.org/'
   local wdt = 'http://www.wikidata.org/prop/direct/' 

   html = html .."TEST : WITHOUT CONFIG only with an endpoint" .. '\n'
   linkedwiki.setEndpoint(endpointUpsud)
    
   --linkedwiki.setDebug(true)
   
   local subjectForTest = 'http://daap.eu/wiki/Lip(Sys)2/Chain_RamanEvolution'
    linkedwiki.setSubject(subjectForTest)
    
   --linkedwiki.setDebug(true)
   html = html .."Subject :" .. subjectForTest  .. '\n'
   html = html .."linkedwiki.getString(rdfs..'label') :" .. linkedwiki.getString(rdfs..'label')  .. '\n'
   html = html .."linkedwiki.getString(rdfs..'label','en') :" .. linkedwiki.getString(rdfs..'label','en')  .. '\n'
   html = html .."linkedwiki.getString(rdfs..'label','fr') :" .. linkedwiki.getString(rdfs..'label','fr')  .. '\n'
   html = html .."linkedwiki.getString(rdfs..'label','') (ok when empty) :" .. linkedwiki.getString(rdfs..'label','')  .. '\n'
   
   html = html .."linkedwiki.getValue(geo..'lat') :" .. linkedwiki.getValue(geo..'lat')  .. '\n'
   
   html = html .."linkedwiki.getValue(daapProp..'picture') :" .. linkedwiki.getValue(daapProp..'picture')  .. '\n'
   
   linkedwiki2.setEndpoint(endpointUpsud)
   --linkedwiki2.setDebug(true)
   linkedwiki2.setLang('fr')
   local subjectForTest2 = 'http://daap.eu/wiki/Lip(Sys)2/Near-infrared_Spectroscopy'
    linkedwiki.setSubject(subjectForTest2)
   html = html .."Subject2 :" .. subjectForTest  .. '\n'
   html = html .."linkedwiki2.getString(rdfs..'label') :" .. linkedwiki2.getString(rdfs..'label')  .. '\n'
   
   
   html = html .."TEST : WITHOUT CONFIG only with an endpoint and a graph" .. '\n'
   linkedwiki3.setEndpoint(endpointUpsud)
    linkedwiki3.setSubject(subjectForTest)
    linkedwiki3.setGraph('http://daap.eu')
   html = html .."Subject :" .. subjectForTest  .. '\n'
   html = html .."linkedwiki3.getString(rdfs..'label') :" .. linkedwiki3.getString(rdfs..'label')  .. '\n'
   html = html .."linkedwiki3.getString(rdfs..'label','en') :" .. linkedwiki3.getString(rdfs..'label','en')  .. '\n'
   html = html .."linkedwiki3.getString(rdfs..'label','fr') :" .. linkedwiki3.getString(rdfs..'label','fr')  .. '\n'
   html = html .."linkedwiki3.getString(rdfs..'label','') (ok when empty) :" .. linkedwiki3.getString(rdfs..'label','')  .. '\n'
   
   html = html .."TEST : WITH CONFIG " .. '\n'
    
    linkedwiki4.setConfig() --bydefault
   
   --linkedwiki4.setDebug(true)
   linkedwiki4.setSubject(test..'Subject')
   html = html .."test..'property4'->http://LinkedWiki.org/iri :" .. linkedwiki4.addPropertyWithIri(test..'property4',test..'iri')  .. '\n'
   html = html .."test..'property4' :" .. linkedwiki4.getValue(test..'property4')  .. '\n'
   
	html = html .."test..'property5'-> \"\"\"text\"\"\" :" .. linkedwiki4.addPropertyWithLitteral(test..'property5', "text",nil,'')  .. '\n'
	html = html .."test..'property5 :" .. linkedwiki4.getValue(test..'property5')  .. '\n'
	html = html .."test..'property6'-> \"\"\"text\"\"\"@fr :" .. linkedwiki4.addPropertyWithLitteral(test..'property6', "text",nil)  .. '\n'
	html = html .."test..'property6 :" .. linkedwiki4.getValue(test..'property6')  .. '\n'
	html = html .."test..'property7'-> \"\"\"text\"\"\"@fr :".. linkedwiki4.addPropertyWithLitteral(test..'property7', "text")  .. '\n'
	html = html .."test..'property7 :" .. linkedwiki4.getValue(test..'property7')  .. '\n'
	html = html .."test..'property8'-> 2 :" .. linkedwiki4.addPropertyWithLitteral(test..'property8', 2,nil,'')  .. '\n'
	html = html .."test..'property8 :" .. linkedwiki4.getValue(test..'property8')  .. '\n'
	html = html .."test..'property9'-> 2.1 :" .. linkedwiki4.addPropertyWithLitteral(test..'property9', 2.1,nil,'')  .. '\n'
	html = html .."test..'property9 :" .. linkedwiki4.getValue(test..'property9')  .. '\n'
	html = html .."test..'property10'-> \"\"\"2.2\"\"\"^^<http://www.w3.org/2001/XMLSchema#decimal> :" .. linkedwiki4.addPropertyWithLitteral(test..'property10', "2.2",xsd.."decimal",'')  .. '\n'
	html = html .."test..'property10 :" .. linkedwiki4.getValue(test..'property10')  .. '\n'
	
	html = html .."Delete all properties of subject :" .. linkedwiki4.removeSubject()  .. '\n'
	html = html .."test..'property10 (empty is ok)" .. linkedwiki4.getValue(test..'property10')  .. '\n'
	
html = html .."TEST : WITH CONFIG of Wikidata " .. '\n'


   linkedwiki5.setConfig('http://www.wikidata.org')
   --linkedwiki5.setDebug(true)
   linkedwiki5.setSubject('http://www.wikidata.org/entity/Q132845')
   
   local values = linkedwiki5.getValue(wdt..'P39')
    local listValue = linkedwiki.explode(";",values)
    for i, value in ipairs(listValue) do
	    html = html .."P39 -> :" .. value  .. '\n'
	    html = html .."P39 label -> :" .. linkedwiki5.getString(rdfs..'label',nil,value)  .. '\n'
    end 
    	
   return html
end
 
return p