Suggestion about enchant.DictWithPWL and suggest

19 views
Skip to first unread message

projetmbc

unread,
Sep 5, 2010, 7:09:00 AM9/5/10
to pyenchant users
Hello,
I've tried the following code.

========================================
#! /usr/bin/env python3

import enchant

d = enchant.DictWithPWL("en_US", "listOfWords.txt")

theExamples = [
'print( d.check("hello") )',
'print( d.suggest("hello") )',
'print( d.check("trucMuche") )',
'print( d.suggest("trucMuche") )'
]

for oneExample in theExamples:
print('---', oneExample, sep="\n")
exec(oneExample)
========================================


The answer is the following one :

===============================================
---
print( d.check("hello") )
True
---
print( d.suggest("hello") )
['hello', 'hell', 'hellos', 'cello', 'Cello', 'hallo', 'hullo',
'hells', 'hell o']
---
print( d.check("trucMuche") )
True
---
print( d.suggest("trucMuche") )
['truculence', 'truculent', 'truncheon', 'truckle']
===============================================


It could be better that the word "trucMuche" appears in the last
suggestion. I think that the problem comes from the fact that the
suggestion is done by enchant. If it is the case, for words added by
using a text file, you could implement something like the following
code :

===============================================================
#! /usr/bin/env python3
import difflib

test = {
'cite' : ['citation', 'cit', 'thisfile', 'table'],
'katr' : ['cinq', 'neuf', 'quatre', 'neuf'],
'katre' : ['cinq', 'neuf', 'huit'],
'cents' : ['cent', 'huit'],
'sens' : ['cent', 'huit'],
'trucmu' : ['trucMuche', 'bibop'],
}

for oneWord, listOfWordForComparisons in test.items():
print(oneWord, listOfWordForComparisons, sep = ' :: ')
print( '\t' + str(difflib.get_close_matches(oneWord,
listOfWordForComparisons)) )
===============================================================

This could be a patch.

Ryan Kelly

unread,
Sep 8, 2010, 6:17:04 PM9/8/10
to pyencha...@googlegroups.com


Thanks, I've implemented and variation on this and suggestions from the
PWL now appear in the suggestions for the DictWithPWL. Will appear in
the next release.


Ryan

--
Ryan Kelly
http://www.rfk.id.au | This message is digitally signed. Please visit
ry...@rfk.id.au | http://www.rfk.id.au/ramblings/gpg/ for details

signature.asc

projetmbc

unread,
Sep 9, 2010, 5:52:49 PM9/9/10
to pyenchant users
Thanks for this.
Reply all
Reply to author
Forward
0 new messages