NLTK多词分词器对大小写敏感。我想同时适用于大写和小写。

2024-06-30 15:45:53 发布

您现在位置:Python中文网/ 问答频道 /正文

NLTK Mutli word tokenzier works区分大小写。我想同时为大写和小写字母工作

tk.add_mwe(('The', 'questions'))

适用于单词问题

但对于单词问题

请给出解决方案或替代方案


Tags: theadd解决方案单词tkword区分questions
1条回答
网友
1楼 · 发布于 2024-06-30 15:45:53

我建议使用优秀的FlashText库。 它可以以不区分大小写的方式定位多词表达式(mwe)。 从文档中提取这些mwe后,可以将它们添加到MWETokenizer(与文档中的大小写相同)。然后标记文档。你知道吗

以下代码说明了此过程:

from flashtext import KeywordProcessor

keyword_processor = KeywordProcessor()

keyword_processor.add_keyword('The questions')
keyword_processor.add_keyword('Starting Point')

sentence = "the questions are the starting point"
keywords_found = keyword_processor.extract_keywords(sentence, span_info=True)

keywords_found

from nltk.tokenize import MWETokenizer
tokenizer = MWETokenizer()
for a in keywords_found:
    tokenizer.add_mwe(sentence[a[1]: a[2]].split())

tokenizer.tokenize(sentence.split())

输出:

['The_questions', 'are', 'the', 'starting_point']

相关问题 更多 >