@@ -36,7 +36,6 @@ namespace LyricFA {
3636 const int n = referencePronunciation.size ();
3737 const int m = searchPronunciation.size ();
3838
39- // 修复: 处理n < m的情况
4039 if (n < m) {
4140 return {0 , std::min (n, m), {}, {}};
4241 }
@@ -52,7 +51,7 @@ namespace LyricFA {
5251 }
5352
5453 const int currentMatchLength = longestCommonSubsequence (searchPronunciation, window);
55- if (currentMatchLength >= maxMatchLength) { // 修复: 使用>=而不是>
54+ if (currentMatchLength >= maxMatchLength) {
5655 maxMatchLength = currentMatchLength;
5756 bestStartIdx = startIdx;
5857 }
@@ -171,13 +170,14 @@ namespace LyricFA {
171170 std::vector<std::string> formattedOps;
172171 for (size_t position = 0 ; position < operations.size (); ++position) {
173172 const auto &[original, modified] = operations[position];
174-
175- if (!original.empty () && modified.empty () && showDel) {
176- formattedOps.push_back (" (" + original + " ->, " + std::to_string (position) + " )" );
177- } else if (original.empty () && !modified.empty () && showIns) {
178- formattedOps.push_back (" (->" + modified + " , " + std::to_string (position) + " )" );
179- } else if (!original.empty () && !modified.empty () && showSub) {
180- formattedOps.push_back (" (" + original + " ->" + modified + " , " + std::to_string (position) + " )" );
173+ if (original != modified) {
174+ if (!original.empty () && modified.empty () && showDel) {
175+ formattedOps.push_back (" (" + original + " ->, " + std::to_string (position) + " )" );
176+ } else if (original.empty () && !modified.empty () && showIns) {
177+ formattedOps.push_back (" (->" + modified + " , " + std::to_string (position) + " )" );
178+ } else if (!original.empty () && !modified.empty () && showSub) {
179+ formattedOps.push_back (" (" + modified + " ->" + original + " , " + std::to_string (position) + " )" );
180+ }
181181 }
182182 }
183183 return join (formattedOps, " " );
@@ -232,8 +232,8 @@ namespace LyricFA {
232232 while (i > 0 || j > 0 ) {
233233 if (i > 0 && j > 0 && sourcePronunciation[i - 1 ] == targetPronunciation[j - 1 ]) {
234234 pronunciationOperations.insert (pronunciationOperations.begin (),
235- {sourcePronunciation[i - 1 ], targetPronunciation[j - 1 ]});
236- textOperations.insert (textOperations.begin (), {referenceTextTokens[i - 1 ], searchText[j - 1 ]});
235+ {targetPronunciation[j - 1 ], targetPronunciation[j - 1 ]});
236+ textOperations.insert (textOperations.begin (), {referenceTextTokens[i - 1 ], referenceTextTokens[i - 1 ]});
237237 i--;
238238 j--;
239239 } else {
@@ -282,15 +282,21 @@ namespace LyricFA {
282282 const auto &pOp = pronOps[idx];
283283 const auto &tOp = textOps[idx];
284284
285- if (!pOp.original .empty () && !pOp.modified .empty () && pOp.original != pOp.modified ) {
286- alignedPronunciation.push_back (pOp.modified );
287- alignedText.push_back (tOp.modified );
285+ if (pOp.original == pOp.modified ) {
286+ // 匹配操作:添加参考文本和参考发音
287+ alignedText.push_back (tOp.original );
288+ alignedPronunciation.push_back (pOp.original );
288289 } else if (pOp.original .empty () && !pOp.modified .empty ()) {
289- alignedPronunciation. push_back (pOp. modified );
290+ // 插入操作:添加目标文本和目标发音
290291 alignedText.push_back (tOp.modified );
291- } else if (!pOp.original .empty () && pOp.modified .empty ()) {
292292 alignedPronunciation.push_back (pOp.modified );
293- alignedText.push_back (tOp.modified );
293+ } else if (!pOp.original .empty () && pOp.modified .empty ()) {
294+ // 删除操作:跳过,不添加
295+ // 什么也不做
296+ } else if (!pOp.original .empty () && !pOp.modified .empty ()) {
297+ // 替换操作:添加参考文本和参考发音
298+ alignedText.push_back (tOp.original );
299+ alignedPronunciation.push_back (pOp.original );
294300 }
295301 }
296302
0 commit comments