昆明理工大学-正向最大匹配算法分词_第1页
昆明理工大学-正向最大匹配算法分词_第2页
昆明理工大学-正向最大匹配算法分词_第3页
昆明理工大学-正向最大匹配算法分词_第4页
昆明理工大学-正向最大匹配算法分词_第5页
已阅读5页,还剩3页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

昆明理工大学信息工程与自动化学院学生实验报告〔2015—2016学年第1学期〕课程名称:信息检索与搜索引擎技术开课实验室:信自楼4442015年11月12日年级、专业、班计科122学号201210405204姓名邹华宇成绩实验工程名称正向最大匹配算法分词指导教师李卫疆教师评语该同学是否了解实验原理: A.了解□ B.根本了解□ C.不了解□该同学的实验能力: A.强□ B.中等□ C.差□该同学的实验是否到达要求: A.到达□ B.根本到达□ C.未到达□实验报告是否标准: A.标准□ B.根本标准□ C.不标准□实验过程是否详细记录: A.详细□ B.一般□ C.没有□教师签名:年月日一、上机目的及内容1、设计程序实现正向最大匹配算法。2、利用正向最大匹配算法将以下语句进行分词,输出分词后的结果。d1:北京安立文高新技术公司d2:新一代的网络访问技术d3:北京卫星网络d4:是最先进的总线技术d5:北京升平卫星技术的新技术有二、实验原理及根本技术路线图三、所用仪器、材料1台PC及Eclipse软件四、实验过程原始记录建立Java工程FMMAlgorithm建立类FMM,编写代码实现该类,如下图运行结果如图示FMM.java代码如下:packagemodel;importjava.io.*;importjava.util.*;publicclassFMM{ privateStringsource; privateStringresult; privateStringdictionaryPath; publicFMM(Stringsource){ this.source=source; this.result=""; this.dictionaryPath="Dictionary.txt"; } publicFMM(Stringsource,StringdictionaryPath){ this.source=source; this.result=""; this.dictionaryPath=dictionaryPath; } publicStringgetSource(){ returnsource; } publicStringgetResult(){ returnresult; } publicArrayList<String>setDictionary(){ ArrayList<String>dictionaryList=newArrayList<String>(); try{ FiledictionaryFile=newFile(this.dictionaryPath); if(!dictionaryFile.exists()){ System.out.println("Can'tFindDictionaryfile!"); returndictionaryList; } Scannerinput=newScanner(dictionaryFile); while(input.hasNext()){ dictionaryList.add(input.nextLine()); } input.close(); }catch(FileNotFoundExceptione){ System.out.println(e.toString()); } returndictionaryList; } publicintdictionaryMaxLength(){ returndictionaryMaxLength(setDictionary()); } publicintdictionaryMaxLength(ArrayList<String>dictionaryList){ intwordMaxLength=0; for(inti=0;i<dictionaryList.size();i++){ if(wordMaxLength<dictionaryList.get(i).length()) wordMaxLength=dictionaryList.get(i).length(); } returnwordMaxLength; } publicStringLeft(Stringsource,intlength){ returnsource.substring(0,length); } publicStringRight(Stringsource,intlength){ returnsource.substring(length); } publicvoidforwardMaximumMatch(){ forwardMaximumMatch(this.source); return; } publicvoidforwardMaximumMatch(Stringsource){ forwardMaximumMatch(source,setDictionary()); return; } publicvoidforwardMaximumMatch(Stringsource,ArrayList<String>dictionaryList){ Stringresult=""; Stringtemp=""; intwordMaxLength=dictionaryMaxLength(dictionaryList); while(!source.isEmpty()){ if(source.length()>=wordMaxLength) temp=Left(source,wordMaxLength); else temp=Left(source,source.length()); intmatchLength=wordMaxLength; do{ if(!dictionaryList.contains(temp)){ temp=Left(temp,matchLength-1); matchLength--; }else break; }while(temp.length()!=1); result+=temp+"/"; if((source=Right(source,temp.length())).isEmpty()) result=result.substring(0,result.length()-1); } this.result=result; return; } publicstaticvoidmain(String[]args){ String[]strSentence={"北京升平卫星技术的新技术有。。。", "北京安立文高新技术公司", "新一代的网络访问技术", "北京卫星网络", "是最先进的总线技术。。。" }; for(inti=0;i<strSentence.length;i++){ FMMtest=newFMM(strSentence[i]); test.forwardMaximumMatch(); System.out.println("语句"+(i+1)+":"); if(strSentence[i].isEmpty()) System.out.println("分词语句为空!未进行分词"); else{ System.out.println("分词前的语句:"+strSentence[i]); Sys

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论