计算两个字符串之间的错误(差异)在Java中。

huangapple go评论54阅读模式
英文:

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:

See here: http://commons.apache.org/proper/commons-text/

And here: https://commons.apache.org/sandbox/commons-text/jacoco/org.apache.commons.text.similarity/LevenshteinDistance.java.html

huangapple
  • 本文由 发表于 2020年4月8日 06:53:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/61090685.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定