[問題] 常規表達式找副詞

看板Python作者 (yuseke)時間10年前 (2015/12/08 17:35), 編輯推噓1(104)
留言5則, 4人參與, 最新討論串1/2 (看更多)
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://www.ptt.cc/bbs/Python/M.1449567300.A.AD5.html

12/08 17:39, , 1F
他只是在舉例而已......
12/08 17:39, 1F

12/08 17:43, , 2F
那如果我真的遇到這個問題的時候該怎麼辦呢?
12/08 17:43, 2F

12/08 17:45, , 3F
只能用字典來做, 或者因為有些副詞和其他詞性拼法相同,
12/08 17:45, 3F

12/08 17:45, , 4F
大概只能用 machine learning 來做; 自然語言分析很難的
12/08 17:45, 4F

12/08 20:56, , 5F
用NLTK做POS tagging 然後查 wordnet (?)
12/08 20:56, 5F
文章代碼(AID): #1MPgH4hL (Python)
討論串 (同標題文章)
文章代碼(AID): #1MPgH4hL (Python)