英文:
Calculating errors between two strings in Java
问题
我想要计算两个字符串之间的错误百分比,也就是说,假设一个字符串是标准答案,另一个字符串是输入的字符串,我想计算输入字符串中的错误数量。
让我们来举个例子:
标准答案 = "This is a test"
输入字符串 = " Thisi is atest"
在“输入字符串”中有2处错误(多了一个 i 和缺少了一个空格)。
我认为可以使用某种距离度量来完成这个任务。在Java中是否有用于计算这种错误率的库?
英文:
I would like to calculate the percentage of error between two strings, that means if we assume that one string is the ground truth and the other string is a typed string, then I would like to calculate the number of mistakes in the typed string.
Let's make an example:
ground truth = "This is a test"
typed = " Thisi is atest"
In typed
there are 2 errors (additional i and missing space).
I think this can be done using some distance metric. Is there a library in Java for calculating such an error rate?
答案1
得分: 2
你在提到Levenshtein距离。它在Apache Commons Text库中实现:
在这里查看:http://commons.apache.org/proper/commons-text/
以及在这里:https://commons.apache.org/sandbox/commons-text/jacoco/org.apache.commons.text.similarity/LevenshteinDistance.java.html
英文:
You are referring to the Levenshtein distance. It is implemented in Apache Commons Text library:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论