![](https://img-blog.csdnimg.cn/20201014180756918.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Python
qq_34505594
这个作者很懒,什么都没留下…
展开
-
剑指offer面试题4--在二维数组中搜索整数
JavaMethod 1: search from the upper right corner,you can search from the lower left corner also.package offer;public class num4_searchInMatrix { /* * description: * in a two-dimensional a...原创 2019-12-18 16:20:32 · 106 阅读 · 0 评论 -
查找重复数
剑指offer-面试题3javapackage offer;/* * description: * find the duplicated number in the array * there are n numbers in the array range from 0 to n-1. * There are some duplicated numbers in the...原创 2019-12-17 20:00:14 · 123 阅读 · 0 评论 -
21. Merge Two Sorted Lists
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.Example:Input: 1->2->4, 1->3->4Output: 1-...原创 2019-08-19 21:08:27 · 78 阅读 · 0 评论 -
Python自然语言处理第二章部分习题
本人初学自然语言处理,如有错误,欢迎指正!--------------------------------------------------------------------------------------------------------P58处理布朗语料库的新闻和言情文体,找出一周中最有新闻价值和最浪漫的日子。days=['Monday','Tuesday','Wednesday',...原创 2018-03-09 13:04:13 · 3920 阅读 · 3 评论 -
python自然语言处理第三章:处理原始文本
1.访问《罪与罚》的英文翻译:from urllib import urlopenurl="http://www.gu tenberg.org/files/2554/2554.txt"raw=urlopen(url).read()type(raw)进程read()将需要几秒来下载这本书。如果Internet代理Python无法正确检测出来,需要用下面的方式手动指定代理。proxies={'http...原创 2018-03-09 13:03:25 · 1476 阅读 · 0 评论 -
python自然语言处理第一二章
随笔记录,有待完善。1.text1.concordance("word") 在text1中搜索word这个词 text2.similar("word") 在text1中搜索在类似上写问中出现的词 text2.comon_text("word1","word2") 在text2中搜索研究共用两个或两个以上词汇的上下文 text2.dispersion_plot(["word1"...原创 2018-03-09 13:02:54 · 284 阅读 · 0 评论 -
python自然语言处理第四章笔记
1.赋值。传递对象的引用。**#改变链表中嵌套链表内的一个项目,全部都改变。引用同一个链表。>>>empty=[]>>>nested=[empty,empty,empty]>>>nested[[],[],[]]>>>nested[1].append('python')>>>nested[['pytho原创 2018-03-09 13:02:12 · 432 阅读 · 0 评论 -
python自然语言处理第五章
1.词性标注器。import nltktext=nltk.word_tokenize('and now for something completely different')nltk.pos_tag(text)CC并列连词,RB副词,IN介词,JJ形容词2.NLTK中提供了每个标记的文档,可以使用标记来查询,如:nltk.help.upenn_tagset('RB')或正则表达式,如:nltk....原创 2018-03-09 13:01:23 · 577 阅读 · 0 评论 -
python自然语言处理第五章习题
3.分词和标注下面的句子:They wind back the clock,while we chase after the wind.句子中包含哪些不同的发音和词类?import nltks='They wind back the clock,while we chase after the wind's1=nltk.word_tokenize(s)s2=nltk.pos_tag(s1) ...原创 2018-03-09 13:00:37 · 2048 阅读 · 0 评论 -
python自然语言处理第四章习题
6.创建n-gram的滑动窗口的方法在下面两种极端情况下是否正确:n=1,n=len(sent)?正确sent=['the','dog','gave','john','the','newspaper']n=3[sent[i:i+n] for i in range(len(sent)-n+1)]9.编写代码删除字符串开头和结尾处的空白,规范词之间的空格并使其成为一个单独的空格字符。a.使用split...原创 2018-03-09 13:00:06 · 1209 阅读 · 1 评论 -
python自然语言处理第六章
1.分类是为给定的输入选择正确的类标签。建立在训练语料基础之上的分类,叫做监督式分类。创建分类器第一步是决定什么样的特征是相关的,以及如何为这些特征编码。下面的特征提取器函数建立了一个字典,其中包含给定名称的相关信息。def gender_features(word): return {'last_letter':word[-1]}gender_features('shrek')这个函数返回...原创 2018-03-09 12:59:27 · 1024 阅读 · 0 评论 -
python自然语言处理第七章
1.句子分割器,分词器和词性标注器。def ie_preprocess(document): sentences=nltk.sents_tokenize(document) sentences=[nltk.word_wokenizes(sent) for sent in sentences] sentence=[nltk.pos_tag(sent) for sent in sen...原创 2018-03-09 12:58:50 · 690 阅读 · 0 评论 -
python自然语言处理第六章习题
2.使用本章所述的3种分类器之一,以及你能想到的任何特征。尽可能好地建立一个名字性别分类器。从将名字语料库分成3个子集开始:500个词为测试集,500个词为开发测试集,剩余6900个词为训练集。然后从示例的名字性别分类器开始,逐步改善。使用开发测试集检查你的进展。一旦对分类器感到满意,在测试集上检查它的最终性能。相比在开发测试集上的性能,它在测试集上的性能如何?这是你期待的吗?import nlt...原创 2018-03-09 12:58:10 · 1060 阅读 · 1 评论 -
python自然语言处理第三章习题
+:项目中的一个或多个实例*:项目中的零个或多个实例 +和*有时被称作闭包^:匹配字符串的开始\s:匹配所有空白字符\w:匹配词中的字符,字母,数字,下划线\W:匹配所有字母、数字、下划线以外的字符\S:是\s的补\b:词边界(零宽度)\d:任一十进制数字\D:任何非数字字符\t:制表符8.编写一个工具函数,以url为参数,返回删除所有HTML标记的URL内容。使用那个url.urlopen访问...原创 2018-03-09 12:57:41 · 1840 阅读 · 0 评论 -
python自然语言处理第八章
1.使用符合语句规则的子串表接收器。def init_wfst(tokens,grammar): numtokens=len(tokens) wwfst=[[None for i in range(numtokens+1)] for j in range(numtokens+1)] for i in range(numtokens): productions=grammar.productio...原创 2018-03-09 12:57:02 · 375 阅读 · 0 评论 -
python自然语言处理第一章部分习题
6.制作《理智与情感》中4个主角:Elinor,Marianne,Eward,和Willoughby的分布图。在这部小说中关于男性和女性所扮演的不同角色,你能观察到什么?你能找出一对夫妻吗?import nltkfrom nltk.book import *freq=FreqDist(text2)cfd=nltk.ConditionalFreqDist((word,fdist[word]) for...原创 2018-03-09 12:56:26 · 771 阅读 · 0 评论