function calculateCost(dimension, property) {
    if (property.dummy) {
        // Dummy properties are inserted to simulate leaving optional dimensions unassigned
        // and can only be assigned to their corresponding dimensions. 
        // Prefer a bad but valid match over leaving an optional dimension unassigned, 
        // but don't assign if the mapping would become invalid.
        if (property.dimension === dimension.optionName) {
            return 100;
        } else {
            return INVALID_MAPPING_WEIGHT;
        }
    }

    var propType = property.type;
    var scalePenalty = INVALID_MAPPING_WEIGHT;

    // A dimension may be able to handle more than one scale of measurement
    // => Take the minimum weight
    for (var i = 0; i < dimension.scalesOfMeasurement.length; i++) {
        var dimType = dimension.scalesOfMeasurement[i];
        if (propType === dimType) {
            scalePenalty = Math.min(0, scalePenalty);
        } else if (
                dimType === "Nominal" && propType === "Ordinal"
                || dimType === "Ordinal" && propType === "Interval"
                || dimType === "Interval" && propType === "Ratio"
                ) {
            scalePenalty = Math.min(30, scalePenalty);
        } else if (dimType === "Interval" && propType === "Ratio") {
            scalePenalty = Math.min(40, scalePenalty);
        }
    }

    var dimensionRole = getDimensionRole(dimension.dimensionRole);
    var propertyRole = property.role;

    var rolePenalty;
    if (dimensionRole && propertyRole) {
        if (dimensionRole === propertyRole) {
            rolePenalty = 0;
        } else {
            // Known false role -- probably pretty bad
            rolePenalty = INVALID_MAPPING_WEIGHT;
        }
    } else if (dimensionRole && !propertyRole) {
        // Dimension role defined but property role unknown 
        // Might or might not work -- some penalty, but less than for assigning property with worse SOM
        rolePenalty = 20;
    } else if (propertyRole && !dimensionRole) {
        // Property role known but dimension role not defined
        // May mean that either kind of data works, but prefer known-good assignments anyway
        rolePenalty = 5;
    } else {
        rolePenalty = 0;
    }

    var optionalPenalty;
    if (dimension.optional) {
        // Prefer mapping required dimensions over mapping optional dimensions,
        // (better to have a suboptimal mapping than to have an incomplete one)
        optionalPenalty = 50;
    } else {
        optionalPenalty = 0;
    }

    var weight = scalePenalty + rolePenalty + optionalPenalty;

    return weight;
}
// Defines how well dimensions and properties match according to their scales of measurement
Defines how well dimensions and properties match according to their scales of measurement
Defines how well dimensions and properties match according to their scales of measurement
function calculateCost(dimension, property) {
    if (property.dummy) {
        if (property.dimension === dimension.optionName) {
            return 100;
        } else {
            return INVALID_MAPPING_WEIGHT;
        }
    }
    var propType = property.type;
    var scalePenalty = INVALID_MAPPING_WEIGHT;
    for (var i = 0; i < dimension.scalesOfMeasurement.length; i++) {
        var dimType = dimension.scalesOfMeasurement[i];
        if (propType === dimType) {
            scalePenalty = Math.min(0, scalePenalty);
        } else if (
                dimType === "Nominal" && propType === "Ordinal"
                || dimType === "Ordinal" && propType === "Interval"
                || dimType === "Interval" && propType === "Ratio"
                ) {
            scalePenalty = Math.min(30, scalePenalty);
        } else if (dimType === "Interval" && propType === "Ratio") {
            scalePenalty = Math.min(40, scalePenalty);
        }
    }
    var dimensionRole = getDimensionRole(dimension.dimensionRole);
    var propertyRole = property.role;
    var rolePenalty;
    if (dimensionRole && propertyRole) {
        if (dimensionRole === propertyRole) {
            rolePenalty = 0;
        } else {
            rolePenalty = INVALID_MAPPING_WEIGHT;
        }
    } else if (dimensionRole && !propertyRole) {
        rolePenalty = 20;
    } else if (propertyRole && !dimensionRole) {
        rolePenalty = 5;
    } else {
        rolePenalty = 0;
    }
    var optionalPenalty;
    if (dimension.optional) {
        optionalPenalty = 50;
    } else {
        optionalPenalty = 0;
    }
    var weight = scalePenalty + rolePenalty + optionalPenalty;
    return weight;
}
function calculateCost ( dimension , property ) { if ( property . dummy ) { if ( property . dimension === dimension . optionName ) { return 100 ; } else { return INVALID_MAPPING_WEIGHT ; } } var propType = property . type ; var scalePenalty = INVALID_MAPPING_WEIGHT ; for ( var i = 0 ; i < dimension . scalesOfMeasurement . length ; i ++ ) { var dimType = dimension . scalesOfMeasurement [ i ] ; if ( propType === dimType ) { scalePenalty = Math . min ( 0 , scalePenalty ) ; } else if ( dimType === "Nominal" && propType === "Ordinal" || dimType === "Ordinal" && propType === "Interval" || dimType === "Interval" && propType === "Ratio" ) { scalePenalty = Math . min ( 30 , scalePenalty ) ; } else if ( dimType === "Interval" && propType === "Ratio" ) { scalePenalty = Math . min ( 40 , scalePenalty ) ; } } var dimensionRole = getDimensionRole ( dimension . dimensionRole ) ; var propertyRole = property . role ; var rolePenalty ; if ( dimensionRole && propertyRole ) { if ( dimensionRole === propertyRole ) { rolePenalty = 0 ; } else { rolePenalty = INVALID_MAPPING_WEIGHT ; } } else if ( dimensionRole && ! propertyRole ) { rolePenalty = 20 ; } else if ( propertyRole && ! dimensionRole ) { rolePenalty = 5 ; } else { rolePenalty = 0 ; } var optionalPenalty ; if ( dimension . optional ) { optionalPenalty = 50 ; } else { optionalPenalty = 0 ; } var weight = scalePenalty + rolePenalty + optionalPenalty ; return weight ; }
Defines how well dimensions and properties match according to their scales of measurement
Defines how well dimensions and properties match according to their scales of measurement
// Dummy properties are inserted to simulate leaving optional dimensions unassigned // and can only be assigned to their corresponding dimensions.  // Prefer a bad but valid match over leaving an optional dimension unassigned,  // but don't assign if the mapping would become invalid. // A dimension may be able to handle more than one scale of measurement // => Take the minimum weight // Known false role -- probably pretty bad // Dimension role defined but property role unknown  // Might or might not work -- some penalty, but less than for assigning property with worse SOM // Property role known but dimension role not defined // May mean that either kind of data works, but prefer known-good assignments anyway // Prefer mapping required dimensions over mapping optional dimensions, // (better to have a suboptimal mapping than to have an incomplete one)