繁体   English   中英

如何在python的文本分析中找到连接词?

[英]how find the connecting words in text analysis in python?

我想检查python文本分析中2个单词之间的连接。当前使用python中的NLTK包。

例如, "Text = "研究人员提出了成千上万种特定的网络类型,以对现有模型进行修改或调整。

在这里,如果我以networksresearchers身份输入,那么我应该以“提议者”或“研究人员提议的网络”形式输出

你可以在两个词之间匹配正则表达式

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM