English 中文(简体)
• 在 Java使用通用的Pair等级和一个Splaytree计算和储存言语及其频率
原标题:Using a generic Pair class and a Splaytree to count and store words and their frequencies in Java

I m 执行一套游戏,以掌握言语及其频率,并选择建立一个能够容纳每个字数(关键值)的奶类。 这就是说, each树的每一个 no子都拥有一个奶类。 乳制品类:

public class SplayEntry<K, V> implements Comparable<SplayEntry<K, V>>{

public K word;
public V frequency;

public SplayEntry(K word, V frequency) {
    this.word = word;
    this.frequency = frequency;
}
getters, setters, hashCode, equals, compareTo etc...

锡米特里:

public class SplayTree<AnyType extends Comparable<? super AnyType>> {

public SplayTree( )
{
    nullNode = new BinaryNode<AnyType>( null );
    nullNode.left = nullNode.right = nullNode;
    root = nullNode;
}

并且有Binary Node。

我所担心的是,每字和频率都如何将其 into入树木,并且还要检查是否已经存在奶制品,如果是这样的话,则会增加频率。 我在文字档案中按行文逐行读,然后将每一行分成两行,然后采用计票系统,现在就是一个小点:

    public void countWords(String line) {
    line = line.toLowerCase();
    String[] words = line.split("\P{L}+");
    SplayEntry<String, Integer> entry = new SplayEntry<String, Integer>(null, null);
    for (int i = 0, n = words.length; i < n; i++) {
        Integer occurances = 0;
        entry.setWord(words[i]);
        entry.setFrequency(occurances);

        if (tree.contains(entry.equals(entry)) && entry.getFrequency() == 0) {
            occurances = 1;

        } else {
            int value = occurances.intValue();
            occurances = new Integer(value + 1);
            entry.setFrequency(occurances);
        }

        entry = new SplayEntry<String, Integer>(words[i], occurances);
        tree.insert(entry);
    }
}

我知道这还不是真正的工作,我需要帮助确定我应如何即时地介绍表演,以及按什么顺序? 我也希望这一方法在文字阵列中逐字逐字逐句地检查在树林内(斜体)的冶炼场中是否存在,如果这个词是新字,那么频率将是1,否则,频率将是+1。 最后,我只是把新的冶炼厂添加到斯温树中,让它陷入适当的节点。

现在,我只想把自己混为一谈,制定同样的法典,时间要超过必要的时间,我非常赞赏能够引导我正确方向的一些要点!

请告诉我,如果我不明白。

问题回答

我建议采用一种标准的方式执行play树,即没有 counter树,并且有单独的<代码>HashMap,用于频率。 这不是牺牲的复杂性,因为 s树的操作是O(log n),而“HashMap





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签