| 26 | } |
| 27 | |
| 28 | function compare(anchorResult: SharedResult, targetResult: SharedResult) { |
| 29 | let anchorParas = anchorResult.transPara; |
| 30 | let targetParas = targetResult.transPara; |
| 31 | let all_parts = []; |
| 32 | if (anchorParas.length != targetParas.length) { |
| 33 | anchorParas = [anchorResult.translation]; |
| 34 | targetParas = [targetResult.translation]; |
| 35 | } |
| 36 | const diffFunc = anchorResult.chineseStyle ? Diff.diffChars : Diff.diffWords; //chinese style的话,是逐个字符比较 |
| 37 | for (let i = 0; i < anchorParas.length; i++) { |
| 38 | let diffParts = diffFunc(anchorParas[i], targetParas[i]); |
| 39 | diffParts = diffParts.filter((p: any) => !p.removed); |
| 40 | all_parts.push(diffParts); |
| 41 | } |
| 42 | return all_parts; |
| 43 | } |