⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dictionary.java

📁 中文分词开源项目JAVA?形姆执士聪钅縅AVA?形姆执士聪钅縅AVA中文分词开源项目JAVA
💻 JAVA
字号:
package WordSegment;
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;
	}
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -