2017-09-29 47 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/)庫可以做我需要的案件。 –