18 April 2007   3 comments   Python

Mind That Age!

This blog post is 11 years old! Most likely, its content is outdated. Especially if it's technical.

Spellcorrector being used on my not-yet-released web app I think a lot of Python people have seen Peter Novig's beautiful article about How to Write a Spelling Corrector. So have I and couldn't wait to write my own little version of it to fit my needs.

The changes I added were:

If you're still reading at this point it's quite likely that you're a coder so you'll prefer code to see how it works:

>>> from spellcorrector import Spellcorrector
>>> sc = Spellcorrector('en')
>>> sc.correct('caracter')
>>> sc.correct(u'caracter')
>>> sc.suggestions(u'caracter')
>>> sc.suggestions(u'spell')
[u'smell', u'shell', u'sell', u'spell', u'swell', u'spill', u'spells']
>>> sc.suggestions(u'spel')
[u'spell', u'sped']
>>> sc.suggestions(u'spel', detailed=True)
[{'count': 9, 'percentage': 90.0, 'word': u'spell'}, \
{'count': 1, 'percentage': 10.0, 'word': u'sped'}]
>>> # Physics database usage example
>>> sc.correct('Planck')
>>> sc.correct('Curie')
>>> sc.train(['Planck','Curie','Einstein','Heisenberg'])
>>> sc.correct('Planck')
>>> sc.correct('curie')
>>> sc.save('Physicist_words.txt')
>>> del sc
>>> file('Physicist_words.txt').read()

A lot more can probably be done to improve it but it works quite well as a foundation to an application that mimics Google's "Did you mean: ..." feature.

I've actually already implemented this on a search feature of a not-yet-launched website for art. Since the art site contains non-English names like "Corneille", "Doucet" or "Belartio" I had to train my spellcorrector for that particular application so that a perfectly fine search for "attentif" didn't become "Did you mean: _attentive_".

I'll blog more about that application once I get it up and running on a public domain.

To take this early code experiment for a spin download: spellcorrector-0.1.2.tar.bz2 (6.7Mb) spellcorrector-0.1.4.tar.bz2 (6.7Mb) spellcorrector-0.1.5.tar.bz2 (6.7Mb)



Hi Peter,

This looks interesting. I'm working on a Zope application and am looking for spelling support for epoZ.



Peter Bengtsson

That's now what this is for. For something for epoz I'd look for ispell or something.

BTW, why Epoz?? Why not ZTinyMCE?


Unfortunately the download file is not found. How can I reach it? Thanks

Your email will never ever be published

Related posts

Albert Einstein figurine head 12 April 2007
Guess my age with MOBi 21 April 2007
Related by Text:
jQuery and Highslide JS 08 January 2008
I'm back! Peterbe.com has been renewed 05 June 2005
Anti-McCain propaganda videos 12 August 2008
Ever wondered how much $87 Billion is? 04 November 2003
Guake, not Yakuake or Yeahconsole 23 January 2010