如何使用wordnet拆分列名并查找字典含义?

我要尝试使用以下数据来获取字典定义,但是仅当它是单个单词时才有效。我如何才能使它使用多个单词?

码:

from nltk.stem import WordNetLemmatizer
from nltk.corpus import wordnet

columns = ['Sector',
 'Community Name',
 'Date',
 'Community Center Point']

tmp = []

for x in columns:
    syns = (wordnet.synsets(x))
    tmp.append(syns[0].definition() if len(syns) > 0 else '')

输出:

pd.DataFrame(tmp).T

                        0    1                               2      3
a plane figure bounded by       the specified day of the month  

第1列和第3列为空,因为“社区名称”和“社区中心点”包含多个单词。

所需的输出:

                          0                                             1                                         2                                                                   3
Sector: [a plane figure...]   Community: [definition], Name: [definition]    Date: [the specified day of the month]  Community: [definition], Center: [definition], Point: [definition]
桑通克
from nltk.corpus import wordnet

columns = ['Sector', 'Community Name', 'Date', 'Community Center Point']

col_defs = []
for item in columns:
    tmp = []
    for word in item.split():
        syns = (wordnet.synsets(word))
        tmp.append(word+': '+syns[0].definition() if len(syns) > 0 else None)
    col_defs.append(', '.join(tmp))

for x in col_defs:
    print(x)

输出:

Sector: a plane figure bounded by two radii and the included arc of a circle
Community: a group of people living in a particular local area, Name: a language unit by which a person or thing is known
Date: the specified day of the month
Community: a group of people living in a particular local area, Center: an area that is approximately central within some larger region, Point: a geometric element that has position but no extension

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何使用 SQL 拆分列名属性和长度

来自分类Dev

如何使用awk拆分列?

来自分类Dev

如何查找字典值的长度

来自分类Dev

熊猫拆分列表列表系列以查找字数/行

来自分类Dev

熊猫拆分列名称

来自分类Dev

如何使用AWK gsub函数拆分列?

来自分类Dev

如何使用AWK gsub函数拆分列?

来自分类Dev

如何使用python 3拆分列表?

来自分类Dev

如何使用viewmodel值和查找字典设置数据网格行的背景颜色?

来自分类Dev

如何使用Python查找字典中所有键的所有子级

来自分类Dev

Rapidminer,如何拆分列?

来自分类Dev

使用Pandas拆分列

来自分类Dev

如何查找字典中是否存在密钥?

来自分类Dev

MongoDB:如何实现用于检查文本的查找字典

来自分类Dev

如何在列表中查找字典键值的索引?(Python)

来自分类Dev

如何在列表中查找字典键值的索引?(Python)

来自分类Dev

使用TCL查找字典中值的最大绝对值

来自分类Dev

使用Ruby在源文本中查找字典词

来自分类Dev

查找字典的不同值

来自分类Dev

查找字典中的值

来自分类Dev

Pandas / Python:基于字典的拆分列

来自分类Dev

如何使用范围在python中拆分列表?

来自分类Dev

如何使用命名字符拆分列表

来自分类Dev

如何使用 TornadoFx 创建嵌套/拆分列标题?

来自分类Dev

如何使用sql查询动态分组和拆分列?

来自分类Dev

如何使用bash按字符串拆分列?

来自分类Dev

使用Iseries SQL拆分列

来自分类Dev

使用Powershell拆分列表

来自分类Dev

使用字典在Python中拆分列表两部分