יחידה:WikidataCrossValidation: הבדלים בין גרסאות בדף
מאין תקציר עריכה |
מ 23 גרסאות של הדף wikipedia:he:יחידה:WikidataCrossValidation יובאו |
||
| (13 גרסאות ביניים של 3 משתמשים אינן מוצגות) | |||
| שורה 18: | שורה 18: | ||
--function CrossValidate.crossValidate( wikitext, propertyName, allowMulti, allowNA, entityId, multiSeperator, optionalQualifier, genderAware ) | --function CrossValidate.crossValidate( wikitext, propertyName, allowMulti, allowNA, entityId, multiSeperator, optionalQualifier, genderAware ) | ||
function CrossValidate.crossValidate( wikitext, propertyName, entityId ) | function CrossValidate.crossValidate( wikitext, propertyName, entityId ) | ||
if wikitext == nil or wikitext == '-' or #wikitext ==0 then | if wikitext == nil or wikitext == '-' or #wikitext ==0 or propertyName ==nil or #propertyName==0 then | ||
return CrossValidate.CrossValidateResult.INVALID_WIKITEXT -- comparing to null wikitext is meaningless | return CrossValidate.CrossValidateResult.INVALID_WIKITEXT -- comparing to null wikitext is meaningless | ||
end | end | ||
| שורה 25: | שורה 25: | ||
entityId = mw.wikibase.getEntityIdForCurrentPage() | entityId = mw.wikibase.getEntityIdForCurrentPage() | ||
end | end | ||
if entityId ==nil then | if entityId == nil then | ||
if mw.title.getCurrentTitle().namespace==0 then | if mw.title.getCurrentTitle().namespace==0 then | ||
return CrossValidate.CrossValidateResult.MISSING_WIKIDATA | return CrossValidate.CrossValidateResult.MISSING_WIKIDATA | ||
| שורה 31: | שורה 31: | ||
return CrossValidate.CrossValidateResult.INVALID_WIKITEXT | return CrossValidate.CrossValidateResult.INVALID_WIKITEXT | ||
end | end | ||
end | |||
-- temporary fix for option param of (e.g P1/P2) | |||
if string.find(propertyName, '/') then | |||
return CrossValidate.CrossValidateResult.INVALID_WIKITEXT | |||
end | end | ||
local propertyVals = mw.wikibase.getBestStatements(entityId, propertyName) | local propertyVals = mw.wikibase.getBestStatements(entityId, propertyName) | ||
| שורה 41: | שורה 45: | ||
else | else | ||
-- try to remove links | -- try to remove links | ||
if mw.ustring.gsub(wikitext, '[%[%]]', '') == formattedValue then | if mw.ustring.gsub(wikitext, '[%[%]]', '') == formattedValue or mw.ustring.gsub(wikitext, '%[%[[^%|%[%]]+%|(.+)%]%]', '%1') == formattedValue then | ||
return CrossValidate.CrossValidateResult.COMPATIBLE | return CrossValidate.CrossValidateResult.COMPATIBLE | ||
end | end | ||
| שורה 54: | שורה 58: | ||
if propValue['type'] == 'wikibase-entityid' then | if propValue['type'] == 'wikibase-entityid' then | ||
local localLabel, langLabel = mw.wikibase.getLabelWithLang( "Q" .. propValue.value['numeric-id'] ) | |||
local isLocalLabel = langLabel=='he' | local isLocalLabel = langLabel=='he' | ||
if not isLocalLabel then | if not isLocalLabel then | ||
| שורה 91: | שורה 95: | ||
end | end | ||
elseif propValue['type'] == 'quantity' then | elseif propValue['type'] == 'quantity' then | ||
return | local noramlizeUnit = mw.ustring.gsub(wikitext, '[%[%]]', '') | ||
noramlizeUnit = mw.ustring.gsub(noramlizeUnit, '(.+) מטרים', '%1 מטר') | |||
noramlizeUnit = mw.ustring.gsub(noramlizeUnit, '(.+) ק"ג$', '%1 קילוגרם') | |||
if noramlizeUnit == formattedValue then | |||
return CrossValidate.CrossValidateResult.COMPATIBLE | |||
end | |||
if mw.ustring.match(noramlizeUnit, '^[%d.,]+ מטר$') then | |||
local ConvertModule = require('Module:Convert') | |||
local success, wikidataMeter = pcall(ConvertModule.convert, mw.getCurrentFrame():newChild{ args = { | |||
['input'] = propertyName, | |||
[2] = 'מטר', | |||
['disp'] = 'out', | |||
['qid'] = entityId, | |||
['abbr']='off' | |||
} }:newChild{}) | |||
if success then | |||
wikidataMeter = mw.ustring.gsub(wikidataMeter, '(.+) מטרים', '%1 מטר') | |||
if wikidataMeter==noramlizeUnit then | |||
return CrossValidate.CrossValidateResult.COMPATIBLE | |||
end | |||
end | |||
end | |||
return CrossValidate.CrossValidateResult.INVALID_WIKITEXT -- TODO: parse quantity and units | |||
elseif propValue['type'] == 'time' then | elseif propValue['type'] == 'time' then | ||
local success, res = pcall(Date.newFromWikitext, wikitext ) | local success, res = pcall(Date.newFromWikitext, wikitext ) | ||
| שורה 116: | שורה 142: | ||
return CrossValidate.CrossValidateResult.COMPATIBLE | return CrossValidate.CrossValidateResult.COMPATIBLE | ||
end | |||
function CrossValidate.templateCrossVal(frame) | |||
local Arguments = require( "Module:Arguments" ) | |||
local args = Arguments.getArgs(frame, { ['trim'] = true, ['removeBlanks'] = true }) | |||
local wikitext = args[1] | |||
local propertyName = args[2] | |||
local res = CrossValidate.crossValidate(wikitext, propertyName) | |||
if res then | |||
return CrossValidate.maintainceCategory(res, propertyName) | |||
end | |||
end | end | ||
return CrossValidate | return CrossValidate | ||