自然语言理解_实验报告

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

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

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

2、根据需要继续读取,即读取两个或三个字。利用map容器来存储统计结果。(2) 流程图(3) 代码字统计 #include #include #include #include using namespace std; /宋词的统计 void display_map(map &wmap); ofstream ofs(c:fenciout2.txt); int main() cout开始:endl; const char *szInputFileName=c:Text.txt; ifstream ifs(szInputFileName); string szTemp;string str1,str2

3、,str3,str;char a10;/ map wmap; /统计双字的 while (ifs)while(ifs.peek()=n) ifs.get();while(ifs.peek()= ) ifs.get();while(!ifs.peek()&0x80) ifs.get();ifs.get(a,3, );if(a0&0x80)str1=a;while(ifs.peek()=n) continue;while(ifs.peek()= ) continue;while(!ifs.peek()&0x80) ifs.get();ifs.get(a,3, );if(a0&0x80) str2=

4、a; if(str1!=,&str1!=。&str1!=?&str1!=!&str1!=&str2!=,&str2!=。&str2!=?&str2!=!&str2!=) szTemp=str1+str2; wmapszTemp+; if(ifs.peek()!=n&ifs.peek()!= ) ifs.seekg(-2,ios:cur);ifs.close();/三字ifstream ifs1(szInputFileName); while (ifs1) while(ifs1.peek()=n) ifs1.get();while(ifs1.peek()= ) ifs1.get();while(

5、!ifs1.peek()&0x80) ifs1.get();ifs1.get(a,3, );if(a0&0x80)str1=a;while(ifs1.peek()=n) continue;while(ifs1.peek()= ) continue;while(!ifs1.peek()&0x80) ifs1.get();ifs1.get(a,3, );if(a0&0x80) str2=a;else continue;while(ifs1.peek()=n) continue;while(ifs1.peek()= ) continue;while(!ifs1.peek()&0x80) ifs1.g

6、et();ifs1.get(a,3, );if(a0&0x80) str3=a;else continue; if(str1!=,&str1!=。&str1!=?&str1!=!&str1!=&str2!=,&str2!=。&str2!=?&str2!=!&str2!=&str3!=,&str3!=。&str3!=?&str3!=!&str3!=) szTemp=str1+str2+str3; wmapszTemp+; if(ifs1.peek()!=n&ifs1.peek()!= ) ifs1.seekg(-4,ios:cur);ifs1.close();/单字ifstream ifs2(s

7、zInputFileName); while (ifs2)while(ifs2.peek()=n) ifs2.get();while(ifs2.peek()= ) ifs2.get();while(!ifs2.peek()&0x80) ifs2.get();ifs2.get(a,3, );if(a0&0x80)str=a;if(str!=,&str!=。&str!=?&str!=!&str!=) szTemp=str; wmapszTemp+;ifs2.close(); display_map(wmap); return false; void display_map(map &wmap) i

8、nt sum=0; 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+) /计算词频 cout(first,second); coutsecond/(sum-1)endl; for (map_it=wmap.begin(); map_it!=wmap.end();map_it+) /计算词频 ofs(first,second);

9、ofssecond/sumendl; 宋词生成 #include #include #include #include using namespace std; void display_map(map &wmap); void ci(int a); map wmap; map wmapp; int main() cout开始:endl; const char *szInputFileName=c:Text.txt; ifstream ifs(szInputFileName); string szTemp,szTempp;string str1,str2,str;char a10;/ /统计双

10、字的 while (ifs)while(ifs.peek()=n) ifs.get();while(ifs.peek()= ) ifs.get();ifs.get(a,3, );if(a0&0x80)str1=a;while(ifs.peek()=n) continue;while(ifs.peek()= ) continue;ifs.get(a,3, );if(a0&0x80) str2=a; if(str1!=,&str1!=。&str1!=?&str1!=!&str1!=&str2!=,&str2!=。&str2!=?&str2!=!&str2!=) szTemp=str1+str2; wmapszTemp+; if(ifs.peek()!=n&ifs.peek()!= ) ifs.seekg(-2,ios:cur);ifs.close(); / display_map(wmap); /单字ifstream ifs1(szInputFileName); while (ifs1)while(ifs1.peek()=n) ifs1.get();while(ifs1.peek()= ) ifs1.get();ifs1.get(a,3, );if(a0&0x80)

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

当前位置:首页 > 大杂烩/其它

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