课外天地 李树青学习天地Java程序语言课件 → [推荐]第二次上机作业的说明——分词


  共有14385人关注过本帖树形打印复制链接

主题:[推荐]第二次上机作业的说明——分词

帅哥哟,离线,有人找我吗?
admin
  1楼 博客 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信 管理员
等级:管理员 帖子:1940 积分:26616 威望:0 精华:34 注册:2003/12/30 16:34:32
[推荐]第二次上机作业的说明——分词  发帖心情 Post By:2008/3/25 22:42:21 [只看该作者]

public class WordSegmentation
{
        public static void main(String[] args)
        {
                String[] stopList = { "an", "and", "are", "as", "at", "be", "by",
                                "for", "from", "has", "he", "in", "is", "it", "its", "of",
                                "on", "that", "the", "to", "was", "were", "will", "with" };
                String doc = "The search trees overcome many issues of hash dictionary";
                java.util.Arrays.sort(stopList);
                String[] result = doc.toLowerCase().split("\\W");
                
                for(int i=0;i<result.length;i++)
                {
                        if(result[i].equals(""))
                                continue;
                        if(java.util.Arrays.binarySearch(stopList,result[i])<0)
                                System.out.println(result[i]);                  
                }
        }
}
[此贴子已经被作者于2010-12-12 08:24:12编辑过]

 回到顶部