java,scala通过ansj分词 并做去除停词处理
来源:互联网 发布:京东数据开放平台 编辑:程序博客网 时间:2024/06/05 07:30
下载ansj jar<dependency> <groupId>org.ansj</groupId> <artifactId>ansj_seg</artifactId> <version>0.9</version></dependency>
java版本
List<Term> parse = NlpAnalysis.parse("山东威海隧道发生交通事故 造成9死1伤3人失踪");new NatureRecognition(parse).recognition(); //词性标注HashMap<String, String> strHashMap = new HashMap<String, String>();//读取停词文件String stopWordTable = "F://360downloads/StopWordTable.txt";File f = new File(stopWordTable);try { FileInputStream fileInputStream = new FileInputStream(f);//读入停用词文件 BufferedReader StopWordFileBr = new BufferedReader(new InputStreamReader(fileInputStream, "GBK")); String stopWord = null; for (; (stopWord = StopWordFileBr.readLine()) != null; ) { strHashMap.put(stopWord, "_stop"); } StopWordFileBr.close(); FilterModifWord.setUpdateDic(strHashMap); List<Term> term = FilterModifWord.modifResult(parse); //根据词性做一些业务上的判断 List list = new ArrayList(); for(int i=0;i<term.size();i++){ String word = term.get(i).getName(); //拿到词 String nature=term.get(i).getNatrue().toString().split(":")[0];//拿到词性 // System.out.println(word+":"+nature); if(nature.equals("d")){ if((term.get(i+1).getNatrue().toString().split(":")[0]).equals("a")){ String w = word+term.get(i+1).getName(); list.add(w); } }else{ if(i>0 && (term.get(i-1).getNatrue().toString().split(":")[0]).equals("d") && nature.equals("a")){ System.out.println("移除这一条数据"); }else{ list.add(word); } } } for(int i=0;i<list.size();i++){ System.out.println(list.get(i)); }} catch (Exception e) { e.printStackTrace();}
scala版本val parse = ToAnalysis.parse("山东威海隧道发生交通事故 造成9死1伤3人失踪
")//new NatureRecognition(parse).recognition(); //词性标注val strHashMap = new util.HashMap[String, String]val file = Source.fromFile("F://360downloads/StopWordTable.txt", "GBK")for (line <- file.getLines) { strHashMap.put(line, "_stop")}file.closeFilterModifWord.setUpdateDic(strHashMap)val term = FilterModifWord.modifResult(parse)System.out.println(term)
阅读全文
0 0
- java,scala通过ansj分词 并做去除停词处理
- 【java自然语言处理】ansj分词
- spark scala 用ansj分词
- Java中文分词器Ansj
- solr6使用ansj做中文分词
- elasticsearch中ANSJ中文分词处理
- python 去除停用词 结巴分词
- python27使用jieba分词,去除停用词
- ansj 分词
- ansj 分词
- Ansj分词
- ansj分词
- 开源 Java 中文分词器 Ansj
- Java中文分词器Ansj的使用
- Ansj中文分词Java开发小记
- 基于java的中文分词工具ANSJ
- 【Java】利用Ansj中文分词工具对段落进行切词
- 自然语言处理之分词器ansj和hanlp介绍
- CentOS 7使用yum安装MySql5.6.24
- springboot整合mybatis
- Python的实例方法,类方法,静态方法之间的区别及调用关系
- android-async-http框架库使用基础
- Hadoop的过去、现在和未来
- java,scala通过ansj分词 并做去除停词处理
- 配置远程连接MySQL数据库
- 输入框动态调整大小
- Booting the Linux Kernel Without an initrd/initramfs
- Linux离线安装sysstat(sar,iostat,sysstat)
- jquery截取地址栏中url参数的值
- ios通用链接(Universal Link)的处理
- LeetCode专栏L020_Valid_Parentheses
- Spring加载applicationContext.xml的路径问题