0

I want to check if a string in Python is a collection of words using PyEnchant.
For example, I want to somehow check a concatenated string is a word or not:

eng = enchant.Dict("en_US")
eng.check("Applebanana")

I know this will return false, but I want it to return true, since Apple + banana are legit words by PyEnchant.

Adinia
  • 3,722
  • 5
  • 40
  • 58
taesu
  • 4,482
  • 4
  • 23
  • 41
  • 3
    There are endless combinations of legitimate words that are legal words when combined too. Countless others will look like subtle spelling mistakes. Then there are the combinations that when split *differently* become different words. Ever heard of `expertsexchange.com`? And how many words combined are we talking about here? You'll probably have to try out different splits manually and test those words against pyenchant. – Martijn Pieters Dec 18 '12 at 07:46
  • Thanks for your input. I thought the pyenchant library has some function that checks... crap! – taesu Dec 18 '12 at 07:48

1 Answers1

1

If you limit yourself to words combined from two other words, you can check the combinations yourself:

>>> s = "applebanana"
>>> splits = [(s[:i], s[i:]) for i in range(1,len(s))]
>>> splits
[('a', 'pplebanana'), ('ap', 'plebanana'), ('app', 'lebanana'), 
 ('appl', 'ebanana'), ('apple', 'banana'), ('appleb', 'anana'), 
 ('appleba', 'nana'), ('appleban', 'ana'), ('applebana', 'na'), 
('applebanan', 'a')]
>>> any((eng.check(item[0]) and eng.check(item[1])) for item in splits)
True

Of course you can expand that to more than two, but this should give you a general idea of where you're headed.

Tim Pietzcker
  • 328,213
  • 58
  • 503
  • 561