Module:Wikidata: Difference between revisions

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search
Content deleted Content added
m cleanup, remove addcat option
move date-related stuff Module:Wikidata/Dates for slightly better readability
Line 7: Line 7:
local tools = require "Module:Wikidata/Tools"
local tools = require "Module:Wikidata/Tools"
local entities = require "Module:Wikidata/FormatEntity"
local entities = require "Module:Wikidata/FormatEntity"
local dates = require "Module:Wikidata/Dates"


--local formatDate = require('Module:Complex date') only loaded when needed to save memory in large pages like Wikidata:List of properties/all
local fb = require('Module:Fallback')
local fb = require('Module:Fallback')
local i18nmessages = mw.loadData('Module:i18n/wikidata')
local i18nmessages = mw.loadData('Module:i18n/wikidata')
Line 77: Line 77:
end
end


-- DATE FUNCTIONS
local function splitTimestamp(timestamp, calendar)
local pattern = "(%W)(%d+)%-(%d+)%-(%d+)"
local era, year, month, day = timestamp:match(pattern)


if calendar == 'julian' then
--todo year, month, day = formatdate.gregorianToJulian( era .. year, month, day )
end

return {day = day, month = month, year = year, era = era, timestamp = timestamp, type = 'dateobject'}
end

local function rangeObject(begin, ending)
local timestamp
if begin then
timestamp = begin.timestamp
elseif ending then
timestamp = ending.timestamp
end
return {begin = begin, ending = ending, timestamp = timestamp, type = 'rangeobject'}
end

local function dateObject(orig, params) -- transforme un snak en un nouvel objet utilisable par Module:Date complexe
if not params then
params = {}
end

local newobj = splitTimestamp(orig.time, orig.calendar) -- initalise l'object en mettant la valeur des dates

newobj.precision = params.precision or orig.precision
newobj.type = 'dateobject'
return newobj
end

local function formatDatepoint(obj, params) -- TO IMPROVE
if not obj then
return nil
end
local formatDate = require('Module:Complex date')
local lang = params.lang or defaultlang
local precision = math.min(obj.precision, params.precision or 15) -- if we don't want to show the value to its full detail
if precision >= 11 then
return formatDate.complex_date{args={date1 = obj.year .. '-' .. obj.month .. '-' .. obj.day, lang= lang}}
elseif precision == 10 then
return formatDate.complex_date{args={date1 = obj.year .. '-' .. obj.month, lang= lang}}
elseif precision == 9 then
return formatDate.complex_date{args={date1 = tostring(obj.year), lang= lang}}
elseif precision == 8 then
return formatDate.complex_date{args={date1 = string.sub(tostring(obj.year), 1, 3) .. '0', lang = lang, precision = 'decade'}}
elseif precision == 7 then
return formatDate.complex_date{args={date1 = string.sub(tostring(obj.year + 100), 1, 2), lang = lang, precision = 'century'}}
end
return nil
end

local function formatDaterange(obj, params) --TODO
local begin = formatDatepoint(obj.begin, params) or ''
local ending = formatDatepoint(obj.ending, params) or ''
return begin .. '-' .. ending
end

local function objectToText(obj, params)
if obj.type == 'dateobject' then
return formatDatepoint(obj, params)
elseif obj.type == 'rangeobject' then
return formatDaterange(obj, params)
end
return nil
end

function p.tableToText(values, params) -- takes a list of already formatted values and make them a text
if not values then
return nil
end
return linguistic.conj(values, params.lang or defaultlang, params.conjtype)--linguistic.conj( values, params.lang, params.conjtype )
end

function p.getDate(obj)
--[[
returns an object containing a timestamp for easy sorting, and other data
possible types of object:
dateobject
{timestamp = string, year = number, month = number, day = number, calendar = string}
rangeobject
{timestamp = string, begin = dateobject, ending = dateobject}
]]--
if not obj then
return nil
end
if type(obj) == 'string' then
obj = p.getEntity(obj)
end

-- if obj is a statement with date, get it
if obj.mainsnak and not isSpecial(obj.mainsnak) and obj.mainsnak.datatype == 'time' then
return dateObject(obj.mainsnak.datavalue.value.time)
end

-- else preload relevant data
local qualifs = obj.qualifiers -- when obj is a statement, look in qualifiers
local claims = obj.claims -- when obj is an item, look in claims

local pointprop = {'P585', 'P571'} -- dates corresponding to a punctual fact
local beginprop = {'P580', 'P569'} -- start date, birth date == start of a date range
local endingprop = {'P582', 'P570'}

local function getval(prop)
local val
if claims and claims[prop] and not isSpecial(claims[prop][1].mainsnak) then
val = claims[prop][1].mainsnak.datavalue.value
elseif qualifs and qualifs[prop] and not isSpecial(qualifs[prop][1]) then
val = qualifs[prop][1].datavalue.value
end
if val then
return dateObject(val)
end
return nil
end

for i, prop in pairs(pointprop) do
local val = getval(prop)
if val then return val end
end
--if no date has not been found, look for startdate or enddate
local begin, ending
for i, prop in pairs(beginprop) do
begin = getval(prop)
if begin then
break
end
end
for i, prop in pairs(endingprop) do
ending = getval(prop)
if ending then
break
end
end
if begin or ending then
return rangeObject(begin, ending)
end
return nil
end

function p.getFormattedDate(statement, params)
local datetable = p.getDate(statement)
if not datetable then
return nil
end
return objectToText(datetable, params)
end


function p.getRawvalue(snak)
function p.getRawvalue(snak)
Line 281: Line 132:


elseif datatype == 'time' then -- format example: +1809-02-12T00:00:00Z
elseif datatype == 'time' then -- format example: +1809-02-12T00:00:00Z
dates.formatTimeSnak(snak, params)
if displayformat == 'raw' then
return value.time
elseif displayformat == 'year' then
obj = dateObject(value);
return obj.year
elseif displayformat == 'isodate' then
obj = dateObject(value);
return obj.year .. '-' .. obj.month .. '-' .. obj.day
else
return objectToText(dateObject(value), params)
end

elseif datatype == 'globecoordinate' then
elseif datatype == 'globecoordinate' then
-- retourne une table avec clés latitude, longitude, précision et globe à formater par un autre module (à changer ?)
-- retourne une table avec clés latitude, longitude, précision et globe à formater par un autre module (à changer ?)
Line 326: Line 166:
return formatError( 'unknown-datavalue-type', datatype )
return formatError( 'unknown-datavalue-type', datatype )
end
end
end

function p.formatDates(args) -- same as formatStatements, but returns the date associated to the claim rather than the main value
local claims = p.getClaims(args)
if not claims then
return nil
end
local formattedvalues = {}
for i, j in pairs(claims) do
table.insert(formattedvalues, dates.getFormattedDate(j))
end
local val = linguistic.conj(formattedvalues)
return val
end
end


Line 422: Line 275:


if args.showdate then -- when "showdate and p.chronosort are both set, date retrieval is performed twice
if args.showdate then -- when "showdate and p.chronosort are both set, date retrieval is performed twice
local timedata = p.getDate(statement)
local date = p.getFormattedDate(statement, params)
if timedata then
if date then
str = str .. '<small>' .. date ..'</small>'
local formatteddate = objectToText(timedata, args)
formatteddate = linguistic.inparentheses(formatteddate, lang)
str = str .. '<small>' .. formatteddate ..'</small>'
end
end
end
end
Line 545: Line 396:
end
end


function p.tableToText(values, params) -- takes a list of already formatted values and make them a text
function p.getTheDate(args)
if not values then
local claims = p.getClaims(args)
if not claims then
return nil
return nil
end
end
return linguistic.conj(values, params.lang or defaultlang, params.conjtype)--linguistic.conj( values, params.lang, params.conjtype )
local formattedvalues = {}
for i, j in pairs(claims) do
table.insert(formattedvalues, p.getFormattedDate(j))
end
local val = linguistic.conj(formattedvalues)
return val
end
---FONCTIONS depuis le FRAME
function p.getaDate(frame)
return p.getTheDate(frame.args)
end
end


Line 583: Line 424:
end
end


-- obsolete param name
if args.item then
args.entity = args.item
end
-- load entity
-- load entity
args.entity = tools.getEntity(args.entity)
args.entity = tools.getEntity(args.entity)
Line 612: Line 457:
end
end
args = removeBlanks(args)
args = removeBlanks(args)
if args.item then -- obsolete
args.entity = args.item
end
return p.formatStatements( args )
return p.formatStatements( args )
end
end

Revision as of 12:26, 5 May 2016

Lua

CodeDiscussionEditHistoryLinksLink count Subpages:DocumentationTestsResultsSandboxLive code All modules

Module permitting basic data retrieval from Wikidata items, based on mw:Extension:Wikibase Client/Lua

Functions callable from Lua

p.getClaims returns claims in a particular item that match a particular query

  • item (required): its Qid
  • property (required) property that the claims should have
  • qualifier = qualifiers that the statement should have
  • withrank = rank of the statement ; 'preferred', 'normal', 'deprecated' or 'valid' (ie. normal and preferred). By default = preferred.
  • sourceproperty = this property should be used in the source
  • withsource = the source that should be provided in the statement (if sourceproperty is not provided, the property used is stated in (P248))
  • excludespecial = set to true if you do not want to get "novalue" and "somevalue".
  • numval = if you want to set a maximum number of values to be returned
  • sorttype = set to "chronological" to get the statements in chronological order using the start time (P580), end time (P582) and point in time (P585) qualifiers. Set to "inverted" for chronological order. From a Lua module, you can also define your own sorting criteria.
  • showsource = set to "true" if you want the source of the statement to be displayed.

p.formatStatements(args): returns a string containing the statements given in the table args. Same keys as getClaims, plus formatting arguments:

  • lang (required) for the desired language
  • displayformat = the format in which the args should be returned. For example, for a string-type property displayformat = "weblink" returns a formatted weblink.
  • conjtype = the conjunction separating the statements. For example, conj = '<br />' will make a new line between each statement.
  • showqualifiers = the qualifiers that should be shown along with the mainsnak value

p.getLabel get the label of an entity

  • entity = entity ID with its Q or P
  • lang

Functions callable from wikitext

  • p.formatStatementsE same as p.formatStatements, except that "lang" is not required. It is most conveniently used from {{Data}} that takes exactly the same arguments.

Examples

Code Render Comment
{{#invoke:Wikidata|pageId}} Script error: The function "pageId" does not exist. return wikidata q-code for pages connected to wikidata
{{#invoke:Wikidata|getLabel|entity=Q42|link=wikipedia}} Douglas Adams link to wikipedia
{{#invoke:Wikidata|getLabel|entity=Q42|link=wikipedia|format=lc}} Douglas Adams link to wikipedia but shown with lower case
{{#invoke:Wikidata|getLabel|entity=Q42|link=-}} Douglas Adams no links
{{#invoke:Wikidata|getLabel|entity=Q42|link=wikipedia|lang=ja}} ダグラス・アダムズ
{{#invoke:Wikidata|getLabel|entity=Q42|link=wikidata}} Douglas Adams link to wikidata
{{#invoke:Wikidata|getLabel|entity=Q42|link=wikidata|lang=ja}} ダグラス・アダムズ
{{#invoke:Wikidata|getDescription|entity=Q42|link=wikidata|lang=fr}} Lua error at line 330: attempt to call field 'getEntity' (a nil value).
{{#invoke:Wikidata|formatStatementsE|item=Q42|property=p31}} human
{{#invoke:Wikidata|formatStatementsE|item=Q42|property=p31|link=-}} human
{{#invoke:Wikidata|formatStatementsE|item=Q42|property=p31|lang=ja}} ヒト
{{#invoke:Wikidata|formatStatementsE|item=Q42|property=p569}}
{{#invoke:Wikidata|formatStatementsE|item=Q42|property=p569|lang=ja}}
{{#invoke:Wikidata|formatStatementsE|item=Q12418|property=p186}} oil paint and poplar panel
{{#invoke:Wikidata|formatStatementsE|item=Q12418|property=p186|link=-}} oil paint and poplar panel
{{#invoke:Wikidata|formatStatementsE|item=Q12418|property=p186|displayformat=raw}} Q296955 and Q106857865
{{#invoke:Wikidata|formatStatementsE|item=Q12418|property=p186|lang=ja}} 油絵具およびポプラ板
{{#invoke:Wikidata|formatStatementsE|item=Q12418|property=p186|rank=valid}} oil paint, poplar panel and wood rank = "valid" accepts both "preferred" and "normal" values
{{#invoke:Wikidata|formatStatementsE|item=Q12418|property=p186|showqualifiers=p518}} Lua error in Module:Linguistic at line 111: variable 'lang' is not declared. shows the value of the p518 qualifier (if any) in addition to the main value
{{#invoke:Wikidata|formatStatementsE|item=Q83259|property=p669|showqualifiers=p670|delimiter=&#32;}} shows the value of the P670 qualifier (if any) in addition to the main value separated by a space
{{#invoke:Wikidata|formatStatementsE|item=Q12418|property=p186|qualifier=p518}} should only display values that have a p518 qualifier
{{#invoke:Wikidata|formatStatementsE|item=Q12418|property=p186|numval=1}} oil paint returns the number of values numval (priority to those with "rank= preferred", if there are not enough of them, also accepts "rank = normal")
{{#invoke:Wikidata|formatStatementsE|item=Q12418|property=P276|sourceproperty=P854}} Salle des États, Louvre
{{#invoke:Wikidata|formatStatementsE|item=Q11879536|property=P460|withsource=Q1645493}} Lisa del Giocondo
{{#invoke:Wikidata|formatStatementsE|item=Q153|property=P231|showsource=true}} Lua error in Module:Cite at line 110: attempt to call field '_getLabel' (a nil value).
{{#invoke:Wikidata|formatStatementsE|item=Q205309|property=P793|sorttype=inverted}} closure, demolition, renovation, renovation, first match and construction
{{#invoke:Wikidata|formatStatementsE|property=P625|item=Q90|displayformat=latitude}} 48.856666666667 Latitude of Paris
{{#invoke:Wikidata|formatStatementsE|property=P19|item=Q1441042}} Lua error at line 23: attempt to call field '_langSwitch' (a nil value). unknown value
{{#invoke:Wikidata|formatStatementsE|property=P19|item=Q43650835}} Lua error at line 23: attempt to call field '_langSwitch' (a nil value). no value

Code

--script that retrieves basic data stored in Wikidata, for the datamodel, see https://www.mediawiki.org/wiki/Extension:Wikibase_Client/Lua

local p = {}

local linguistic = require('Module:Linguistic')
local selectClaims = require "Module:Wikidata/GetClaims"
local tools = require "Module:Wikidata/Tools"
local entities = require "Module:Wikidata/FormatEntity"
local dates = require "Module:Wikidata/Dates"

local fb = require('Module:Fallback')
local i18nmessages = mw.loadData('Module:i18n/wikidata')

-- Wiki-specific parameters
local defaultlang = mw.getCurrentFrame():preprocess("{{int:lang}}")
local defaultlink = 'wikidata'

local function i18n(str, lang)
	local message = i18nmessages[str]
	if type(message) == 'string' then
		return message
	end
	return fb._langSwitch(message, lang or defaultlang)
end

local function formatError( key, text )
	return error(i18n(key) .. (text or ''))
end

p.getClaims = selectClaims.getClaims

local function removeBlanks(args)
	for i = #args, 1, -1 do
		if (args[i] == '') or (args[i] == '-') then
			table.remove(args, i)
		end
	end
	return args
end

local function formatTheUnknown() -- voir si on peut accorder/adapter l'usage de "inconnu"
	return i18n('somevalue')
end

local function isSpecial(snak)
	return snak.snaktype ~= 'value'
end

local function sameValue(snak, target)
	return not isSpecial(snak) and p.getRawvalue(snak) == target
end

local function showLang(statement, str) -- TODO (not yet in proper format)
	--adds a lang indication at the start of the string, based on data in statement
	local mainsnak = statement.mainsnak
	if isSpecial(mainsnak) then
		return str
	end

	local langlist = {}
	if mainsnak.datavalue.type == 'monolingualtext' then
		langlist = {mainsnak.datavalue.value.language}
	elseif statement.qualifiers and statement.qualifiers.P407 then
		local convertlangcode = mw.loadData('Module:Dictionary/lang codes')
		for i, j in pairs( statement.qualifiers.P407 ) do
			if not isSpecial(j) then
				local val = convertlangcode[j.datavalue.value['numeric-id']]
				table.insert(langlist, val)
			end
		end
	end
	if #langlist == 0 then
		return str
	else
		return '('.. table.concat(langlist) .. ')' .. str
	end
end



function p.getRawvalue(snak)
	return p.getDatavalue(snak, {displayformat = 'raw'})
end


function p.getDatavalue(snak, params)
	if isSpecial(snak) then
		return nil
	end

	if not params then
		params = {}
	end

	local displayformat = params.displayformat
	local datatype = snak.datavalue.type
	local value = snak.datavalue.value

	if datatype == 'wikibase-entityid' then
		if type(displayformat) == 'function' then
			return displayformat(snak, params)
		end
		local prefix = 'Q'
		if snak.datavalue.value["entity-type"] == 'property' then
			prefix = 'P'
		end
		local id = prefix .. tostring(value['numeric-id'])
		if displayformat == 'raw' then
			return id
		elseif displayformat == 'wikidatastyle' then
			return p.showentity(id, params.lang)
		else
			return p.formatEntity(id, params)
		end

	elseif datatype == 'string' then
		local showntext = params.showntext
		if displayformat == 'weblink' then
			if showntext then
				return '[' .. value .. ' ' .. showntext .. ']'
			else
				return value
			end
		end
		if snak.datatype == 'math' and displayformat ~= 'raw' then
			value = mw.getCurrentFrame():extensionTag('math', value)
		end
		if params.urlpattern then
			value = '[' .. mw.ustring.gsub(mw.ustring.gsub(params.urlpattern, '$1', value), ' ', '%%20') .. ' ' .. (showntext or value) .. ']'
		end
		return value

	elseif datatype == 'time' then -- format example: +1809-02-12T00:00:00Z
		dates.formatTimeSnak(snak, params) 
	elseif datatype == 'globecoordinate' then
		-- retourne une table avec clés latitude, longitude, précision et globe à formater par un autre module (à changer ?)
		if displayformat == 'latitude' then
			return value.latitude
		elseif displayformat == 'longitude' then
			return value.longitude
		elseif displayformat == 'qualifier' then
			local coord = require 'Module:Coordinates'
			value.globe = require('Module:Wikidata/Globes')[value.globe]
			value.precision = nil
			return coord._coord(value)
		else
			value.globe = require('Module:Wikidata/Globes')[value.globe] -- transforme l'ID du globe en nom anglais utilisable par geohack
			return value -- note : les coordonnées Wikidata peuvent être utilisée depuis Module:Coordinates. Faut-il aussi autoriser à appeler Module:Coordiantes ici ?
		end

	elseif datatype == 'quantity' then -- todo : gérer les paramètre précision
		if displayformat == 'raw' then
			return tonumber(value.amount)
		else
			local formatNum = require 'Module:Formatnum'
			local number = formatNum.formatNum(value.amount)
			local unit = mw.ustring.match(value.unit, '(Q%d+)')
			if unit then
				number = number .. '&nbsp;' .. p.formatEntity(unit, params)
			end
			return number
		end
	elseif datatype == 'monolingualtext' then
		return '<span lang="' .. value.language .. '">' .. value.text .. '</span>'
	else
		return formatError( 'unknown-datavalue-type', datatype )
	end
end

function p.formatDates(args) -- same as formatStatements, but returns the date associated to the claim rather than the main value
	local claims = p.getClaims(args)
	if not claims then
		return nil
	end
	local formattedvalues = {}
	for i, j in pairs(claims) do
		table.insert(formattedvalues, dates.getFormattedDate(j))
	end
	local val = linguistic.conj(formattedvalues)
	return val
end

function p.stringTable(args) -- like getClaims, but get a list of string rather than a list of snaks, for easier manipulation
	local claims = p.getClaims(args)
	if not claims then
		return nil
	end
	for i, j in pairs(claims) do
		claims[i] = p.formatStatement(j, args)
	end
	return claims
end

local function getQualifiers(statement, qualifs, params)
	if not statement.qualifiers then
		return nil
	end
	local vals = {}
	for i, j in pairs(qualifs) do
		j = string.upper(j)
		if statement.qualifiers[j] then
			local inserted = false
			if statement.qualifiers[j][1].datatype == 'monolingualtext' then
				local in_preferred_lang
				for _, language in pairs(fb.fblist(params.lang or defaultlang)) do
					for _, snak in pairs(statement.qualifiers[j]) do
						if isInLanguage(snak, language) then
							in_preferred_lang = snak
							break
						end
					end
					if in_preferred_lang then
						break
					end
				end
				if in_preferred_lang then
					table.insert(vals, in_preferred_lang)
					inserted = true
				end
			end
			if not inserted then
				for _, snak in pairs(statement.qualifiers[j]) do
					table.insert(vals, snak)
				end
			end
		end
	end
	if #vals == 0 then
		return nil
	end
	return vals
end

function p.getFormattedQualifiers(statement, qualifs, params)
	if not params then params = {} end
	local qualiftable = getQualifiers(statement, qualifs, params)
	if not qualiftable then
		return nil
	end
	for i, j in pairs(qualiftable) do
		local params = params
		if j.datatype == 'globe-coordinate' then
			params.displayformat = 'qualifier'
		end
		qualiftable[i] = p.formatSnak(j, params)
	end
	return linguistic.conj(qualiftable, params.lang or defaultlang)
end

function p.formatStatement( statement, args )
	if not statement.type or statement.type ~= 'statement' then
		return formatError( 'unknown-claim-type', statement.type )
	end
	if not args then args = {} end
	local lang = args.lang or defaultlang
	local str = p.formatSnak( statement.mainsnak, args )
	if args.showlang == true then
		str = showLang(statement, str)
	end

	local qualifs = args.showqualifiers
	if qualifs then
		if type(qualifs) == 'string' then
			qualifs = mw.text.split(qualifs, ',')
		end
		local foundvalues = p.getFormattedQualifiers(statement, qualifs, args)
		if foundvalues then
			if args.delimiter then
				str = str .. args.delimiter .. foundvalues
			else
				str = str .. linguistic.inparentheses(foundvalues, lang)
			end
		end
	end

	if args.showdate then -- when "showdate and p.chronosort are both set, date retrieval is performed twice
		local date = p.getFormattedDate(statement, params)
		if date then
			str = str .. '<small>' .. date ..'</small>'
		end
	end

	if args.showsource and statement.references then
		local cite = require 'Module:Cite'
		local frame = mw.getCurrentFrame()
		local sourcestring = ''
		for i, ref in pairs(statement.references) do
			if ref.snaks.P248 then
				for j, source in pairs(ref.snaks.P248) do
					if not isSpecial(source) then
						local page
						if ref.snaks.P304 and not isSpecial(ref.snaks.P304[1]) then
							page = ref.snaks.P304[1].datavalue.value
						end
						local s = cite.citeitem('Q' .. source.datavalue.value['numeric-id'], lang, page)
						s = frame:extensionTag( 'ref', s )
						sourcestring = sourcestring .. s
					end
				end
			elseif ref.snaks.P854 and not isSpecial(ref.snaks.P854[1]) then
				s = frame:extensionTag( 'ref', p.getDatavalue(ref.snaks.P854[1]) )
				sourcestring = sourcestring .. s
			end
		end
		str = str .. sourcestring
	end
	return str
end

function p.formatSnak(snak, params)
	--local params = params or {} pour faciliter l'appel depuis d'autres modules
	if snak.snaktype == 'value' then
		return p.getDatavalue(snak, params)
	elseif snak.snaktype == 'somevalue' then
		return formatTheUnknown()
	elseif snak.snaktype == 'novalue' then
		return i18n('novalue') --todo
	else
		return formatError( 'unknown-snak-type', snak.snaktype )
	end
end

function p._getDescription(entity, lang)
	if not entity then
		return i18n('no description')
	end
	if type(entity) == "string" and ( (not lang) or (lang == defaultlang) ) then
		return mw.wikibase.description(entity)
	end
	entity = p.getEntity(entity)
	local descriptions = entity.descriptions
	if not descriptions then
		return i18n('no description')
	end
	if descriptions[lang] then
		return descriptions[lang].value
	end
	local langlist = fb.fblist(lang or defaultlang) -- list of fallback languages if no label in the desired language
	for i, lg in pairs(langlist) do
		if descriptions[lg] then
			return descriptions[lg].value
		end
	end
	return i18n('no description')
end

p.formatEntity = entities.formatEntity

function p.getLabel(frame) -- simple for simple templates like {{Q|}}}
	local args = frame.args
	local entity = args.entity
	local lang = args.lang
	if lang == '' then
		lang = defaultlang
	end

	if string.sub(entity, 1, 10) == 'Property:P' then
		entity = string.sub(entity, 10)
	elseif (string.sub(entity, 1, 1) ~= 'P' and string.sub(entity, 1, 1) ~= 'Q') or (not tonumber(string.sub(entity, 2))) then
		return i18n('invalid-id')
	end

	return p.formatEntity(entity, args)
end

function p.formatStatements( args )--Format statements and concat them cleanly
	if args.value == '-' then
		return nil
	end
	--If a value is already set, use it
	if args.value and args.value ~= '' then
		return args.value
	end
	local valuetable = p.stringTable(args)
	return p.tableToText(valuetable, args)
end

function p.showQualifier( args )
	local qualifs = args.qualifiers or args.qualifier
	if type(qualifs) == 'string' then
		qualifs = mw.text.split(qualifs, ',')
	end
	if not qualifs then
		return formatError( 'property-param-not-provided' )
	end
	local claims = p.getClaims(args)
	if not claims then
		return nil
	end
	local str = ''
	for i, j in pairs(claims) do
		local new = p.getFormattedQualifiers(j, qualifs, args) or ''
		str = str .. new
	end
	return str
end

function p.tableToText(values, params) -- takes a list of already formatted values and make them a text
	if not values then
		return nil
	end
	return linguistic.conj(values, params.lang or defaultlang, params.conjtype)--linguistic.conj( values, params.lang, params.conjtype )
end

function p.getQualifier(frame)
	return p.showQualifier(frame.args)
end

function p.getDescription(frame) -- simple for simple templates like {{Q|}}}
	local entity = frame.args.entity
	local lang = frame.args.lang

	return p._getDescription(entity, lang) or i18n('invalid-id')
end

function p.formatStatements( args )--Format statement and concat them cleanly
	if args.value == '-' then
		return nil
	end

	--If a value is already set, use it
	if args.value and args.value ~= '' then
		return args.value
	end

	-- obsolete param name
	if args.item then
		args.entity = args.item
	end
	-- load entity
	args.entity = tools.getEntity(args.entity)

	-- args.grouped: used to prettify output through an intricated function, see fr.wikipedia
	if args.grouped and args.grouped ~= '' then
		args.grouped = false
		-- not activated return p.groupedStatements(args)
	end

	-- get relevant statements and format each of them
	local valuetable = args.valuetable or p.stringTable(args)

	-- concatenate the the right way
	local str = p.tableToText(valuetable, args)

	return str
end

function p.formatStatementsE(frame)
	local args = {}
	if frame == mw.getCurrentFrame() then
		args = frame:getParent().args -- paramètres du modèle appelant (est-ce vraiment une bonne idée ?)
		for k, v in pairs(frame.args) do
			args[k] = v
		end
	else
		args = frame
	end
	args = removeBlanks(args)
	return p.formatStatements( args )
end

return p