字典
来源:互联网 发布:windows终端 编辑:程序博客网 时间:2024/04/29 10: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 boolean findto(String s)
{
int len = s.length();
for (int i=0; i<len; ++i)
{
char ch = s.charAt(i);
if (!(((ch > 'a') && (ch < 'z')) || ((ch>'A') && (ch < 'Z')) || ((ch > '0') && (ch < '9'))))
return true;
}
return false;
}
public Integer GetFreq(String word)
{
if(Find(word) == false)
{
return new Integer(0);
}
return (Integer)hm.get(word);
}
}
- 字典
- 字典
- 字典
- 字典
- 字典
- 字典
- 字典
- 字典
- 字典
- 字典
- 字典
- 字典
- 字典
- 字典
- 字典
- 字典
- 字典
- 字典
- Windows 系统环境变量(好用)
- 关于体力活
- Ruby on Rails上了老牌技术杂志Dr.Dobb's Journal的专题
- BREW接口的继承和多态
- 注册自定义URL协议
- 字典
- 返回值的理解
- 用ASP.NET写一个发送ICQ信息的程序
- ★Object Oriented Design Tips
- Assembly Language Reference
- Apache服务器主要配置文件httpd.conf中文注释
- FreeBSD下构建安全的Web服务器
- ASP.NET状态管理
- 我需要独处,清净