在Java中向Concordance函数添加频率计数

时间:2018-10-20 04:54:35

标签: java dictionary hashtable word-frequency

希望获得有关我的逻辑是否正确的输入。我的任务只是修改功能以跟踪单词频率。我想我已经添加了一个计数器来执行此操作。

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

0 个答案:

没有答案