python机器学习-乳腺癌细胞挖掘(博主亲自录制视频)https://study.163.com/course/introduction.htm?courseId=1005269003&utm_campaign=commission&utm_source=cp-400000000398149&utm_medium=share

机器学习,统计项目合作QQ:231469242

Lemmatizing with NLTK

# -*- coding: utf-8 -*-
"""
Spyder Editor This is a temporary script file.
""" import nltk
from nltk.stem import WordNetLemmatizer lemmatizer=WordNetLemmatizer()
#如果不提供第二个参数,单词变体还原为名词
#pythonly 无法还原,说明精确度仍然达不到100%
print(lemmatizer.lemmatize("cats"))
print(lemmatizer.lemmatize("cacti"))
print(lemmatizer.lemmatize("geese"))
print(lemmatizer.lemmatize("rocks"))
print(lemmatizer.lemmatize("pythonly"))
print(lemmatizer.lemmatize("better", pos="a"))
print(lemmatizer.lemmatize("best", pos="a"))
print(lemmatizer.lemmatize("run"))
print(lemmatizer.lemmatize("run",'v')) '''
cat
cactus
goose
rock
pythonly
good
best
run
run '''

A very similar operation to stemming is called lemmatizing. The
major difference between these is, as you saw earlier, stemming can
often create non-existent words, whereas lemmas are actual words.

So, your root stem, meaning the word you end up with, is not
something you can just look up in a dictionary, but you can look up a
lemma.

Some times you will wind up with a very similar word, but sometimes,
you will wind up with a completely different word. Let's see some
examples.

from nltk.stem import WordNetLemmatizer

lemmatizer = WordNetLemmatizer()

print(lemmatizer.lemmatize("cats"))
print(lemmatizer.lemmatize("cacti"))
print(lemmatizer.lemmatize("geese"))
print(lemmatizer.lemmatize("rocks"))
print(lemmatizer.lemmatize("python"))
print(lemmatizer.lemmatize("better", pos="a"))
print(lemmatizer.lemmatize("best", pos="a"))
print(lemmatizer.lemmatize("run"))
print(lemmatizer.lemmatize("run",'v'))

Here, we've got a bunch of examples of the lemma for the words that we use. The only major thing to note is that lemmatize takes a part of speech parameter, "pos." If not supplied, the default is "noun." This means that an attempt will be made to find the closest noun, which can create trouble for you. Keep this in mind if you use lemmatizing!

In the next tutorial, we're going to dive into the NTLK corpus that came with the module, looking at all of the awesome documents they have waiting for us there.

 

自然语言19.1_Lemmatizing with NLTK(单词变体还原)的更多相关文章

  1. 完全图解RNN、RNN变体、Seq2Seq、Attention机制

    完全图解RNN.RNN变体.Seq2Seq.Attention机制 本文主要是利用图片的形式,详细地介绍了经典的RNN.RNN几个重要变体,以及Seq2Seq模型.Attention机制.希望这篇文章 ...

  2. RNN-GRU-LSTM变体详解

    首先介绍一下 encoder-decoder 框架 中文叫做编码-解码器,它一个最抽象的模式可以用下图来展现出来: 这个框架模式可以看做是RNN的一个变种:N vs M,叫做Encoder-Decod ...

  3. Provide Several View Variants for End-Users 为最终用户提供多个视图变体

    In this lesson, you will learn how to provide several customized variants of the same View, and allo ...

  4. 【Visual Lisp】变体与安全数组

    (vlax-make-variant) ;;创建一个未初始化的变体 ;;01.整型值变体(setq myvar (vlax-make-variant 10)) ;;创建整型值变体,返回 #<va ...

  5. labview 变体数据类型

    变体数据类型是LabVIEW中多种数据类型的容器.将其它数据转换为变体时,变体将存储数据和数据的原始类型,保证日后可将变体数据反向转换. 例如,如将字符串数据转换为变体,变体将存储字符串的文本,以及说 ...

  6. Bootstrap 标签的变体 实例样式

    Bootstrap 标签样式,代码如下: <!DOCTYPE html> <html> <head> <title>Bootstrap 实例 - 标签的 ...

  7. 自然语言处理(1)之NLTK与PYTHON

    自然语言处理(1)之NLTK与PYTHON 题记: 由于现在的项目是搜索引擎,所以不由的对自然语言处理产生了好奇,再加上一直以来都想学Python,只是没有机会与时间.碰巧这几天在亚马逊上找书时发现了 ...

  8. Odoo / PS Cloud12版本中,产品变体功能如何使用

    场景: 产品:陶瓷马克杯 产品颜色变体:红色.蓝色.白色 产品尺寸变体:10CM.12CM.15CM 每个变体都有不同价格维度 odoo / PS Cloud 专业实施开发 EMAIL:1715860 ...

  9. 二叉查找树及B-树、B+树、B*树变体

    动态查找树主要有二叉查找树(Binary Search Tree),平衡二叉查找树(Balanced Binary Search Tree), 红黑树 (Red-Black Tree ), 都是典型的 ...

随机推荐

  1. Asp.Net Form验证不通过,重复登录

    问题产生根源: 当然,其实应该需要保持线上所有机器环境一致!可是,写了一个小程序.使用的是4.5,aysnc/await实在太好用了,真心不想把代码修改回去. so,动了念头,在这台服务器上装个4.5 ...

  2. 利用springframework+javax.mail发邮件(普通邮件、带附件邮件、HTML格式邮件)

    Spring提供了发送电子邮件的支持,可以发送普通邮件.带附件邮件.HTML格式邮件,甚至还可以使用Velocity模板定制化邮件内容. 一.引入相关的库 1 2 3 4 5 6 7 8 9 10 1 ...

  3. shell中逻辑与的两种表示方法

    bash中表示逻辑与的两种方法: (1)[ $state == "running" -a $name == "zone1" ] (2)[[ $state == ...

  4. 解决PHP生成UTF-8编码的CSV文件用Excel打开乱码的问题

    在要输出的内容前先输出"\xEF\xBB\xBF", eg:要输出的内容保存在$content里$content = "\xEF\xBB\xBF".$conte ...

  5. yii自动登录

    在yii,登录页面选择记住密码,下次就会自动登陆 前些天,自己增加了一个web应用,但是发现虽然选择记住密码,没选退出,关闭浏览器,重新进入还会跳转到登陆页面 自动登录是利用cookie实现的 配置U ...

  6. iOS7模拟器安装

    安装路径:/Library/Developer/CoreSimulator/Profiles/Runtimes 其中,后两个文件夹没有,需要手动创建. 把iOS7模拟器拖拽到Runtimes文件夹下即 ...

  7. SPOJ ORDERSET - Order statistic set

    ORDERSET - Order statistic set   In this problem, you have to maintain a dynamic set of numbers whic ...

  8. [NOIP2012] 提高组 洛谷P1079 Vigenère 密码

    题目描述 16 世纪法国外交家 Blaise de Vigenère 设计了一种多表密码加密算法――Vigenère 密 码.Vigenère 密码的加密解密算法简单易用,且破译难度比较高,曾在美国南 ...

  9. Java中使用JDBC

    JDBC简介 JDBC(Java Data Base Connectivity,java数据库连接)是一种用于执行SQL语句的Java API,可以为多种关系数据库提供统一访问,它由一组用Java语言 ...

  10. SQL数据操作和查询

    1.Oracle中可以把查询的结果根据结果集中的表结构和数据形成一张新表. CREATE TABLE 表名 AS SELECT语句,例如: CREATE TABLE INFOS1 AS SELECT  ...