【发布时间】:2014-03-17 11:06:43
【问题描述】:
我有一堆不相关的段落,我需要遍历它们以找到类似的事件,例如,给定搜索 object falls,我找到一个布尔值 True 用于包含以下内容的文本:
- 盒子从架子上掉下来
- 灯泡摔在地上
- 一块石膏从天花板上掉下来
还有False:
- 责任落在了莎拉身上
- 气温骤降
我可以使用 nltk 到 tokenise、tag 并获得 Wordnet synsets,但我发现很难弄清楚如何适应nltk 的运动部件一起达到预期的效果。在寻找同义词之前我应该chunk 吗?我应该写context-free grammar 吗?从 treebank 标记转换为 Wordnet 语法标记时是否有最佳实践? nltk book 没有解释这些,我在nltk cookbook 上也找不到。
答案中包含pandas 的答案可获得奖励积分。
[编辑]:
一些开始工作的代码
In [1]:
from nltk.tag import pos_tag
from nltk.tokenize import word_tokenize
from pandas import Series
def tag(x):
return pos_tag(word_tokenize(x))
phrases = ['Box fell from shelf',
'Bulb shattered on the ground',
'A piece of plaster fell from the ceiling',
'The blame fell on Sarah',
'Berlin fell on May',
'The temperature fell abruptly']
ser = Series(phrases)
ser.map(tag)
Out[1]:
0 [(Box, NNP), (fell, VBD), (from, IN), (shelf, ...
1 [(Bulb, NNP), (shattered, VBD), (on, IN), (the...
2 [(A, DT), (piece, NN), (of, IN), (plaster, NN)...
3 [(The, DT), (blame, NN), (fell, VBD), (on, IN)...
4 [(Berlin, NNP), (fell, VBD), (on, IN), (May, N...
5 [(The, DT), (temperature, NN), (fell, VBD), (a...
dtype: object
【问题讨论】:
-
以前发过similar question,但我希望至少能用
pseudocode来吸引答案。