View Single Post
Old 01-28-2017, 12:22 PM   #4
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 45,438
Karma: 27757438
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
I dont have the time to write the function for you, but it would go something like this:
Code:
words = text.split()
i = 0
while i < len(words) - 1:
      w1, w2 = words[i:i+2]
      if not dictionaries.recognized(w1) and not dictionaries.recognized(w2) and dictionaries.recognized(w1 + w2):
         words[i] = w1 + w2
         words[i+1] = ''
         i += 1
      i += 1
return ' '.join(words)
kovidgoyal is offline   Reply With Quote