本文整理汇总了Java中edu.berkeley.nlp.math.SloppyMath.max方法的典型用法代码示例。如果您正苦于以下问题:Java SloppyMath.max方法的具体用法?Java SloppyMath.max怎么用?Java SloppyMath.max使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类edu.berkeley.nlp.math.SloppyMath
的用法示例。
在下文中一共展示了SloppyMath.max方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: longestCommonSubstring
import edu.berkeley.nlp.math.SloppyMath; //导入方法依赖的package包/类
/**
* Computes the longest common substring of s and t. The longest common
* substring of a and b is the longest run of characters that appear in
* order inside both a and b. Both a and b may have other extraneous
* characters along the way. This is like edit distance but with no
* substitution and a higher number means more similar. For example, the LCS
* of "abcD" and "aXbc" is 3 (abc).
*/
public static int longestCommonSubstring(String s, String t) {
int d[][]; // matrix
int n; // length of s
int m; // length of t
int i; // iterates through s
int j; // iterates through t
char s_i; // ith character of s
char t_j; // jth character of t
// Step 1
n = s.length();
m = t.length();
if (n == 0) {
return 0;
}
if (m == 0) {
return 0;
}
d = new int[n + 1][m + 1];
// Step 2
for (i = 0; i <= n; i++) {
d[i][0] = 0;
}
for (j = 0; j <= m; j++) {
d[0][j] = 0;
}
// Step 3
for (i = 1; i <= n; i++) {
s_i = s.charAt(i - 1);
// Step 4
for (j = 1; j <= m; j++) {
t_j = t.charAt(j - 1);
// Step 5
// js: if the chars match, you can get an extra point
// otherwise you have to skip an insertion or deletion (no subs)
if (s_i == t_j) {
d[i][j] = SloppyMath.max(d[i - 1][j], d[i][j - 1],
d[i - 1][j - 1] + 1);
} else {
d[i][j] = Math.max(d[i - 1][j], d[i][j - 1]);
}
}
}
if (false) {
// num chars needed to display longest num
int numChars = (int) Math.ceil(Math.log(d[n][m]) / Math.log(10));
for (i = 0; i < numChars + 3; i++) {
System.err.print(' ');
}
for (j = 0; j < m; j++) {
System.err.print("" + t.charAt(j) + " ");
}
System.err.println();
for (i = 0; i <= n; i++) {
System.err.print((i == 0 ? ' ' : s.charAt(i - 1)) + " ");
for (j = 0; j <= m; j++) {
System.err.print("" + d[i][j] + " ");
}
System.err.println();
}
}
// Step 7
return d[n][m];
}