如何解决将文本段落转换为具有完整句子含义的多行-自然语言处理nlp
是否可以将段落转换为多个句子,并使最大措词保持不变,并根据需要调整几个?
这里是一个例子。跟进我当前的代码。我建议忽略代码,因为它只是一个开始。我需要在后续流程中提供帮助。
变量 b 是我的输入。
b = '''Wiring methods selected shall be compliant with BS 7671,robust,suitable
for the environment,accessible,rewireable and,where visible,neat and tidy
and in accord with the desired aesthetic. Preferred wiring methods for final
circuits are:'''
#nltk.download('punkt')
#nltk.download('averaged_perceptron_tagger')
import nltk.corpus
from nltk.text import Text
from nltk.corpus import stopwords
from nltk.tokenize import sent_tokenize,word_tokenize,regexp_tokenize
from tensorflow.keras.preprocessing.text import Tokenizer
import re
#b = [a.split('\n')]
Store_data = []
result = []
#sent_tokenize(a)
words = word_tokenize(b)
for val in range(0,len(words)):
i = words[val]
if ")" == i :
Store_data.append(int(val-1))
for val in Store_data:
new_val = words[val]
result.append(new_val)
if 'a' in result:
print("Passage have pointers existed")
else:
new_result = sent_tokenize(b)
for sentence in new_result:
tokenized_text = word_tokenize(sentence)
tagged = nltk.pos_tag(tokenized_text)
print(tagged)
_text = nltk.Text(i.lower() for i in tokenized_text)
new_result = _text.similar('with')
print(new_result)
我的预期输出看起来像这样:
1. Wiring methods selected shall be compliant with BS 7671
2. Wiring methods selected shall be robust
3. Wiring methods selected shall be suitable for the environment
4. Wiring methods selected shall be accessible
5. Wiring methods selected shall be rewireable
6. Wiring methods selected shall be,neat and tidy and in accord with the desired aesthetic.
我正在使用NLTK python库并完成了令牌化和 pos_tagging ,想了解下一步可能是正确的方向。由于段落在这种情况下可能会有所不同,因此我有代码。某些段落可能已经将这些点作为输出格式。因此,该方法可能会在相同的方法上起作用。
抱歉,我已经多年没有练习了。希望能听到我可以采取的任何快速指导和步骤,以实现这一目标。
谢谢 灰
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。