?? dictionary.java
字號:
import java.io.*;
import java.util.*;
public class Dictionary implements Serializable
{
/**
*
*/
private static final long serialVersionUID = 1L;
private HashMap<String, Integer> dic = new HashMap<String, Integer>();
private int maxWordLength = 0;
private long wordsNumOfTrainDoc = 0;
/**
* @param newWord Add the word to dictionary
*/
public void addWord(String newWord)
{
if (newWord.length() > maxWordLength)
maxWordLength = newWord.length();
if (checkWord(newWord))
{
int t = (Integer)dic.get(newWord);
dic.put(newWord, new Integer(t + 1));
}
else
dic.put(newWord, new Integer(1));
wordsNumOfTrainDoc++;
}
public int getFrequency(String word)
{
if(checkWord(word))
return (Integer)dic.get(word);
else
return 0;
}
public boolean checkWord(String word) //Check if the word is in the dictionary
{
if (dic.get(word) == null)
return false;
else
return true;
}
public int getMaxLength() { return maxWordLength; }
public String toString()
{
Iterator keyIter = dic.keySet().iterator();
String value = new String();
while (keyIter.hasNext())
{
String key = (String)keyIter.next();
value += key + " " + getFrequency(key) + "\n";
}
return value;
}
public long getWordsNumOfTrainDoc() {
return wordsNumOfTrainDoc;
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -