自然语言处理实验报告

上传人:枫** 文档编号:563230721 上传时间:2022-08-11 格式:DOCX 页数:33 大小:203.24KB
返回 下载 相关 举报
自然语言处理实验报告_第1页
第1页 / 共33页
自然语言处理实验报告_第2页
第2页 / 共33页
自然语言处理实验报告_第3页
第3页 / 共33页
自然语言处理实验报告_第4页
第4页 / 共33页
自然语言处理实验报告_第5页
第5页 / 共33页
点击查看更多>>
资源描述

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

1、“自然语言处理”实验报告专业:智能科学与技术班级:1501学号:姓名:日期:2018/4/16目录实验1 31、实验目的: 32、实验原理和内容: 33、实验环境和编程语言: 34、主要功能及实现: 35、实验结论 8实验2 中文分词 81、实验目的和内容 82、实验原理 93、实验平台及语言 104、主要功能及实现 114.1 算法流程图114.2实验结果115、实验结论13实验三 中文文本分类 131、小组成员以及分工132、实验目的和内容 133、实验原理以及数据处理144、实验平台和语言 165、实验结果166、实验结论16四、实验1-3 代码17实验11、实验目的:本实验学习如何在利

2、用NLTK进行分词词性分析与句法分析,。通过次实 验项目的练习,增强学生对课堂理论知识的理解,帮助学生以知识获取与 自主实践相结合,学习对英文自然语言信息的处理的实践。2、实验原理和内容:NLTK自然语言处理工具包,里面包含了许多处理自然语言的库可以直接 调用,本实验利用NLTK对obamao txt语料库进行对应的分词和词频统 计,再对布朗语料库进行词性和句法分析。3、实验环境和编程语言:windows 下 anaconda3 spyder(python3.6)4、主要功能及实现:4.1怎样载入自己的英文语料库(obama.txt),在自己的语料库中找出 responsibility, ed

3、ucation和working出现的频率及其他们词干出现的频率。(使用 nltk的英文分词函数tokenize和stem)使用open以及read函数读取obama.txt文档,调用nltk里面的word_tokenize() 函数,先把文档进行分词,再调用nltk中的FreDist()函数进行词频统计。统计 responsibility, education 和 working 出现的频率。结果见表一。提取词干的时候, NLTK 中提供了三种最常用的词干提取器接口,即 Porterstemmer, Lancaster Stemmer 和 Snowball Stemmer。统计词干频率时,先对

4、全 文提取词干(whole_stems),然后在提取的词干中统计三者词干出现的频率,结果 见表二。表一 原词以及对应词干频率统计r esp on sibility( resp ons)educati on( educ)wor ki ng(wo rk)原词出现频率8112词干出现频率91112全文总词数:3066 全文总词干数:3066)表二 三种词干提取器提取结果Porter stemmerLan caste r Stemme rSno wball Stemme rresp on sibilityresponsresponsresponseducati oneduceduceducworkin

5、gwo rkwo rkwo rk4.2 写程序处理布朗语料库,找到以下答案:4.2.1 哪些名词常以他们复数形式而不是它们的单数形式出现?(只考虑常规的复数形式,-s后缀形式的)。 先查看布朗语料库里面包含的类别(如图一)In 5 : runfil 皂( Ds/spyderi/INatrualExpe rime nt py wdir= D;:/spyderx 序)1 adventure? pbelle5_letire51j 1editorialj fiction *j governmenthobbies1 j humor1 lea rn 亡 cT lc r亡mystery1 news 1 r

6、亡 1 i 呂 ionreviewsR j romancesczience_fiction In &;图一 布朗语料库包含类别 选取其中一个类别的语料库 adventure,提取里面的所有 NNS 标注的复数词放入word_double提取NN标注而非NNS标注的单数词放入word_single然后对这两个词表提取词干,比较两个词干表里面相同的词干,同时去除里面重复出现的词干,然后再在复数词表里面找出这些词。可得常以复数不以单数出现的词有:handseyesclothesfoolskidsn ightshor ses mountainshills fences wingsbuildi ngsr

7、ifles frie ndswarsEyesride rshopessprings sn akeshouses times lightsRide rstro ubleskeysrocksLooksbootslooksciga rettes str eetscoun ties autho ritiesmea nsdeputiesmurders HousesSp ringssaloons bars attackersholes Zeros powe rselbowsLights office rs feeli ngs wate rs thr oats lifeboats isla nds un c

8、les mothe rs hai rs valleys Hills Commanders kills offices centers farmers horns products talks marines murderers stores persons4.2.2选择布朗语料库的不同部分(其他目录),计数包含wh的词:H J 严-H*r” Xi, r-T T Tl r. rl +.吕 C =N lr 1+ DEC TVarloLle tHplorerFi-le SMplcrrIFython consolafl Xr| Console 1 /A |此处我查找新闻(news)类别里面包含wh的词

9、,结果如图二Ln53 : mu n f ile ( 1D/ s py da r S J? /Nat r u a IE up e rime ni:. py j. wd ir= 1D py d e rl J? 1 ) itfheat: 1 wherever: 1whips 2 whipped: 2 wholesale: 1 whichever; 1 whisking: 1 why! 14 wheeled: 2 wholly e d s 1 whims; 1 where59 whiplash: 1 which: 245 whereby; 3 white 57 wheels: 1 who: 2BE w

10、heel: 4 whites: 2 when: 169 haterer;: 2whose: 22white-clad: 1while: 55 wholly1图二布朗语料库新闻类别中包含wh的词wheat: 1 whe reve r: 1 whip: 2 whipped: 2 wholesale: 1 whicheve r: 1whisk ing: 1 why: 14 wheeled: 2 wholly-ow ned: 1 whims: 1 where: 59whiplash: 1 which: 245 wher eby: 3 white: 57 wheels: 1 who: 268 wheel

11、: 4whites: 2 whe n: 169 whateve r: 2 whose: 22 white-clad: 1 while: 55 wholly: 1whethe r: 18 what: 95 whopp ing: 1 whole:321 whom: 8 whi rli ng: 1 whiz: 24.3、输出brown文本集名词后面接的词性,结果如图三In &0 ! runfile D:/spyderz序日lExpErim已nt,pywdir= D:/spyderj?)ADP. VERBMOLIMCOMJADVDETPRT ADJNUM PROMX|1175& 78556S22.39

12、13882$SSB56356232图三brown文本集名词后面接的词性由统计可知:名词后面出现频率最高的是ADP (介词和后置词)第二是标点第三是动词 依次是名词、连接词、副词、限定词、PRT、形容词、数量词、代名词、以及其他。4.4 句法分析演示使用nltk的句法分析器parser (自底向上)nltk.app.srparser()后打开以下窗口,运行step 会逐步演示对 my dog saw a manin the park with a statue这句话进行文法分析。结果见图四、图五 Shift Reduce Parser Application;ile dit Apply View

13、 Animate HelpAvailable FLeduulonsStackS-NPVP hJP-L:6tFJ NP-NPPP 卵- yp FP 卵-VNPFP VFiNF PPt PNP NP T Det.-Thp- Det-a- N- man v-sa柑 2 in P- with N v park1 N -=- dog N-statue Det-rn/Remaining Text图四parser句法分析器nltk.app.rdparser() 使用递归下降解析器(自顶向下),进行文法分析 文法=词法+句法f RtBirarTP CiriEerL Fe 测 肚 Jdii Ajy Mi Jii

14、ruM bHpL-sriQieoswT E肚E 字rr*-*- r nrHP亠T id - fu Da-irHmilliraED:i EfTREDp ii 亠 xwH MeEcapi-Slip IJkavtap 11 i*cMr*c I图五 rdparser 递归下降解析器4.5 对话框系统图六Enter a number in the range 1-5: 1TherapistTalk to the program by typing; in plain English using normal upper-and lower-case letters and punctuation Enter quif when doneHello- Hb闍 are you feeling: today?goodwhy do you say that good?1 eat s lot and feel very happy.you eat a lot and feel very happy.叩PPlease tell me more.my mother chated with me and tol

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

当前位置:首页 > 学术论文 > 其它学术论文

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