- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
示例:
预期输出:敏捷的棕色狮子跳过懒惰的兔子。
我现在得到的。
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.
我想知道整个单词/句子何时被删除插入,以便我可以将其正确保存在数据库中。你能帮忙的话,我会很高兴。多谢。 :-)
编辑下面提到的答案完美地获得了 2 个可以保存在数据库中的独立字符串。
最佳答案
经过广泛的重新考虑,我认为这不是正则表达式的情况。相同的更改会出现在多行中,因此您必须像这样逐行检查您的输入:
//-------------------------Example Strings---------------------------------------------
private static String oldText = "I yoyo am also working on a \n 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.";
private static String newText = "akshay is also working on a \n 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.";
//-------------------------Example Strings end --------------------------------------
private static diff_match_patch diffMatchPatch;
public static void main(String[] args) {
diffMatchPatch = new diff_match_patch();
//Split text into List of strings
List<String> oldTextList = Arrays.asList(oldText.split("(\\.|\\n)"));
List<String> newTextList = Arrays.asList(newText.split("(\\.|\\n)"));
//If we have different length
int counter = Math.max(oldTextList.size(), newTextList.size());
StringBuilder sb = new StringBuilder();
for(int current = 0; current < counter; current++){
String oldString = null;
String newString = null;
if(oldTextList.size() <= current){
oldString = "";
newString = newTextList.get(current);
} else if (newTextList.size() <= current){
oldString = oldTextList.get(current);
newString = "";
} else {
if (isLineDifferent(oldTextList.get(current), newTextList.get(current))){
oldString = oldTextList.get(current);
newString = newTextList.get(current);
}
}
if(oldString != null && newString != null) {
//---- Insert into database here -----
sb.append("Changes for Line: " + current + "\n");
sb.append("Old: " + oldString + "; New: " + newString +";\n");
}
}
System.out.println(sb.toString());
}
private static boolean isLineDifferent(String oldString, String newString) {
LinkedList<diff_match_patch.Diff> deltas = diffMatchPatch.diff_main(oldString,newString);
for(diff_match_patch.Diff d : deltas){
if (d.operation == diff_match_patch.Operation.EQUAL) continue;
return true;
}
return false;
}
}
这应该为您带来以下结果:
Changes for Line: 0
Old: I yoyo am also working on a ; New: akshay is also working on a ;
Changes for Line: 2
Old: In this, he can either write one paragraph, one sentence; New: He can either write one paragraph, one sentence;
Changes for Line: 8
Old: Kindly let me know what I am doing wrong; New: ;
请注意,我只添加了“;”作为 Stringbuilder 的分隔符号,这样您就可以辨别字符串的结束位置。这当然还有不完善的几点需要考虑:
关于Java : Getting effected sentence in Google-diff-match-patch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28858139/
我知道使用 GET 和 SET 函数的公共(public)变量的缺点/私有(private)变量的优点,但目前我正在使用 Ogre3D 开发自己的第一个“真实”游戏(C++)..同时,我有时需要 6-
我正在开发一个 GSM/GPRS 应用程序,它将每 10 秒报告一些值。我必须使用的 SIM 卡每月只有 15MB 可用数据。我使用的是 SIM900 GSM 芯片供您引用。 我到达服务器的方式是通过
这三者有什么区别:gets - 它获取带有 '\n' 的行gets.chomp - 它得到一行,但删除 '\n' 这样对吗? gets.chomp! 怎么样? 最佳答案 gets - 它得到一个末尾带
问题和我现在遇到的问题 脚本 顺便说一句,评论是挪威语的,如果它们看起来很奇怪哈哈 Connect-AzureAD #variabel $Users = Get-AzureADUser -All:$t
我现在面临的问题是获取一个 URL,如下所示: www.example.com/example.php?url=www.google.com 现在的问题是,如果我的网址中有一个 get,如下所示: w
我有一个 queryString 传递给 servlet 的 doGet() 方法,如下所示: count=9&preId0=-99&objId0=-99&preId1=-99&objId1=-99&
这是我在 Django 模板中的代码: {% for tag in tags %} {{ tag }} {% endfor %} 在view.py中: def tag_find(
我正在尝试在express.js中为我的网络应用程序创建一个路由系统,我需要知道是否需要使用app.get/post/put/delete.apply以编程方式设置多个功能对于一条路线。 也是如此 a
我正在通过示例查看 A.Mele Django,第 1 章 def post_list(request, category=None): object_list = Post.publishe
如果我想找到与IIS站点或应用程序关联的目录,我该怎么做? 我似乎无法从Get-Website和Get-WebApplication的对象的任何属性中找到任何允许我这样做的东西。 最佳答案 只需查看一
不知道发生了什么。当我执行以下代码时......它运行良好......但它产生了错误。如果我将以下内容粘贴到我的浏览器地址栏中并点击它,我会得到一个 URL。如果我通过 KRL http:get 输入
Curl 提供了一系列不同的带有 X 前缀的 http 方法调用,但也提供了不带 X 的相同方法。我两种都试过了,但我似乎无法弄清楚其中的区别。有人可以快速向我解释这两种操作有何不同吗? 最佳答案 默
request.GET.get 是什么意思?我在 Django 中看到类似的东西 page = request.GET.get('page', 1) 我认为它与类似的东西有关 « 它们是如
我正在从我的 Angular2 站点查询一些 Elasticsearch 服务器。为了帮助提高安全性,我们希望锁定对 GET 请求的访问权限。 Elasticsearch 支持带主体的 GET,但我在
关闭。这个问题是opinion-based .它目前不接受答案。 想改善这个问题吗?更新问题,以便可以通过 editing this post 用事实和引文回答问题. 4年前关闭。 Improve t
调用 HTable.get(List) 返回的 Result 数组的顺序是什么? ? 我的意思是,假设与输入列表的顺序相同是否正确? 最佳答案 结果数组中的顺序将与输入列表的顺序相同。与批处理方法一样
所以我有一个看起来像这样的 JSON 数组: var myData = { foo : { biz : 'baz', fig : 'tree' } }
我正在学习 Ajax、javascript 和 html,并且有一个应用程序可以触发“get”请求,然后再触发另一个“get”请求。这些请求是用户按下按钮的结果。在我的 servlet 中,我使用 T
关闭。这个问题是opinion-based 。目前不接受答案。 想要改进这个问题吗?更新问题,以便 editing this post 可以用事实和引文来回答它。 . 已关闭 6 年前。 Improv
运行以下 cmdlet 适用于组成员(Amer 域中的组)中的所有用户,无论列出的用户位于哪个域: Get-ADGroupMember -Server amer 但是,当尝试通过管道传输到 Get-
我是一名优秀的程序员,十分优秀!