作者yuseke (yuseke)
看板Python
标题[问题] 常规表达式找副词
时间Tue Dec 8 17:34:57 2015
as title
这两天在看RE的部分
根据PYTHON 基金会的网站:
https://docs.python.org/2/library/re.html
7.2.5.7. Finding all Adverbs and their Positions¶
If one wants more information about all matches of a pattern than the matched
text, finditer() is useful as it provides instances of MatchObject instead of
strings. Continuing with the previous example, if one was a writer who wanted
to find all of the adverbs and their positions in some text, he or she would
use finditer() in the following manner:
>>> text = "He was carefully disguised but captured quickly by police."
>>> for m in re.finditer(r"\w+ly", text):
... print '%02d-%02d: %s' % (m.start(), m.end(), m.group(0))
07-16: carefully
40-47: quickly
关於""""for m in re.finditer(r"\w+ly", text):""""
这个部份我有一个疑问,
可是并不是所有的adv都有ly字尾.......
这种情形该怎麽处理呢?
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 36.226.195.60
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Python/M.1449567300.A.AD5.html
1F:推 tiefblau: 他只是在举例而已...... 12/08 17:39
2F:→ yuseke: 那如果我真的遇到这个问题的时候该怎麽办呢? 12/08 17:43
3F:→ uranusjr: 只能用字典来做, 或者因为有些副词和其他词性拼法相同, 12/08 17:45
4F:→ uranusjr: 大概只能用 machine learning 来做; 自然语言分析很难的 12/08 17:45
5F:→ bibo9901: 用NLTK做POS tagging 然後查 wordnet (?) 12/08 20:56