void EditCostsTable_setInsertionCosts (EditCostsTable me, char32 *targets, double cost) { for (char32 *token = Melder_firstToken (targets); token != 0; token = Melder_nextToken ()) { long irow = EditCostsTable_getTargetIndex (me, token); irow = irow > 0 ? irow : my numberOfRows - 1; // nomatch condition to penultimate row my data[irow][my numberOfColumns] = cost; } }
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."); } }
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."); } }
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]; }
double EditCostsTable_getInsertionCost (EditCostsTable me, const char32 *symbol) { long irow = EditCostsTable_getTargetIndex (me, symbol); irow = irow == 0 ? my numberOfRows - 1 : irow; // others is penultimate row return my data[irow][my numberOfColumns]; }