dictionary.java

来自「java开发的智能分词系统,经过编译可以运行!」· Java 代码 · 共 59 行

JAVA
59
字号
// 中文分词词典类
// Class for Dictionary
// 
import java.util.*;
import java.io.*;
import java.lang.*;

public class Dictionary
{
	HashMap hm;		//a word set
	
	public Dictionary()
	{
		hm = new HashMap();
	}
	
	public Dictionary(String fileName)
	{
		hm = new HashMap();
		Load(fileName);
	}

	public void Load(String fileName)
	{
		try 
		{
			BufferedReader in=
				new BufferedReader(
					new FileReader(fileName) );
			
			String s;
			String []words;
			while((s = in.readLine()) != null)
			{
				words = s.split("\t");
				Integer freq = new Integer(words[1]);
				hm.put(words[0], freq );
			}
		}
		catch(IOException e)
		{
			System.out.println("Error: " + e);
		}
	}

	public boolean Find(String word)
	{
		return hm.containsKey(word);
	}

	public Integer GetFreq(String word)
	{
		if(Find(word) == false)
		{
			return new Integer(0);
		}
		return (Integer)hm.get(word);
	}
}

⌨️ 快捷键说明

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