projetmbc
unread,Sep 5, 2010, 7:09:00 AM9/5/10Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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.