ק
rv
קאין תקציר עריכה |
ק (rv) צייכן: צוריקגעשטעלט |
||
| שורה 2: | שורה 2: | ||
Cross validation with wikidata: parse the wikitext of a value related to wikidata and see if they are close enough. | Cross validation with wikidata: parse the wikitext of a value related to wikidata and see if they are close enough. | ||
]] | ]] | ||
local Date = require('יחידה: | local Date = require('יחידה:דאטע') | ||
local CrossValidate = {} | local CrossValidate = {} | ||
CrossValidate.CrossValidateResult = { | CrossValidate.CrossValidateResult = { | ||
| שורה 9: | שורה 9: | ||
INCOMPATIBLE='לא מתאים', | INCOMPATIBLE='לא מתאים', | ||
COMPATIBLE='מתאים', | COMPATIBLE='מתאים', | ||
MISSING_WIKIDATA_LABEL=' | MISSING_WIKIDATA_LABEL='פעלט יידיש עטיקעט' | ||
} | } | ||
function CrossValidate.maintainceCategory(value, propertyName) | function CrossValidate.maintainceCategory(value, propertyName) | ||
if value==CrossValidate.CrossValidateResult.INVALID_WIKITEXT then return '' end | if value==CrossValidate.CrossValidateResult.INVALID_WIKITEXT then return '' end | ||
return '[[ | return '[[קאטעגאריע: ויקינתונים - השוואת ערכים: ' .. value.. ']]' .. '[[קאטעגאריע: ויקינתונים - השוואת ערכים: ' .. value.. ': '..(mw.wikibase.label( propertyName) or propertyName)..']]' | ||
end | end | ||
--function CrossValidate.crossValidate( wikitext, propertyName, allowMulti, allowNA, entityId, multiSeperator, optionalQualifier, genderAware ) | --function CrossValidate.crossValidate( wikitext, propertyName, allowMulti, allowNA, entityId, multiSeperator, optionalQualifier, genderAware ) | ||
| שורה 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 | end | ||
local propertyVals = mw.wikibase.getBestStatements(entityId, propertyName) | local propertyVals = mw.wikibase.getBestStatements(entityId, propertyName) | ||
| שורה 45: | שורה 41: | ||
else | else | ||
-- try to remove links | -- try to remove links | ||
if mw.ustring.gsub(wikitext, '[%[%]]', ' | if mw.ustring.gsub(wikitext, '[%[%]]', '') == formattedValue then | ||
return CrossValidate.CrossValidateResult.COMPATIBLE | return CrossValidate.CrossValidateResult.COMPATIBLE | ||
end | end | ||
| שורה 58: | שורה 54: | ||
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==' | local isLocalLabel = langLabel=='yi' | ||
if not isLocalLabel then | if not isLocalLabel then | ||
return CrossValidate.CrossValidateResult.MISSING_WIKIDATA_LABEL | return CrossValidate.CrossValidateResult.MISSING_WIKIDATA_LABEL | ||
| שורה 70: | שורה 66: | ||
if not isCompatible then | if not isCompatible then | ||
local entityObject = mw.wikibase.getEntity( "Q" .. propValue.value['numeric-id'] ) | local entityObject = mw.wikibase.getEntity( "Q" .. propValue.value['numeric-id'] ) | ||
local entityAliases = entityObject and entityObject.aliases and entityObject.aliases[' | local entityAliases = entityObject and entityObject.aliases and entityObject.aliases['yi'] | ||
if entityAliases then | if entityAliases then | ||
for _, curAlias in ipairs(entityAliases) do | for _, curAlias in ipairs(entityAliases) do | ||
| שורה 95: | שורה 91: | ||
end | end | ||
elseif propValue['type'] == 'quantity' then | elseif propValue['type'] == 'quantity' then | ||
return MISSING_WIKIDATA -- 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 ) | ||
| שורה 142: | שורה 116: | ||
return CrossValidate.CrossValidateResult.COMPATIBLE | return CrossValidate.CrossValidateResult.COMPATIBLE | ||
end | end | ||
return CrossValidate | return CrossValidate | ||