Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to split concatenated strings of this kind: "howdoIsplitthis?"

Suppose I have a string such as this:

"IgotthistextfromapdfIscraped.HowdoIsplitthis?"

And I want to produce:

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

How can I do it?

like image 984
Marcus Vinícius Monteiro Avatar asked Dec 13 '25 17:12

Marcus Vinícius Monteiro


1 Answers

It turns out that this task is called word segmentation, and there is a python library that can do that:

>>> from wordsegment import load, segment
>>> load()
>>> segment("IgotthistextfromapdfIscraped.HowdoIsplitthis?")
['i', 'got', 'this', 'text', 'from', 'a', 'pdf', 'i', 'scraped', 'how',
 'do', 'i', 'split', 'this']
like image 147
Marcus Vinícius Monteiro Avatar answered Dec 16 '25 11:12

Marcus Vinícius Monteiro



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!