我有兩個段落是有句子,我想比較兩個段落,並希望顯示UI的差異。文本比較算法或程序?
以下是可能的用例,我可以想一想。在算法或代碼中的任何幫助將是可觀的。
情況1:字刪除從STR2
String str1 = "Hello I am new How are you";
String str2 = "How are you Hello";
output :
str1 = "<del>Hello I am new</del> How are you";
str2 = "How are you <add>Hello</add>"
情況2:字加入到STR2
String str1 = "Hello How are you what about you";
String str2 = "How are you I am fine what about you";
output :
str1 = "<del>Hello</del> How are you what about you";
str2 = "How are you <add>I am fine</add> what about you"
情況3:字相等
String str1 = "Hello How are you";
String str2 = "Hello How rea you";
output :
str1 = "Hello How <missmatch>are</missmatch> you";
str2 = "Hello How <missmatch>rea</missmatch> you"
不應該在這兩種情況下1和2包含第二個字符串
而不是?如果將字符串'Hello'添加到'str2',它們將不相等。 –
我不確定,但有一種算法用於刪除插入等拼寫校正,稱爲**對稱刪除拼寫更正**。見http://blog.faroo.com/2012/06/07/improved-edit-distance-based-spelling-correction/你可能會有一些想法 –
@NikolasCharalambidis在案例1和2中,子字符串已被添加新,這是在Str1中沒有匹配 – user3676578