יחידה:WikidataCrossValidation: הבדלים בין גרסאות בדף

מאין תקציר עריכה
מאין תקציר עריכה
שורה 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 then  
return CrossValidate.CrossValidateResult.INVALID_WIKITEXT -- comparing to null wikitext is meaningless
return CrossValidate.CrossValidateResult.INVALID_WIKITEXT -- comparing to null wikitext is meaningless
שורה 26: שורה 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
שורה 35: שורה 34:
     local propertyVals = mw.wikibase.getBestStatements(entityId, propertyName)
     local propertyVals = mw.wikibase.getBestStatements(entityId, propertyName)
     if (not propertyVals) or (#propertyVals==0) then return CrossValidate.CrossValidateResult.MISSING_WIKIDATA end --no such property for this item
     if (not propertyVals) or (#propertyVals==0) then return CrossValidate.CrossValidateResult.MISSING_WIKIDATA end --no such property for this item
   
    -- parsing the wikidata value gives similar result to wikitext
    local formattedValue = require('Module:PropertyLink').getPropertyByOptions(propertyName, entityId, {allowMulti=1 })
    if formattedValue == wikitext then
    return CrossValidate.CrossValidateResult.COMPATIBLE
    end
   
     local resTable = {}
     local resTable = {}
    local missingTranslation = false
    local isEqual = true
     for i, property in ipairs(propertyVals) do
     for i, property in ipairs(propertyVals) do
    local propValue = property.mainsnak and property.mainsnak.datavalue
    local propValue = property.mainsnak and property.mainsnak.datavalue