已阅读5页,还剩32页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
分词系统工程报告分词系统工程报告 课程 自然语言理解 姓名 王佳淼 学号 2011914 班级 信息安全 11 1 日期 2013 11 2 实验一实验一 宋词字统计宋词字统计 一 研究背景一 研究背景 本实验所涉及的研究背景是利用计算机来 鉴赏 宋词 主要 针对宋词这种特殊的汉语诗歌体裁 开展了有关自动生成算法及其实 现方法的探索性研究 通过对大量语料的学习 来自动生成宋词 由于宋词自身的特性 能够在经过大量预料学习后 利用在宋词当 中出现频率较高的词语或者单字排列组合来生成宋词 二 实验所采用的开发平台及语言工具二 实验所采用的开发平台及语言工具 实验在 WIN7 的环境下利用 VC 编程 三 系统设计三 系统设计 1 算法基本思想 从文本中字符 判断是否为中文字符 全角字符 若为全角字 符则根据需要继续读取 即读取两个或三个字 利用 map 容器来存 储统计结果 2 流程图 3 代码 字统计 include include include include using namespace std 宋词的统计 void display map map ofstream ofs c fenciout2 txt int main cout 开始 endl const char szInputFileName c Text txt ifstream ifs szInputFileName string szTemp string str1 str2 str3 str char a 10 map wmap 统计双字的 while ifs while ifs peek n ifs get while ifs peek ifs get while ifs peek ifs get a 3 if a 0 while ifs peek n continue while ifs peek continue while ifs peek ifs get a 3 if a 0 if str1 wmap szTemp if ifs peek n ifs close 三字 ifstream ifs1 szInputFileName while ifs1 while ifs1 peek n ifs1 get while ifs1 peek ifs1 get while ifs1 peek ifs1 get a 3 if a 0 while ifs1 peek n continue while ifs1 peek continue while ifs1 peek ifs1 get a 3 if a 0 else continue while ifs1 peek n continue while ifs1 peek continue while ifs1 peek ifs1 get a 3 if a 0 else continue if str1 wmap szTemp 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 a 0 if str wmap szTemp ifs2 close display map wmap return 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 计算词频 cout first second cout second sum 1 endl for map it wmap begin map it wmap end map it 计算词频 ofs first second ofs second sum endl 宋词生成 include include include include using namespace std void display map map 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 a 10 统计双字的 while ifs while ifs peek n ifs get while ifs peek ifs get ifs get a 3 if a 0 while ifs peek n continue while ifs peek continue ifs get a 3 if a 0 if str1 wmap szTemp if ifs peek n 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 a 0 if str wmapp szTemp ifs1 close display map wmapp int as while 1 cout 请随意输入一个数来创造宋词 输入 0 时退出 as if as 0 return 0 ci as cout endl endl cout endl cout endl endl return false void ci int a cout 如梦 令 endl map iterator map it for int i 0 i 3 i map it wmap begin for int j 0 j rand a 2 wmap size j map it cout first cout for i 0 i 3 i map it wmap begin for int j 0 j rand a j map it cout first cout for i 0 i 2 i map it wmap begin for int j 0 j rand wmap size j map it cout first map it wmapp begin for int j 0 j rand a 3 wmapp size j map it cout first cout for i 0 i 3 i map it wmap begin for int j 0 j rand a wmap size j map it cout first cout map it wmap begin for j 0 jfirst cout temp temp for i 0 i 3 i map it wmap begin for int j 0 j a rand wmap size j map it cout first cout endl void display map map for map it wmap begin map it wmap end map it cout first second endl 四 系统演示与分析四 系统演示与分析 1 截图 字统计 宋词生成 如梦令 2 结果分析 五 对次实验的感想 意见和建议五 对次实验的感想 意见和建议 通过此次实验 能熟练利用 MAP 容器 为接下来的两个实验 打好基础 也能对汉字进行操作 清楚的了解到汉字在计算机中的 存储方式有别于字符型 利用位运算 人民日报的词频统计 typedef pair PAIR vector vecpair void display map map ofstream ofs c fenciout txt int cmp const PAIR int main cout 开始 endl const char szInputFileName c cidian txt ifstream ifs szInputFileName string szTemp string str1 str2 str3 str char a 100 map wmap map wmapok 统计 while ifs szTemp int i 0 ifs a i 逐个字符读入 if ifs eof break if a i if a i continue while a i 读取 szTemp a i i ifs a i wmap szTemp 对应字频加 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 中的 first 是词 而且降序排列 for int i 0 i vecpair size i ofs vecpair i first vecpair i second endl display map wmap return 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 计算词频 在界面上输出 此时是无序的 cout first second cout second sum endl 四 系统演示与分析四 系统演示与分析 1 截图 排序后 2 结果分析 五 对次实验的感想 意见和建议五 对次实验的感想 意见和建议 在这次实验后 能含有分词字符的文件进行读取 利用语料来 训练程序 并将结果保存在文件当中 以便实验三可以使用 而且 能够进行排序 按照 value 的值 即词语出现次数由高到低进行排 序 美中不足的是 程序运行速度有待提高 由于 map 是按照键值 排序的 所以引入了 vector 并利用 vector 的 sort 函数进行排序 熟悉了这两种容器的使用 提高了对 c 库函数的认识 实验三实验三 人民日报分词人民日报分词 一 研究背景一 研究背景 自动词法分析就是利用计算机对自然语言的形态 morphology 进行分析 判断词的结构和类别等 自动分词是汉语句子分析的基 础 而且 词语的分析具有广泛的应用 词频统计 词典编纂 文 章风格研究等 二 模型方法二 模型方法 正向最大匹配算法 Forward MM FMM 这种算法使得程序简 单易行 开发周期短 而且仅需要很少的语言资源 词表 不需要 任何词法 句法 语义资源 三 系统设计三 系统设计 1 算法基本思想 FMM 算法描述 1 令 i 0 当前指针 pi 指向输入字串的初始位置 执行下面的操 作 2 计算当前指针 pi 到字串末端的字数 即未被切分字串的长度 n 如果 n 1 转 4 结束算法 否则 令 m 词典中最长单词的字 数 如果 n m 令 m n 3 从当前 pi 起取 m 个汉字作为词 wi 判断 a 如果 wi 确实是词典中的词 则在 wi 后添加一个切分标志 转 c b 如果 wi 不是词典中的词且 wi 的长度大于 1 将 wi 从右端去 掉一个字 转 a 步 否则 wi 的长度等于 1 则在 wi 后添加一个 切分标志 单字 执行 c 步 c 根据 wi 的长度修改指针 pi 的位置 如果 pi 指向字串末端 转 4 否则 i i 1 返回 2 4 输出切分结果 结束分词程序 2 流程图 图 1 分词流程图 图 2 FMM 算法流程图 3 代码 include include include include include include using namespace std 人民日报的词频统计 typedef pair PAIR vector vecpair ofstream ofs c fenciout txt int cmp const PAIR int main cout 开始 endl const char szInputFileName c cidian txt ifstream ifs szInputFileName string szTemp string str1 str2 str3 str char a 100 map wmap map wmapok 统计 while ifs szTemp int i 0 ifs a i 逐个字符读入 if ifs eof break if a i if a i continue while a i szTemp a i i ifs a i wmap szTemp 对应字频加 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 中的 first 是词 而且降序排列 for int i 0 i vecpair size i ofs vecpair i first endl ofs close ifstream infile2 infile2 open c fenciout txt ios in if infile2 cerr 文件打开错误 endl exit 1 vectorarr1 arr2 1 是读取词典 2 是存储分好的句子 string word string text 台湾是中国领土不可分割的一部分 这是大势所趋 cout 原句是 台湾是中国领土不可分割的一部分 这是大势 所趋 endl 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 分词结果为 endl for vector iterator iter arr2 begin iter arr2 end iter cout iter cout endl endl endl return 四 系统演示与分析四 系统演示与分析 1 截图 对于语料库中没有出现的词语 2 结果分析 在测试的范围内 对于语料库中含有的句子能完美分词 但对 于一些句子中含有非语料库词语的情况并不能很好的完成分词 但 这一缺陷可以通过加大语料库 加强语料训练来弥补 对于未登录 词语 在程序中并没有加以实现 所以在测试中并没有进行着方面 测试 五 对次实验的感想 意见和建议五 对次实验的感想 意见和建议 通过这次实验 能顺利对测试句子进行分词 利用实验二的词 频统计结果和 FMM 算法对语句进行分词操作 由于 FMM 算法的 缺陷 以及语料信息不全等众多因素 分词时 召回率不是很高 可以考虑采用双向最大匹配算法来进行分词 确信可以弥补这一缺 陷 尽可能大的消除奇异 这次实验使得我对 FMM 算法的认识有 了一定程度上的加深 对分词的各类算法都有了较深入的接触 感想与建议感想与建议 自然语言理解是人工智能研究的一个重要方面 可以认为它一 门新兴的边缘学科 它研究能实
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026年全国安全员C证考试真题卷(附解析)
- 高青智能终端全产业链智造基地项目可行性研究报告模板-立项拿地
- 中小学几何最值培优课程案
- 2027届贵州省铜仁伟才学校九上化学期末调研试题含解析
- 2027届河北省高邑县九年级化学第一学期期中达标检测模拟试题含解析
- 吉林省德惠市2027届化学九上期末监测试题含解析
- 开学安全知识问答题目和答案
- 海南省儋州市2027届九上物理期末综合测试试题含解析
- (新)小区建筑垃圾清运合同协议书范本-正式版
- 写作商品说明书CDB市公开课获奖课件省名师示范课获奖课件
- 语文中考经验分享精彩演讲稿
- 《地铁车辆运营技术规范(试行)》
- 化工行业打非治违工作总结
- 2024北京北师大实验初三开学考物理试题及答案
- 离婚协议标准版(有两小孩)
- 2023年湖北省就业援藏事业单位山南籍高校毕业生招聘考试真题
- 暴聋突发性耳聋的中医辩证及护理方案
- 工程经济学(第6版)全套教学课件
- 建设工程质量检测方案-技术标部分
- 海水分析化学
- JJF 1986-2022 差压式气密检漏仪校准规范
评论
0/150
提交评论