Ganame - A Genetic Algorithm -Based File Renaming Tool

So should it be called AGABFRT instead? AGABaFiReT?

Author: Erkki Seppälä <flux@modeemi.fi>, aka flux (on IRCNet, FreeNode).

Ganame is a small toy that turned out to have some slight real-world usage potential also. The use case is this: you want to rename a bunch of files with some pattern, but you don't know how to express this pattern; perhaps you haven't yet mastered the Perl regular expressions and the s//-operator, or a certain detail of them has slipped your mind. Here Ganame comes into rescue: you provide it a set of examples and it tries to figure out the pattern in them.

Mind you, the pattern cannot be particularly complex, atleast not at the moment. Basically characters can be skipped, spaces can be converted to underscores and vice versa, the same with uppercase and lowercase, and changes in case and a fixed set of separators can be detected. It can also detect added strings, and infact without sufficient examples (ie. only one) it can easily diverge to using those. Also simple mappings are handled. List of supported operations:

Supported operations

I just want to try it out, now!

Okay. So I put a demo form up. I put in a limit of handling only one request concurrently as processing one query take at most 10 seconds. I hope the load doesn't become a problem.

It doesn't work!

Could happen. After all, it's basically just randomly evaluating predetermined rules if they fit. If you find it's giving wrong results, try giving it more examples.

Downloading

You can get Ganame 0.3 from here.

Latest Ganame is also available from its Darcs repository.

Building

To build it, you will need OCaml compiler (atleast 3.10.x due to ocamlbuild), findlib, ExtLib and PCRE OCaml (in Ubuntu: apt-get install ocaml-nox ocaml-findlib libpcre-ocaml-dev libextlib-ocaml-dev). After that you may run:

% ocamlbuild ganame.native

You may install the binary with:

% sudo install ganame.native /usr/local/bin/ganame

Or perhaps you want to install it to ~/bin instead.

Using

% ganame IMG_1234.JPG=img_1234.JPG -- *.JPG

In this instance and by luck in my test with a previous version, this produced the following plan:

Until(Separator,MapCopy(Lowercase)),Until(Separator,Copy),Until(ChangeCase,Copy),Until(ChangeCase,Copy)

Note that it didn't figure out that the . is a separator and it could've been used instead of detecting 'changed case' (numbers are considered to be lowercase at the moment).

After running it (it will finish in at most 10 seconds; slower or more heavily loaded hosts may get worse results), it will first list the renames it would perform and then interactively ask, if you wish to commit. If you just want to see what kind of plan it would produce, you may omit the -- and the file names.

Acknowledgements

I would've never tried this out if I hadn't read the book Essentials of Metaheuristics (well, atleast the first few chapters..). It's a very practical-oriented good read.

License

The software is licensed under the BSD license without the advertising clause. The software uses these two modules for core functionality:

levenstein.ml originates from Berke Durak's OCaml software page and it is apparently under Public Domain, although the page isn't quite exact about it.

genepool.mli and genepool.ml originate from Alex Rubinsteyn's GenePool which is licensed under LGPL v3. It is also slightly modified to allow custom comparison of fitness.