【发布时间】:2019-02-02 13:23:43
【问题描述】:
我设计了一个红色字体动词短语的代码并将其输出为 HTML。
from __future__ import unicode_literals
import spacy,en_core_web_sm
import textacy
import codecs
nlp = en_core_web_sm.load()
sentence = 'The author is writing a new book. The dog is barking.'
pattern = r'<VERB>?<ADV>*<VERB>+'
doc = textacy.Doc(sentence, lang='en_core_web_sm')
lists = textacy.extract.pos_regex_matches(doc, pattern)
with open("my.html","w") as fp:
for list in lists:
search_word = (list.text)
fp.write(sentence.replace(search_word, '<span style="color: red">{}</span>'.format(search_word)))
电流输出
The author **is writing** a new book. The dog is barking.The author is writing a new book. The dog **is barking.**
句子重复了两次,第一次是写作,最后一次是吠叫。
预期输出:
The author **is writing** a new book. The dog **is barking.**
在将其发送到列表检查之前,我是否必须进行句子标记化?请帮忙?
【问题讨论】:
标签: html beautifulsoup nltk spacy