自然语言理解 实验报告

上传人:小** 文档编号:56331373 上传时间:2018-10-11 格式:DOC 页数:37 大小:896KB
返回 下载 相关 举报
自然语言理解 实验报告_第1页
第1页 / 共37页
自然语言理解 实验报告_第2页
第2页 / 共37页
自然语言理解 实验报告_第3页
第3页 / 共37页
自然语言理解 实验报告_第4页
第4页 / 共37页
自然语言理解 实验报告_第5页
第5页 / 共37页
点击查看更多>>
资源描述

《自然语言理解 实验报告》由会员分享,可在线阅读,更多相关《自然语言理解 实验报告(37页珍藏版)》请在金锄头文库上搜索。

1、分词系统工程报告分词系统工程报告 课程:自然语言理解 姓名:王佳淼 学号:2011914 班级:信息安全 11-1 日期:2013-11-2 实验一实验一 宋词字统计宋词字统计 一研究背景一研究背景 本实验所涉及的研究背景是利用计算机来“鉴赏”宋词。主要 针对宋词这种特殊的汉语诗歌体裁,开展了有关自动生成算法及其实 现方法的探索性研究。通过对大量语料的学习,来自动生成宋词。 由于宋词自身的特性,能够在经过大量预料学习后,利用在宋词当 中出现频率较高的词语或者单字排列组合来生成宋词。 二实验所采用的开发平台及语言工具二实验所采用的开发平台及语言工具 实验在 WIN7 的环境下利用 VC+编程。

2、三系统设计三系统设计 (1)算法基本思想 从文本中字符,判断是否为中文字符(全角字符) ,若为全角字 符则根据需要继续读取,即读取两个或三个字。利用 map 容器来存 储统计结果。 (2)流程图 (3)代码 字统计 #include #include #include #include using namespace std; /宋词的统计 void display_map(map ofstream ofs(“c:fenciout2.txt“); int main() cout wmap; /统计双字的 while (ifs) while(ifs.peek()=n) ifs.get(); wh

3、ile(ifs.peek()= ) ifs.get(); while(!ifs.peek() ifs.get(a,3, ); if(a0 while(ifs.peek()=n) continue; while(ifs.peek()= ) continue; while(!ifs.peek() ifs.get(a,3, ); if(a0 if(str1!=“,“ wmapszTemp+; if(ifs.peek()!=n ifs.close(); /三字 ifstream ifs1(szInputFileName); while (ifs1) while(ifs1.peek()=n) ifs1.

4、get(); while(ifs1.peek()= ) ifs1.get(); while(!ifs1.peek() ifs1.get(a,3, ); if(a0 while(ifs1.peek()=n) continue; while(ifs1.peek()= ) continue; while(!ifs1.peek() ifs1.get(a,3, ); if(a0 else continue; while(ifs1.peek()=n) continue; while(ifs1.peek()= ) continue; while(!ifs1.peek() ifs1.get(a,3, ); i

5、f(a0 else continue; if(str1!=“,“ wmapszTemp+; if(ifs1.peek()!=n ifs1.close(); /单字 ifstream ifs2(szInputFileName); while (ifs2) while(ifs2.peek()=n) ifs2.get(); while(ifs2.peek()= ) ifs2.get(); while(!ifs2.peek() ifs2.get(a,3, ); if(a0 if(str!=“,“ wmapszTemp+; ifs2.close(); display_map(wmap); return

6、false; void display_map(map map:const_iterator map_it; for (map_it=wmap.begin(); map_it!=wmap.end();map_it+) / 统计总数 sum+=map_it-second; for (map_it=wmap.begin(); map_it!=wmap.end();map_it+) / 计算词频 coutfirstsecondsecond/(sum-1)firstsecondsecond/sum #include #include #include using namespace std; void

7、 display_map(map void ci(int a); map wmap; map wmapp; int main() coutas; if(as=0) return 0; ci(as); cout:iterator map_it; for(int i=0;ifirst; coutfirst; coutfirst; map_it=wmapp.begin(); for( int j=0;jfirst; coutfirst; coutfirst; coutfirst; cout for (map_it=wmap.begin(); map_it!=wmap.end();map_it+) c

8、outfirstsecond #include #include #include #include #include using namespace std; /人民日报的词频统计 typedef pair PAIR; vector vecpair; void display_map(map ofstream ofs(“c:fenciout.txt“); int cmp(const PAIR int main() cout wmap; map wmapok; /统计 while (ifs) szTemp=“; int i=0; ifsai;/逐个字符读入 if(ifs.eof() break

9、; if(!(ai if(!(ai continue; while(ai!=/)/读取 szTemp+=ai; i+; ifsai; wmapszTemp+;/对应字频加 1 ifs.close(); /map 根据 value 排序 map:const_iterator curr; for(curr=wmap.begin();curr!=wmap.end();+curr) vecpair.push_back(make_pair(curr-first,curr-second); sort(vecpair.begin(),vecpair.end(),cmp);/调用排序函数,则 vecpair

10、中的 first 是词,而且降序排列 for(int i = 0 ;i “ map:const_iterator map_it; for (map_it=wmap.begin(); map_it!=wmap.end();map_it+) / 统计总数 sum+=map_it-second; for (map_it=wmap.begin(); map_it!=wmap.end();map_it+) / 计算词频,在界面上输出,此时是无序的 coutfirstsecondsecond/sum #include #include #include #include #include using na

11、mespace std; /人民日报的词频统计 typedef pair PAIR; vector vecpair; ofstream ofs(“c:fenciout.txt“); int cmp(const PAIR int main() cout wmap; map wmapok; /统计 while (ifs) szTemp=“; int i=0; ifsai;/逐个字符读入 if(ifs.eof() break; if(!(ai if(!(ai continue; while(ai!=/) szTemp+=ai; i+; ifsai; wmapszTemp+;/对应字频加 1 ifs.

12、close(); /map 根据 value 排序 map:const_iterator curr; for(curr=wmap.begin();curr!=wmap.end();+curr) vecpair.push_back(make_pair(curr-first,curr-second); sort(vecpair.begin(),vecpair.end(),cmp);/调用排序函数,则 vecpair 中的 first 是词,而且降序排列 for(int i = 0 ;iarr1,arr2;/1 是读取词典,2 是存储分好的句子 string word; string text=“台

13、湾是中国领土不可分割的一部分,这是大势所趋。 “; cout=0;i-=2) if(find(arr1.begin(),arr1.end(),temp1)!=arr1.end() temp1+=“/“; arr2.push_back(temp1); p1=i; break; else temp1=temp2.substr(0,i-2); temp2=temp2.substr(p1);/还没有分的赋值给 temp1 temp1=temp2; cout:iterator iter=arr2.begin();iter!=arr2.end();+iter) cout*iter; coutendlend

14、lendl; return; 四系统演示与分析四系统演示与分析 (1)截图 对于语料库中没有出现的词语: (2)结果分析 在测试的范围内,对于语料库中含有的句子能完美分词,但对 于一些句子中含有非语料库词语的情况并不能很好的完成分词。但 这一缺陷可以通过加大语料库,加强语料训练来弥补。对于未登录 词语,在程序中并没有加以实现,所以在测试中并没有进行着方面 测试。 五对次实验的感想、意见和建议五对次实验的感想、意见和建议 通过这次实验,能顺利对测试句子进行分词。利用实验二的词 频统计结果和 FMM 算法对语句进行分词操作,由于 FMM 算法的 缺陷,以及语料信息不全等众多因素,分词时,召回率不是

15、很高。 可以考虑采用双向最大匹配算法来进行分词,确信可以弥补这一缺 陷,尽可能大的消除奇异。这次实验使得我对 FMM 算法的认识有 了一定程度上的加深,对分词的各类算法都有了较深入的接触。 感想与建议感想与建议 自然语言理解是人工智能研究的一个重要方面,可以认为它一 门新兴的边缘学科。它研究能实现人与计算机之间用自然语言进行 有效通信的各种理论和方法。 我是信息安全的学生,这门课程其实并不是信息安全专业的特 色课程。选修这门课程的原因有两个,一是因为对人工智能研究的 好奇和兴趣,人工智能有很好很广阔的发展前景,我相信这门课程 会对我以后的发展起到不小的帮助;二是因为在做与此相关的创新 项目,项目是关于在语音中屏蔽敏感非法字符的。通过选修这门课 程,我能熟练对汉字进行操作和比对,对分词中经常遇到的各类歧 义情况有了深入的了解,例如交集型歧义和组合型歧义在分词时候 应该注意什么,对于未登录词的处理方法等。 孙晓老师为人风趣,讲课条理清楚

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 商业/管理/HR > 管理学资料

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号