Zum Inhalt springen

Modul:Wikidata utilities: Unterschied zwischen den Versionen

fw -> wu; +function wu.addProperty( p )
(Datum)
(fw -> wu; +function wu.addProperty( p ))
Zeile 1: Zeile 1:
-- Wikidata convenience utilities
-- documentation
-- documentation
local FastWikidata = {
local FastWikidata = {
suite  = 'FastWikidata',
suite  = 'FastWikidata',
serial = '2020-08-13',
serial = '2020-09-26',
item  = 65439025
item  = 65439025
}
}


-- module variable
-- module variable
local fw = {}
local wu = {}


-- table storing property ids used
-- table storing property ids used
Zeile 14: Zeile 16:
}
}


function fw.getEntity( id )
function wu.getEntity( id )
local wrongQualifier = false
local wrongQualifier = false
local entity = nil
local entity = nil
Zeile 34: Zeile 36:
end
end


function fw.getEntityId( id )
function wu.getEntityId( id )
local wrongQualifier = false
local wrongQualifier = false
local entity = nil
local entity = nil
Zeile 54: Zeile 56:
end
end


function fw.getLabel( entity, lang )
function wu.getLabel( entity, lang )
local isString = type( entity ) == 'string'
local isString = type( entity ) == 'string'
if not entity or ( isString and entity == '' ) then
if not entity or ( isString and entity == '' ) then
Zeile 74: Zeile 76:
end
end


function fw.getSitelink( entity, globalSiteId )
function wu.getSitelink( entity, globalSiteId )
local isString = type( entity ) == 'string'
local isString = type( entity ) == 'string'
if not entity or ( isString and entity == '' ) then
if not entity or ( isString and entity == '' ) then
Zeile 128: Zeile 130:
end
end


function fw.getBestStatements( entity, p )
function wu.getBestStatements( entity, p )
if type( entity ) == 'string' then
if type( entity ) == 'string' then
return mw.wikibase.getBestStatements( entity, p )
return mw.wikibase.getBestStatements( entity, p )
Zeile 136: Zeile 138:
end
end


function fw.getStatements( entity, p, count )
function wu.getStatements( entity, p, count )
local ar = {}
local ar = {}
if not entity or entity == '' then
if not entity or entity == '' then
Zeile 142: Zeile 144:
end
end


local statements = fw.getBestStatements( entity, p )
local statements = wu.getBestStatements( entity, p )


count = count or #statements
count = count or #statements
Zeile 163: Zeile 165:
end
end


function fw.getValue( entity, p )
function wu.getValue( entity, p )
local value = ''
local value = ''
if entity and entity ~= '' and p and p ~= '' then
if entity and entity ~= '' and p and p ~= '' then
value = getFirstValue( fw.getBestStatements( entity, p ) )
value = getFirstValue( wu.getBestStatements( entity, p ) )
if value then
if value then
catTable[ p ] = ''
catTable[ p ] = ''
Zeile 176: Zeile 178:
end
end


function fw.getId( entity, p )
function wu.getId( entity, p )
local value = ''
local value = ''
if entity and entity ~= '' and p and p ~= '' then
if entity and entity ~= '' and p and p ~= '' then
value = getFirstValue( fw.getBestStatements( entity, p ) )
value = getFirstValue( wu.getBestStatements( entity, p ) )
if value then
if value then
catTable[ p ] = ''
catTable[ p ] = ''
Zeile 190: Zeile 192:
end
end


function fw.getValues( entity, p, count )
function wu.getValues( entity, p, count )
local values = ''
local values = ''
if entity and entity ~= '' and p and p ~= '' then
if entity and entity ~= '' and p and p ~= '' then
local statements = fw.getBestStatements( entity, p )
local statements = wu.getBestStatements( entity, p )
values = getNValues( statements, count or #statements )
values = getNValues( statements, count or #statements )
if #values > 0 then
if #values > 0 then
Zeile 202: Zeile 204:
end
end


function fw.getValuesByLang( entity, p, count, lang )
function wu.getValuesByLang( entity, p, count, lang )
local ar = ''
local ar = ''
if entity and entity ~= '' and p and p ~= '' then
if entity and entity ~= '' and p and p ~= '' then
local statements = fw.getBestStatements( entity, p )
local statements = wu.getBestStatements( entity, p )
ar = {}
ar = {}
count = count or #statements
count = count or #statements
Zeile 228: Zeile 230:
end
end


function fw.getValuesWithQualifierIds( entity, p, qualifierP, defaultId )
function wu.getValuesWithQualifierIds( entity, p, qualifierP, defaultId )
local result = {}
local result = {}
if entity and entity ~= '' and p and p ~= '' and qualifierP and qualifierP ~= '' then
if entity and entity ~= '' and p and p ~= '' and qualifierP and qualifierP ~= '' then
local statements = fw.getStatements( entity, p, nil )
local statements = wu.getStatements( entity, p, nil )
if #statements > 0 then
if #statements > 0 then
-- defaultId is used if a qualifier is missing
-- defaultId is used if a qualifier is missing
Zeile 260: Zeile 262:


-- get values array for monolingual text
-- get values array for monolingual text
function fw.getValuesWithLanguages( entity, p )
function wu.getValuesWithLanguages( entity, p )
local result = {}
local result = {}
if entity and entity ~= '' and p and p ~= '' then
if entity and entity ~= '' and p and p ~= '' then
local statements = fw.getStatements( entity, p, nil )
local statements = wu.getStatements( entity, p, nil )
local hyphen, lng, value
local hyphen, lng, value
if #statements > 0 and statements[ 1 ].mainsnak.datatype == 'monolingualtext' then
if #statements > 0 and statements[ 1 ].mainsnak.datatype == 'monolingualtext' then
Zeile 304: Zeile 306:


-- The following function is an experimental one, not for extensive use
-- The following function is an experimental one, not for extensive use
function fw.getValuesWithQualifiers( entity, p, qualifiers, count )
function wu.getValuesWithQualifiers( entity, p, qualifiers, count )
local result = {}
local result = {}
local statements = fw.getStatements( entity, p, count )
local statements = wu.getStatements( entity, p, count )
if #statements == 0 then
if #statements == 0 then
return result
return result
Zeile 352: Zeile 354:
end
end


function fw.getAliases( entity, lang )
function wu.getAliases( entity, lang )
if type( entity ) == 'string' then -- is Q id
if type( entity ) == 'string' then -- is Q id
entity = mw.wikibase.getEntity( entity )
entity = mw.wikibase.getEntity( entity )
Zeile 368: Zeile 370:
end
end


function fw.getCategories( formatStr )
-- maintenance utilities
function wu.addProperty( p )
catTable[ p ] = ''
end
 
function wu.getCategories( formatStr )
local result = ''
local result = ''


Zeile 382: Zeile 389:
end
end


return fw
return wu
Anonymer Benutzer