[英]how find the connecting words in text analysis in python?
我想檢查python文本分析中2個單詞之間的連接。當前使用python中的NLTK包。
例如, "Text = "
研究人員提出了成千上萬種特定的網絡類型,以對現有模型進行修改或調整。
在這里,如果我以networks
和researchers
身份輸入,那么我應該以“提議者”或“研究人員提議的網絡”形式輸出
你可以在兩個詞之間匹配正則表達式
import re
word_one = "networks"
word_two = "researchers"
string = "There are thousands of types of specific networks proposed by researchers as modifications or tweaks to existing models"
result = re.search(f'{word_one}(.+?){word_two}', string)
print(result.group(1))
湯姆的答案更干凈。 這是我的回答,沒有其他庫
找到每個單詞的位置,然后使用這些位置提取它
text = "There are thousands of types of specific networks proposed by researchers as modifications or tweaks to existing models"
word1 = "networks"
word2 = "researchers"
start = text.find(word1)
end = text.find(word2)
if start != -1 and end != -1 and start < end:
print(text[start + len(word1):end])
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.