假设我有一个这样的字符串:
"IgotthistextfromapdfIscraped.HowdoIsplitthis?"
我想制作:
"I got this text from a pdf I scraped. How do I split this?"
我该怎么做?
答案 0 :(得分:3)
简短的回答:没有现实的机会。
答案很长:
唯一提示拆分字符串的提示是在字符串中查找有效的单词。所以你需要一个预期语言的字典,不仅包含根词,还包含所有的屈曲(是正确的语言术语吗?)。然后你可以尝试找到与你的字符串中的字符匹配的这些单词的序列。
答案 1 :(得分:3)
事实证明这个任务被称为word segmentation,并且有python library可以做到这一点:
>>> from wordsegment import load, segment
>>> load()
>>> segment("IgotthistextfromapdfIscraped.HowdoIsplitthis?")
['i', 'got', 'this', 'text', 'from', 'a', 'pdf', 'i', 'scraped', 'how',
'do', 'i', 'split', 'this']