编程语言
首页 > 编程语言> > Java:在Google-diff-match-patch中生效的句子

Java:在Google-diff-match-patch中生效的句子

作者:互联网

>我正在一个Java应用程序中进行比较2
段落并获得两个字符串中不同的句子
进行比较.现在我可以获取插入的内容以及
已删除.我面临的问题是,我想得到
是有效的,不仅是言语.

范例:

>老弦:敏捷的棕色狐狸跳过了懒惰的兔子.好奇心杀死了那只猫.
>新弦乐:敏捷的棕色狮子跳过了懒惰的兔子.好奇心杀死了那只猫.

预期的输出:敏捷的棕色狮子跳过了懒兔子.

我现在得到的是什么.

Diff(DELETE,"fox")
Diff(INSERT,"lion")

因此,我没有关于狐狸在哪里被删除以及狮子在哪里被添加的上下文.因此,即使进行了某些操作的字符左右也有15个字符也可以.
我现在拥有的代码:

diff_match_patch diffMatchPatch = new diff_match_patch();
            LinkedList<diff_match_patch.Diff> deltas = diffMatchPatch.diff_main(oldText,newText);
            for(diff_match_patch.Diff d : deltas){
                if((d.operation == diff_match_patch.Operation.DELETE) || (d.operation== diff_match_patch.Operation.INSERT)) {
                    System.out.println(d);
                }
            }

你能帮忙的话,我会很高兴.非常感谢. :-)如果对我的解释方式有任何疑问,请告诉我.

编辑
从答案中添加了新代码:

 diff_match_patch diffMatchPatch = new diff_match_patch();
            LinkedList<diff_match_patch.Diff> deltas = diffMatchPatch.diff_main(notes1.getNotetext(),notes.getNotetext());
            for(diff_match_patch.Diff d : deltas) {
                if ((d.operation == diff_match_patch.Operation.DELETE) || (d.operation == diff_match_patch.Operation.INSERT)) {
                    Pattern myPattern = Pattern.compile("(\\. |^)(.*" + d.text + ".*)(\\. )");
                    Matcher m = myPattern.matcher(notes1.getNotetext());
                    while (m.find()) {
                        System.out.println("Found " + d.operation + " of: " + d.text + " in sentence: " + m.group());
                    }
                }
            }

The output I am getting is wrong, something like this I am getting,
Found DELETE of: I  in sentence: I yoyo am also working on a webapp in which the user can make changes to a text area. In this, he can either write one paragraph, one sentence. So what I am currently trying to do is to split the whole paragraph by a dot separator. Once that is done, I would like to check which sentences have changed. I am currently doing it using for loop, which is not accurate as I have to length of array to Math.minimum of both String arrays. But it is not working, I am getting zero String modified from it. Kindly let me know what I am doing wrong. 
Found DELETE of: oyo am in sentence: I yoyo am also working on a webapp in which the user can make changes to a text area. In this, he can either write one paragraph, one sentence. So what I am currently trying to do is to split the whole paragraph by a dot separator. Once that is done, I would like to check which sentences have changed. I am currently doing it using for loop, which is not accurate as I have to length of array to Math.minimum of both String arrays. But it is not working, I am getting zero String modified from it. Kindly let me know what I am doing wrong. 
Found DELETE of: a in sentence: akshay also working on a webapp in which the user can make changes to a text area. In this, he can either write one paragraph, one sentence. So what I am currently trying to do is to split the whole paragraph by a dot separator. Once that is done, I would like to check which sentences have changed. I am currently doing it using for loop, which is not accurate as I have to length of array to Math.minimum of both String arrays. But it is not working, I am getting zero String modified from it. Kindly let me know what I am doing wrong. 
Found INSERT of: a in sentence: kshay also working on a webapp in which the user can make changes to a text area. In this, he can either write one paragraph, one sentence. So what I am currently trying to do is to split the whole paragraph by a dot separator. Once that is done, I would like to check which sentences have changed. I am currently doing it using for loop, which is not accurate as I have to length of array to Math.minimum of both String arrays. But it is not working, I am getting zero String modified from it. Kindly let me know what I am doing wrong. 
Found INSERT of: r in sentence: akshay also working on a webapp in which the user can make changes to a text area. In this, he can either write one paragraph, one sentence. So what I am currently trying to do is to split the whole paragraph by a dot separator. Once that is done, I would like to check which sentences have changed. I am currently doing it using for loop, which is not accurate as I have to length of array to Math.minimum of both String arrays. But it is not working, I am getting zero String modified from it. Kindly let me know what I am doing wrong. 
Found DELETE of: ks in sentence: akshay also working on a webapp in which the user can make changes to a text area. In this, he can either write one paragraph, one sentence. So what I am currently trying to do is to split the whole paragraph by a dot separator. Once that is done, I would like to check which sentences have changed. I am currently doing it using for loop, which is not accurate as I have to length of array to Math.minimum of both String arrays. But it is not working, I am getting zero String modified from it. Kindly let me know what I am doing wrong. 
Found DELETE of: ay in sentence: akshay also working on a webapp in which the user can make changes to a text area. In this, he can either write one paragraph, one sentence. So what I am currently trying to do is to split the whole paragraph by a dot separator. Once that is done, I would like to check which sentences have changed. I am currently doing it using for loop, which is not accurate as I have to length of array to Math.minimum of both String arrays. But it is not working, I am getting zero String modified from it. Kindly let me know what I am doing wrong. 
Found INSERT of: ul in sentence: akshay also working on a webapp in which the user can make changes to a text area. In this, he can either write one paragraph, one sentence. So what I am currently trying to do is to split the whole paragraph by a dot separator. Once that is done, I would like to check which sentences have changed. I am currently doing it using for loop, which is not accurate as I have to length of array to Math.minimum of both String arrays. But it is not working, I am getting zero String modified from it. Kindly let me know what I am doing wrong. 
Found DELETE of: In this, in sentence: rahul also working on a webapp in which the user can make changes to a text area. In this, he can either write one paragraph, one sentence. So what I am currently trying to do is to split the whole paragraph by a dot separator. Once that is done, I would like to check which sentences have changed. I am currently doing it using for loop, which is not accurate as I have to length of array to Math.minimum of both String arrays. But it is not working, I am getting zero String modified from it. Kindly let me know what I am doing wrong. 
Found DELETE of: ang in sentence: rahul also working on a webapp in which the user can make changes to a text area.  he can either write one paragraph, one sentence. So what I am currently trying to do is to split the whole paragraph by a dot separator. Once that is done, I would like to check which sentences have changed. I am currently doing it using for loop, which is not accurate as I have to length of array to Math.minimum of both String arrays. But it is not working, I am getting zero String modified from it. Kindly let me know what I am doing wrong. 
Found DELETE of: s in sentence: rahul also working on a webapp in which the user can make changes to a text area.  he can either write one paragraph, one sentence. So what I am currently trying to do is to split the whole paragraph by a dot separator. Once that is done, I would like to check which sentences have changed. I am currently doing it using for loop, which is not accurate as I have to length of array to Math.minimum of both String arrays. But it is not working, I am getting zero String modified from it. Kindly let me know what I am doing wrong. 
Found INSERT of: ck in sentence: rahul also working on a webapp in which the user can make changes to a text area.  he can either write one paragraph, one sentence. So what I am currently trying to do is to split the whole paragraph by a dot separator. Once that is done, I would like to check which sentences have changed. I am currently doing it using for loop, which is not accurate as I have to length of array to Math.minimum of both String arrays. But it is not working, I am getting zero String modified from it. Kindly let me know what I am doing wrong. 
Found DELETE of: rahul  in sentence: rahul also working on a webapp in which the user can make check to a text area.  he can either write one paragraph, one sentence. So what I am currently trying to do is to split the whole paragraph by a dot separator. Once that is done, I would like to check which sentences have changed. I am currently doing it using for loop, which is not accurate as I have to length of array to Math.minimum of both String arrays. But it is not working, I am getting zero String modified from it. Kindly let me know what I am doing wrong. 

我想知道何时删除整个单词/句子,因此可以将其正确保存在数据库中.你能帮忙的话,我会很高兴.非常感谢.

标签:string-comparison,string,java,regex,google-diff-match-patch
来源: https://codeday.me/bug/20191120/2045597.html