问题描述
是否可以将段落转换为多个句子,并使最大措词保持不变,并根据需要调整几个?
这里是一个例子。跟进我当前的代码。我建议忽略代码,因为它只是一个开始。我需要在后续流程中提供帮助。
变量 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 (将#修改为@)