java - 在 Java 中向 Concordance 函数添加频率计数
问题描述
希望得到关于我的逻辑是否正确的意见。我的任务只是修改函数以跟踪词频。我想我已经添加了一个计数器来做到这一点。
public void enterWord (Object word, Integer line) {
Vector set = (Vector) dict.get(word);
int counter = 0;
if (set == null) { // word not in dictionary
set = new Vector( );
dict.put(word, set); // enter word and empty Vector
} // if
if (allowDupl || !set.contains(line)) {
counter++;
set.addElement(line);
set.addElement(counter);
}
} // enterWord
原始代码示例输入:
this is just a test or is it
is
just
a
test
输出:
a: 1 4
this: 1
it: 1
is: 1 1 2
or: 1
just: 1 3
test: 1 5
使用我添加的计数器,输出如下所示:
a: 1 1 4 1
this: 1 1
it: 1 1
is: 1 1 1 1 2 1
or: 1 1
just: 1 1 3 1
test: 1 1 5 1
解决方案
推荐阅读
- sql-server - 将非标准 varchar 转换为 DATETIME
- python - Windows API 调用不起作用:SaveBitmapFile
- javascript - 重定向到 div
- python - 在 Seaborn 线图中通过“色调”设置线条颜色
- azure-active-directory - Azure Web App Authentication using Azure AD – 如何获取用户组
- java - 如何获取和设置剪贴板数据?
- python - 收集集合中字段的所有值
- wordpress - 在 WooCommerce 中创建新用户后,用户更改不起作用
- java - 如何更改 JavaFx ComboBox 文本颜色
- java - StringJoiner - 括号中的每一项