For my first reasonably substantial program, I wrote a Cobra version of Peter Norvig's spelling corrector: http://norvig.com/spell-correct.html
My version is several times longer than the Python version, mostly because I couldn't translate the set-builder expressions. Perhaps this is where LINQ will help?
For example, the Python version has:
- Code: Select all
def known_edits2(word):
return set(e2 for e1 in edits1(word) for e2 in edits1(e1) if e2 in NWORDS)
Whereas I have:
def known_edits2(word as String) as Set<of String>
result = Set<of String>()
for e1 in .edits1(word)
for e2 in .edits1(e1)
if e2 in _model.keys
result.add(e2)
return result
Also, the program takes three times longer to run on my machine, but this is because Python is freakishly fast at reading and splitting up the input text file. (I tried processing the file line-by-line instead of using readAllText, but that made things slower.)
I've attached my program. Any comments on style/performance welcome!