Lettercount
From MairasNetWiki
Contents |
Introduction
For quite some time I was wondering what would be the best way to create self-referential sentences in Finnish. In principle, their generation is just an optimization problem, but unfortunately the shape of the optimization terrain is particularly nasty. So, I wanted to try genetic algorithms (GA) to solve the problem. Here are the results.
Of course, there wasn't a really suitable GA library for Python available, so I took the Python Cookbook version and modified it to my liking (cue pygena).
The genetic algorithms didn't quite work. They found near-optimal (but still incorrect) solutions, but seemed to never stumble to the absolutely correct one. Next I tried a simple, stupid iterative search, and that seemed to work.
Note: I am fully aware of the rather stupid, straightforward implementation of the lettercount module. Sometimes it just pays off to sacrifice some (or a lot of) processor time to reduce the implementation time. That's why I used Python in this project in the first place, anyway.
Examples
Tämä virke sisältää kaksi d-, h- ja v-, kolme o-, r- ja u-, neljä l- ja y-, kuusi m-, seitsemän n- ja t-, yhdeksän j-, kymmenen e-, i- ja ä- sekä yksitoista a-, k- ja s-kirjainta.
Tämä virke sisältää yhden p-kirjaimen, kolme v-, neljä r-, viisi d-, h-, l- ja u-, kuusi y-, seitsemän j-, kahdeksan o-, yhdeksän m-, yksitoista n-, kolmetoista ä-, kuusitoista a- ja e-, seitsemäntoista t-, yhdeksäntoista k- sekä kaksikymmentäkaksi i- ja s-kirjainta.
Licence
The software is licenced under the X11 licence, which is a free and open-source licence, compatible with the GPL. The licence details can be found in the package.