EditDistanceTable EditDistanceTable_createFromCharacterStrings (const char32 *chars1, const char32 *chars2) { try { autoStrings s1 = Strings_createAsCharacters (chars1); autoStrings s2 = Strings_createAsCharacters (chars2); autoEditDistanceTable me = EditDistanceTable_create (s1.peek(), s2.peek()); return me.transfer(); } catch (MelderError) { Melder_throw (U"EditDistanceTable not created from character strings."); } }
autoTable IntervalTiers_to_Table_textAlignmentment (IntervalTier target, IntervalTier source, EditCostsTable costs) { try { long numberOfTargetIntervals = target -> intervals.size; long numberOfSourceIntervals = source -> intervals.size; autoNUMvector<long> targetOrigin (1, numberOfTargetIntervals); autoNUMvector<long> sourceOrigin (1, numberOfSourceIntervals); autoStrings targets = IntervalTier_to_Strings_withOriginData (target, targetOrigin.peek()); autoStrings sources = IntervalTier_to_Strings_withOriginData (source, sourceOrigin.peek()); autoEditDistanceTable edit = EditDistanceTable_create (targets.peek(), sources.peek()); if (costs != 0) { EditDistanceTable_setEditCosts (edit.peek(), costs); EditDistanceTable_findPath (edit.peek(), nullptr); } long pathLength = edit -> warpingPath -> pathLength; autoTable thee = Table_createWithColumnNames (pathLength - 1, U"targetInterval targetText targetStart targetEnd sourceInterval sourceText sourceStart sourceEnd operation"); for (long i = 2; i <= pathLength; i++) { structPairOfInteger p = edit -> warpingPath -> path[i]; structPairOfInteger p1 = edit -> warpingPath -> path[i - 1]; double targetStart = NUMundefined, targetEnd = NUMundefined; double sourceStart = NUMundefined, sourceEnd = NUMundefined; const char32 * targetText = U"", *sourceText = U""; long targetInterval = p.y > 1 ? targetOrigin[p.y - 1] : 0; long sourceInterval = p.x > 1 ? sourceOrigin[p.x - 1] : 0; if (targetInterval > 0) { TextInterval ti = target -> intervals.at [targetInterval]; targetStart = ti -> xmin; targetEnd = ti -> xmax; targetText = ti -> text; } if (sourceInterval > 0) { TextInterval ti = source -> intervals.at [sourceInterval]; sourceStart = ti -> xmin; sourceEnd = ti -> xmax; sourceText = ti -> text; } long irow = i - 1; if (p.y == p1.y) { // deletion Table_setNumericValue (thee.peek(), irow, 1, 0); Table_setStringValue (thee.peek(), irow, 2, U""); Table_setNumericValue (thee.peek(), irow, 3, NUMundefined); Table_setNumericValue (thee.peek(), irow, 4, NUMundefined); Table_setNumericValue (thee.peek(), irow, 5, sourceInterval); Table_setStringValue (thee.peek(), irow, 6, sourceText); Table_setNumericValue (thee.peek(), irow, 7, sourceStart); Table_setNumericValue (thee.peek(), irow, 8, sourceEnd); Table_setStringValue (thee.peek(), irow, 9, U"d"); } else if (p.x == p1.x) { // insertion Table_setNumericValue (thee.peek(), irow, 1, targetInterval); Table_setStringValue (thee.peek(), irow, 2, targetText); Table_setNumericValue (thee.peek(), irow, 3, targetStart); Table_setNumericValue (thee.peek(), irow, 4, targetEnd); Table_setNumericValue (thee.peek(), irow, 5, 0); Table_setStringValue (thee.peek(), irow, 6, U""); Table_setNumericValue (thee.peek(), irow, 7, NUMundefined); Table_setNumericValue (thee.peek(), irow, 8, NUMundefined); Table_setStringValue (thee.peek(), irow, 9, U"i"); } else { // substitution ? Table_setNumericValue (thee.peek(), irow, 1, targetInterval); Table_setStringValue (thee.peek(), irow, 2, targetText); Table_setNumericValue (thee.peek(), irow, 3, targetStart); Table_setNumericValue (thee.peek(), irow, 4, targetEnd); Table_setNumericValue (thee.peek(), irow, 5, sourceInterval); Table_setStringValue (thee.peek(), irow, 6, sourceText); Table_setNumericValue (thee.peek(), irow, 7, sourceStart); Table_setNumericValue (thee.peek(), irow, 8, sourceEnd); Table_setStringValue (thee.peek(), irow, 9, Melder_equ (targetText, sourceText) ? U" " : U"s"); } } return thee; } catch (MelderError) { Melder_throw (target, U" and ", source, U" not aligned."); } }