2017-09-29 158 views
2

假设我有一个字符串,如这样的:如何拆分这种连接字符串:“howdoIsplitthis?”

"IgotthistextfromapdfIscraped.HowdoIsplitthis?" 

我想生产:

"I got this text from a pdf I scraped. How do I split this?" 

我该怎么办呢?

+0

“wheeloffortune” - >“车轮”,“关闭”“或”“调”? –

+0

@RobertLozyniak ['python-wordsegment'](https://github.com/grantjenks/python-wordsegment)的'segment'函数将它分割成'['wheel','of','fortune']' 。尼斯不是? –

回答

2

事实证明,这个任务被称为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'] 
3

简答:没有现实的可能性。

龙答:

唯一的线索哪里拆分字符串在字符串中找到有效的话。所以你需要一个预期语言的词典,不仅包含词根,还包括所有的词语(这是否是正确的语言术语?)。然后,您可以尝试查找与您的字符串的字符匹配的这些单词的序列。

+0

...也许通过与“自动修复”的语法检查器 – theGleep

+0

[python-wordsegment](https://github.com/grantjenks/python-wordsegment/)库可以做我需要的案件。 –