Esempio n. 1
0
void EditCostsTable_setDeletionCosts (EditCostsTable me, char32 *sources, double cost) {
    for (char32 *token = Melder_firstToken (sources); token != 0; token = Melder_nextToken ()) {
        long icol = EditCostsTable_getSourceIndex (me, token);
        icol = icol > 0 ? icol : my numberOfColumns - 1; // nomatch condition to penultimate column
        my data[my numberOfRows][icol] = cost;
    }
}
Esempio n. 2
0
void EditCostsTable_setSubstitutionCosts (EditCostsTable me, char32 *targets, char32 *sources, double cost) {
    try {
        autoNUMvector<long> targetIndex (1, my numberOfRows);
        autoNUMvector<long> sourceIndex (1, my numberOfRows);
        long numberOfTargetSymbols = 0;
        for (char32 *token = Melder_firstToken (targets); token != 0; token = Melder_nextToken ()) {
            long index = EditCostsTable_getTargetIndex (me, token);
            if (index > 0) {
                targetIndex[++numberOfTargetSymbols] = index;
            }
        }
        if (numberOfTargetSymbols == 0) {
            targetIndex[++numberOfTargetSymbols] = my numberOfRows - 1;
        }
        long numberOfSourceSymbols = 0;
        for (char32 *token = Melder_firstToken (sources); token != 0; token = Melder_nextToken ()) {
            long index = EditCostsTable_getSourceIndex (me, token);
            if (index > 0) {
                sourceIndex[++numberOfSourceSymbols] = index;
            }
        }
        if (numberOfSourceSymbols == 0) {
            sourceIndex[++numberOfSourceSymbols] = my numberOfColumns - 1;
        }
        for (long i = 1; i <= numberOfTargetSymbols; i++) {
            long irow = targetIndex[i];
            for (long j = 1; j <= numberOfSourceSymbols; j++) {
                my data [irow][sourceIndex[j]] = cost;
            }
        }
    } catch (MelderError) {
        Melder_throw (me, U": substitution costs not set.");
    }
}
Esempio n. 3
0
void EditCostsTable_setSubstitutionCosts (EditCostsTable me, wchar_t *targets, wchar_t *sources, double cost) {
	try {
		autoNUMvector<long> targetIndex (1, my numberOfRows);
		autoNUMvector<long> sourceIndex (1, my numberOfRows);
		long ntargets = 0;
		for (wchar_t *token = Melder_firstToken (targets); token != 0; token = Melder_nextToken ()) {
			long index = EditCostsTable_getTargetIndex (me, token);
			if (index > 0) {
				targetIndex[++ntargets] = index;
			}
		}
		if (ntargets == 0 && targets != 0 && targets[1] != '\0') {
			ntargets = 1; targetIndex[1] = my numberOfRows - 1;
		}
		long nsources = 0;
		for (wchar_t *token = Melder_firstToken (sources); token != 0; token = Melder_nextToken ()) {
			long index = EditCostsTable_getSourceIndex (me, token);
			if (index > 0) {
				sourceIndex[++nsources] = index;
			}
		}
		if (nsources == 0 && sources != 0 && sources[1] != '\0') {
			nsources = 1; sourceIndex[1] = my numberOfColumns - 1;
		}
		for (long i = 1; i <= ntargets; i++) {
			long irow = targetIndex[i];
			for (long j = 1; j <= nsources; j++) {
				my data [irow][sourceIndex[j]] = cost;
			}
		}
	} catch (MelderError) {
		Melder_throw (me, ": substitution costs not set.");
	}
}
Esempio n. 4
0
double EditCostsTable_getSubstitutionCost (EditCostsTable me, const char32 *symbol, const char32 *replacement) {
    long irow = EditCostsTable_getTargetIndex (me, symbol);
    long icol = EditCostsTable_getSourceIndex (me, replacement);
    if (irow == 0 && icol == 0) { // nomatch
        irow = my numberOfRows;
        icol = my numberOfColumns;
        if (my v_matchTargetWithSourceSymbol (symbol, replacement)) {
            --irow;
            --icol;
        }
    } else {
        irow = irow == 0 ? my numberOfRows - 1 : irow;
        icol = icol == 0 ? my numberOfColumns - 1 : icol;
    }
    return my data[irow][icol];
}
Esempio n. 5
0
double EditCostsTable_getDeletionCost (EditCostsTable me, const char32 *sourceSymbol) {
    long icol = EditCostsTable_getSourceIndex (me, sourceSymbol);
    icol = icol == 0 ? my numberOfColumns - 1 : icol; // others is penultimate column
    return my data[my numberOfRows][icol];
}