summaryrefslogtreecommitdiffstats
path: root/ktouch/extras/training-gen
diff options
context:
space:
mode:
Diffstat (limited to 'ktouch/extras/training-gen')
-rw-r--r--ktouch/extras/training-gen/c/README8
-rw-r--r--ktouch/extras/training-gen/c/english_conf13
-rw-r--r--ktouch/extras/training-gen/c/ktouchgen.c233
-rw-r--r--ktouch/extras/training-gen/perl/README80
-rw-r--r--ktouch/extras/training-gen/perl/dk.config19
-rw-r--r--ktouch/extras/training-gen/perl/en.config15
-rw-r--r--ktouch/extras/training-gen/perl/es.config17
-rwxr-xr-xktouch/extras/training-gen/perl/ktouch-gen.pl180
-rw-r--r--ktouch/extras/training-gen/perl/no.config20
-rw-r--r--ktouch/extras/training-gen/python/README5
-rw-r--r--ktouch/extras/training-gen/python/english_conf190
-rw-r--r--ktouch/extras/training-gen/python/ktouchgen.py269
12 files changed, 1049 insertions, 0 deletions
diff --git a/ktouch/extras/training-gen/c/README b/ktouch/extras/training-gen/c/README
new file mode 100644
index 00000000..230ed429
--- /dev/null
+++ b/ktouch/extras/training-gen/c/README
@@ -0,0 +1,8 @@
+To get files with words:
+$ aspell dump master hash_file
+
+Compile the program:
+$ gcc ktouchgen.c -o ktouchgen
+
+Run the program:
+$ ./ktouchgen english_conf english_word english.ktouch
diff --git a/ktouch/extras/training-gen/c/english_conf b/ktouch/extras/training-gen/c/english_conf
new file mode 100644
index 00000000..121a6ee6
--- /dev/null
+++ b/ktouch/extras/training-gen/c/english_conf
@@ -0,0 +1,13 @@
+jf
+kd
+ls
+ai
+en
+vu
+ir
+oc
+pq
+wm
+bp
+ty
+xz
diff --git a/ktouch/extras/training-gen/c/ktouchgen.c b/ktouch/extras/training-gen/c/ktouchgen.c
new file mode 100644
index 00000000..dbb2dcf2
--- /dev/null
+++ b/ktouch/extras/training-gen/c/ktouchgen.c
@@ -0,0 +1,233 @@
+/***************************************************************************
+ main.c - description
+ -------------------
+ begin : Wed Mar 21 21:39:53 EST 2001
+ copyright : (C) 2001 by Haavard Froeiland 2264228
+ email : havard@student.unsw.edu.au
+
+ ***************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <ctype.h>
+#include <time.h>
+
+#define max 50
+
+typedef struct WordNode *WordList;
+
+struct WordNode
+{
+ char *word;
+ struct WordNode *next;
+};
+
+void *addWord(WordList first, char w[])
+{
+ struct WordNode *ptr;
+
+ ptr=malloc(sizeof(struct WordNode));
+ ptr->word=strdup(w);
+ ptr->next=first;
+ return ptr;
+}
+
+void printWordList(WordList l)
+{
+ struct WordNode *ptr=l;
+ /* loop throug the linked list */
+ while(ptr!=NULL)
+ {
+ printf("%s\n",ptr->word);
+ ptr=ptr->next;
+ }
+}
+
+void printLevel(FILE *f,char *l[])
+{
+ int pos=0;
+ int line=0;
+ int arrayMax=0;
+ int arrayPos=0;
+
+ while(l[arrayMax]!=NULL)
+ {
+ arrayMax++;
+ }
+
+ if (arrayMax == 0) return;
+ /* loop throug the linked list */
+ while(line<30)
+ {
+ arrayPos=((float)rand()/RAND_MAX)*arrayMax;
+ pos=pos+strlen(l[arrayPos]);
+ fprintf(f,"%s",l[arrayPos]);
+ if(pos>40)
+ {
+ fprintf(f,"\n");
+ pos=0;
+ line++;
+ }
+ else
+ {
+ pos++;
+ fprintf(f," ");
+ }
+ }
+}
+
+
+void creatLevelList(WordList l,char *levelList[],char s_or[], char s_and[])
+{
+ struct WordNode *ptr=l;
+ int i;
+ int j;
+ int pos=0;
+ bool or_failed;
+ bool and_failed;
+
+ /* loop throug the linked list */
+ while(ptr!=NULL)
+ {
+ /* loop through the word */
+ /* printf("%s\n",ptr->word); */
+ i=strlen(ptr->word)-1;
+ for(;i>=0;i--)
+ {
+
+ or_failed=true;
+ j=strlen(s_or)-1;
+ for(;j>=0;j--)
+ {
+ if(ptr->word[i]==s_or[j])
+ {
+ or_failed=false;
+ j=-1;
+ }
+ }
+
+ and_failed=true;
+ j=strlen(s_and)-1;
+ for(;j>=0;j--)
+ {
+ if(ptr->word[i]==s_and[j])
+ {
+ and_failed=false;
+ j=-1;
+ }
+ }
+
+ if(or_failed==true)
+ {
+ i=-1;
+ }
+ }
+ if(or_failed==false && and_failed==false)
+ {
+ levelList[pos]=ptr->word;
+ pos++;
+ /* printf("%d\n",pos); */
+ }
+
+ ptr=ptr->next;
+ }
+ levelList[pos]=NULL;
+}
+
+
+int main(int argc, char *argv[])
+{
+ time_t lt;
+ FILE *file;
+ WordList list=NULL;
+ char *levelList[100000];
+ char word[max];
+ char test[100];
+ int i=0;
+ char *s[50];
+
+ if(argc<4)
+ {
+ printf("\nUsage: ktouchgen ConfigFile WordFile TrainingFile\n");
+ exit(0);
+ }
+
+ /**
+ * Read in the configFile
+ *
+ */
+ if((file = fopen(argv[1],"r"))==NULL)
+ {
+ printf("can't open config_file:%s for reading",argv[2]);
+ }
+ i=0;
+ while(!feof(file))
+ {
+ fscanf(file,"%s",word);
+
+ s[i]=strdup(word);
+ printf("%s\n",s[i]);
+ i++;
+ }
+ s[i]=NULL;
+ fclose(file);
+
+
+
+ /**
+ * Read in the wordFile and add each word to the list
+ *
+ */
+ printf("Starting reading words");
+ if((file = fopen(argv[2],"r"))==NULL)
+ {
+ printf("can't open word_file:%s for reading",argv[2]);
+ }
+ while(!feof(file))
+ {
+ fscanf(file,"%s",word);
+ list=addWord(list, word);
+ }
+ fclose(file);
+
+
+ if((file = fopen(argv[3],"w"))==NULL)
+ {
+ printf("Error when writing to file:%s",argv[3]);
+ }
+
+ lt = time(NULL);
+ fprintf(file,"#############################################################\n");
+ fprintf(file,"# Rrainingfile genereated %s",ctime(&lt));
+ fprintf(file,"# Program written by Håvard Frøiland\n");
+ fprintf(file,"#############################################################\n\n");
+
+ strcpy(test,"");
+
+ i=0;
+ while(s[i]!=NULL)
+ {
+ if (strlen(test) + strlen(s[i]) + 1 > sizeof(test))
+ {
+ printf("Buffer overflow.\n");
+ exit(1);
+ }
+ strcat(test,s[i]);
+ fprintf(file,"# Level %d\n",i+1);
+ fprintf(file,"%s\n", s[i]);
+ creatLevelList(list,levelList,test,s[i]);
+ printLevel(file,levelList);
+ fprintf(file,"\n");
+ i++;
+ }
+ fclose(file);
+
+ return EXIT_SUCCESS;
+}
+
diff --git a/ktouch/extras/training-gen/perl/README b/ktouch/extras/training-gen/perl/README
new file mode 100644
index 00000000..557a7468
--- /dev/null
+++ b/ktouch/extras/training-gen/perl/README
@@ -0,0 +1,80 @@
+###################################################################
+#
+# ktouch-gen.pl
+#
+# written by: Steinar Theigmann <steinart@incatel.no>
+# Håvard Frøiland <havard.froiland@chello.no>
+#
+# This file describes how to generate your own training files
+# in 3. steps.
+#
+
+
+Step 1: Collect data
+
+The script needs a data file with words, one word on each line. You
+can create it in your editor, or you can get it generated (see
+below). You will also find some data files in cvs.
+
+Suggestion for creating your own data file using an excisting dictionary. See http://aspell.sourceforge.net for more info.
+
+$ aspell dump master
+
+This will print out a looong list with words in the default
+language. If you have installed other languages that you want to use
+you can write:
+
+$ aspell dump master norwegian
+
+This will print out all the norwegian words found in the norwegian
+ditionary.
+
+Since we don't want this word on the screen, but in a file we do this:
+
+$ aspell dump master > ~/your-word-file
+
+You will now have a file called your-word-file stored in your home directory.
+
+
+Step 2: Creat a configuration file
+
+The config file is shown below.
+
+<---- the file starts here ---->
+length-of-line 20
+number-of-line 10
+
+jf
+kd
+ls
+ca
+nt
+iv
+me
+hr
+go
+bp
+qu
+wn
+cx
+yz
+ABCDEFGHIJKLMNOPQRSTUVWXYZ
+<---- the file ends here ---->
+
+The length of a line is set to be 20 characters, and each level should
+be 10 lines loong. The first level will only contain combinations of
+"jf" and the next one will contain "jfkd" and so on.
+
+Save it to a file called your-config-file, and we are ready to try the script.
+
+
+Step 3: Generate your training file
+
+To test the script you should do this:
+
+$ perl ktouch-gen.pl your-config-file < your-word-file
+
+This will print out the newly generated training file to your screen,
+if you are happy with it, you could save it to file by doing this.
+
+$ perl ktouch-gen.pl your-config-file < your-word-file > your-training-file.ktouch
diff --git a/ktouch/extras/training-gen/perl/dk.config b/ktouch/extras/training-gen/perl/dk.config
new file mode 100644
index 00000000..409a07ca
--- /dev/null
+++ b/ktouch/extras/training-gen/perl/dk.config
@@ -0,0 +1,19 @@
+length-of-line 12
+number-of-line 6
+
+jf
+kd
+ls
+øa
+nt
+iv
+me
+hr
+go
+bp
+qå
+wn
+cæ
+x
+,.
+ABCDEFGHIJKLMNOPQRSTUVWYZÆØÅ \ No newline at end of file
diff --git a/ktouch/extras/training-gen/perl/en.config b/ktouch/extras/training-gen/perl/en.config
new file mode 100644
index 00000000..bb5df1ae
--- /dev/null
+++ b/ktouch/extras/training-gen/perl/en.config
@@ -0,0 +1,15 @@
+jf
+kd
+ls
+ca
+nt
+iv
+me
+hr
+go
+bp
+qu
+wn
+cx
+yz
+ABCDEFGHIJKLMNOPQRSTUVWXYZ
diff --git a/ktouch/extras/training-gen/perl/es.config b/ktouch/extras/training-gen/perl/es.config
new file mode 100644
index 00000000..49b8b32d
--- /dev/null
+++ b/ktouch/extras/training-gen/perl/es.config
@@ -0,0 +1,17 @@
+length-of-line 30
+number-of-line 20
+jf
+kd
+ls
+caá
+ntñ
+iví
+meé
+hr
+goó
+bp
+quü
+wnñ
+cx
+yz
+ABCDEFGHIJKLMNOPQRSTUVWXYZ
diff --git a/ktouch/extras/training-gen/perl/ktouch-gen.pl b/ktouch/extras/training-gen/perl/ktouch-gen.pl
new file mode 100755
index 00000000..901df6e0
--- /dev/null
+++ b/ktouch/extras/training-gen/perl/ktouch-gen.pl
@@ -0,0 +1,180 @@
+#!/usr/bin/perl -w --strict
+
+# default values
+$length_of_line = 60;
+$number_of_line = 30;
+
+
+# genword( accumulated, core )
+# This function will generate a random sequens of character
+# containing only characters from accum or core and all words
+# generated will contain at lest on character from core
+sub genword
+{
+ (my $accum, my $core) = @_;
+
+ my $all=$accum.$core;
+ my $res="";
+
+ for(my $i=0;$i<=rand(5);$i++)
+ {
+ my $ran_pos=int(rand(length($all)));
+ $res=$res.substr($all,$ran_pos,1);
+ }
+
+ # check if we have generated a walid word, containig some characters from $core
+ if ($res =~ m/[$core]/)
+ {
+ return $res;
+ }
+ else
+ {
+ return genword($accum,$core);
+ }
+}
+
+# This function will return a list of words containing only characters from
+# accum or core. And all words will contain at lest on echaracter from core.
+# If we can't find enough words, we will use genword to generate enough words
+# to fill the list.
+sub genlist
+{
+ ($accum, $core) = @_;
+ my @res;
+
+ my $all=$accum.$core;
+
+
+ #print "$core\n";
+
+ foreach(@word_list)
+ {
+ chomp($_);
+ if (m/[$core]/ && m/^[($all)][$all]*$/)
+ {
+ push @res,$_;
+ }
+ }
+
+ for(my $i=@res;$i<30;$i++)
+ {
+ push @res,genword($accum,$core);
+ }
+
+ return @res;
+}
+
+
+# Genlevel will generate a level
+sub genlevel
+{
+ ($accum, $core) = @_;
+ my $res = "";
+ my @list = genlist($accum,$core);
+ my $max_lines = $number_of_line;
+ my $max_length = $length_of_line;
+ while($max_lines >0)
+ {
+ my $tmp=$list[rand(@list)-1];
+ $res = $res.$tmp; # first word on line should not have space
+ while($max_length >0)
+ {
+ my $tmp=$list[rand(@list)-1];
+ $res = $res." ".$tmp;
+ $max_length = $max_length - (length($tmp) + 1); # +1 is for counting one extra space for each word
+ }
+ $res = $res."\n";
+ $max_length = $length_of_line;
+ $max_lines = $max_lines - 1;
+ }
+ return $res;
+}
+
+sub rrr
+{
+ print ".";
+ s/\\/\\\\/g; #remove escape character...
+ s/-/\\-/g; #remove any - since this will mean range
+ s/ //g;
+ return $_;
+}
+
+sub heading
+{
+ return
+ "######################################################################\n".
+ "##\n".
+ "# KTouch training file generated ".localtime(time())."\n".
+ "#\n".
+ "# Perl Script written by Steinar Theigmann & Håvard Frøiland.\n".
+ "#\n";
+}
+
+sub usage
+{
+ return
+ "\n".
+ "usage: ktouch-gen config_file\n".
+ " Example: ./ktouch-gen english-conf < english-word-file\n".
+ "\n";
+}
+
+# --------------------- START ----------------------------
+
+if(@ARGV == 0) # exit if there is no config_file specified
+{
+ die usage;
+}
+
+open(CONFIG,$ARGV[0]) # First argument should be config file
+ or die "\ nCan't find config_file: $ARGV[0]\n\n";
+
+# Read in all elements in config file
+while (<CONFIG>)
+{
+ chomp($_);
+
+ if(s/length\-of\-line//)
+ {
+ $length_of_line = $_;
+ }
+ elsif(s/number\-of\-line//)
+ {
+ $number_of_line = $_;
+ }
+ elsif($_) # Add to config if not empty
+ {
+ push @config,$_;
+ }
+}
+
+#foreach(@config)
+#{
+# print "$_\n";
+#}
+#exit 0;
+
+# Read in all words
+while (<STDIN>)
+{
+ chomp($_);
+ if(length($_)>0)
+ {
+ push @word_list, $_;
+ }
+}
+
+print heading;
+
+$accum="";
+$count=0;
+foreach(@config)
+{
+ $count++;
+ print "# Level $count\n";
+ print "$_\n";
+ print genlevel($accum,$_);
+ $accum=$accum.$_;
+ print "\n\n";
+}
+
diff --git a/ktouch/extras/training-gen/perl/no.config b/ktouch/extras/training-gen/perl/no.config
new file mode 100644
index 00000000..2135fce3
--- /dev/null
+++ b/ktouch/extras/training-gen/perl/no.config
@@ -0,0 +1,20 @@
+length-of-line 20
+number-of-line 10
+
+jf
+kd
+ls
+øa
+nt
+iv
+me
+hr
+go
+bp
+qå
+wn
+cæ
+x
+,.
+-
+<>
diff --git a/ktouch/extras/training-gen/python/README b/ktouch/extras/training-gen/python/README
new file mode 100644
index 00000000..98115f52
--- /dev/null
+++ b/ktouch/extras/training-gen/python/README
@@ -0,0 +1,5 @@
+To get files with words:
+$ aspell dump master hash_file
+
+Usage:
+python ktouchgen.py english_word english.conf english.ktouch
diff --git a/ktouch/extras/training-gen/python/english_conf b/ktouch/extras/training-gen/python/english_conf
new file mode 100644
index 00000000..62fe9aa6
--- /dev/null
+++ b/ktouch/extras/training-gen/python/english_conf
@@ -0,0 +1,190 @@
+# Configfile for ktouchgen.py
+# For Documentation see ktouchgen.by
+
+[Main]
+level_rows = 40
+row_length = 70
+
+[Level1]
+lchars = jf
+title = mainregion jf
+rows = 10
+type = 2
+
+[Level2]
+lchars = kd
+title = mainregion kd
+rows = 10
+type = 2
+
+[Level3]
+lchars = ls
+title = mainregion ls
+rows = 10
+type = 2
+
+[Level4]
+lchars = a;
+title = mainregion a;
+rows = 10
+type = 2
+
+[Level5]
+lchars = asdfjkl;
+title = mainregion practice
+
+[Level6]
+lchars = ei
+rows = 10
+type = 2
+
+[Level7]
+title = practice ei
+lchars = ei
+
+[Level8]
+lchars = ur
+rows = 10
+type = 2
+
+[Level9]
+title = practice ru
+lchars = ru
+
+[Level10]
+lchars = gh
+rows = 10
+type = 2
+
+[Level11]
+lchars = gh
+title = practice gh
+
+[Level12]
+lchars = ty
+type = 2
+rows = 10
+
+[Level13]
+lchars = ty
+title = practice ty
+
+[Level14]
+lchars = ghty
+title = practice ghty
+
+[Level15]
+lchars = vn
+type = 2
+rows = 10
+
+[Level16]
+lchars = vn
+title = practice vn
+
+[Level17]
+lchars = mc
+type = 2
+rows = 10
+
+[Level18]
+lchars = mc
+title = practice mc
+
+[Level19]
+lchars = b
+type = 2
+rows = 10
+
+[Level20]
+lchars = by
+title = practice by
+
+[Level21]
+lchars = cvbynm
+title = practice by
+
+[Level22]
+lchars = ow
+type = 2
+rows = 10
+
+[Level23]
+lchars = ow
+title = practice ow
+
+[Level24]
+lchars = pq
+type = 2
+rows = 10
+
+[Level25]
+lchars = oq
+title = practice pq
+
+[Level26]
+lchars = ['
+type = 2
+rows = 10
+
+[Level27]
+lchars = qwop['
+title = practice qwoop['
+
+[Level28]
+lchars = xz
+type = 2
+rows = 10
+
+[Level29]
+lchars = xz
+title = practice xz
+
+[Level30]
+lchars = ,.
+type = 2
+rows = 10
+
+[Level31]
+lchars = JUYHNM
+type = 2
+rows = 10
+
+[Level32]
+lchars = JUYHNM
+title = practice JUYHNM
+
+[Level33]
+lchars = FRTGBV
+type = 2
+rows = 10
+
+[Level34]
+lchars = FRTGBV
+title = practice FRTGBV
+
+[Level35]
+lchars = EDCWSXQAZ
+type = 2
+rows = 10
+
+[Level36]
+lchars = EDCWSXQAZ
+title = practice EDCWSXQAZ
+
+[Level37]
+lchars = IKOLP;:
+type = 2
+rows = 10
+
+[Level38]
+lchars = IKOLP;:
+title = practice IKOLP;:
+
+[Level39]
+lchars = QWERTYUIOPLKJHGFDSAZXCVBNM;:
+title = Gesamtübung
+
+
+
+
diff --git a/ktouch/extras/training-gen/python/ktouchgen.py b/ktouch/extras/training-gen/python/ktouchgen.py
new file mode 100644
index 00000000..97083c01
--- /dev/null
+++ b/ktouch/extras/training-gen/python/ktouchgen.py
@@ -0,0 +1,269 @@
+#!/usr/bin/python
+##################################################################################
+#
+# ktouchgen.py Builds Levelfiles for ktouch
+# This is an enhanced reimplementation of a programm written by
+# Haavard Froeiland <havard@student.unsw.edu.au>
+#
+# This Version was written by
+# Hendrik Naumann <hn75@gmx.de>
+# License: GPL
+# Last edited: 11.10.2001
+##################################################################################
+#
+# SYNTAX OF THE CONFIGFILE
+#
+# Sections:
+# [Main]
+# level_rows = Generated rows per level
+# row_length = Length of the generated rows
+#
+# [Level<Num>] Settings for the Levels to create
+# lchars = Chars that must be in the words
+# in the following levels these chars will be
+# permitted to be in the words
+# title = Title of the Level. If not given it is set to
+# lchars
+# rows = Number of rows. This overwrites level_rows.
+# type = 0 Wordlist will be used for Level. If type is
+# not given this is default.
+# type > 0 Words will be created from lchars and permitted
+# chars. The number of type indicates the length
+# of the genrated words.
+#
+##################################################################################
+
+from whrandom import randint, random
+import string
+from string import join, maketrans, translate, count, strip, lower, find, upper
+import time
+import sys
+import ConfigParser
+import regex
+
+DOCSTRING = """
+Usage:
+ ./ktouchgen.py wordfile configfile outputfile
+ wordfile Is an file containing the words the levels are build from.
+ It should contain one word on each line
+ configfile File that contains the configuration of the levels.
+ See ktouchgen.py for documentation.
+ outputfile The name of the new levelfile. If it exists it will
+ be overwritten.
+"""
+
+class LevelList:
+ "Level List Class"
+ def __init__(self, Levelchars, Permitchars):
+ self.list = {0:[join(Levelchars,"")]}
+ self.wordcount = 0.0
+ self.llist = Levelchars
+ self.plist = Permitchars
+
+ def SelectWords(self, Wordlist):
+ """
+ SelectWords(self, Wordlist)
+ Searches for words only contain Permitchars and at least
+ one Levelchar.
+ Calculate the number of levelchars / per chars of the word
+ and fill this values in an mapping
+ {lchars/chars*1000 :[list of words with this property]}
+ """
+ Transstring = maketrans("","")
+ pliststring = join(self.plist, "")
+ lliststring = join(self.llist, "")
+
+ for Word in Wordlist:
+ lchar_count = 0
+ if len(translate(Word, Transstring, pliststring)) == 0:
+ lchar_count = len(Word) - len(translate(Word, Transstring, lliststring))
+ if lchar_count:
+ weight = int((float(lchar_count) / float(len(Word))) * 1000)
+ if self.list.has_key(weight):
+ self.list[weight].append(Word)
+ else:
+ self.list[weight] = [Word]
+ self.wordcount = self.wordcount + 1
+
+ def GetRandomList(self, listlength):
+ """
+ GetRandomList(self, listlength)
+ Returns a list of randomwords with listlength length.
+ First choose words with most Levelchars, if these are
+ not enough, words with less are chosen.
+ """
+ retlist = []
+ selectlist = []
+ length = 0
+ val = 0
+ temp = 0
+ keys = self.list.keys()
+ keys.sort()
+ keys.reverse()
+ for key in keys:
+ if length < listlength:
+ for count in range(len(self.list[key]) - 1):
+ if length < listlength and key > 0 :
+ num = randint (0, len(self.list[key]) - 1)
+ word = self.list[key][num]
+ temp = temp + key
+ del(self.list[key][num])
+ val = val + 1
+ length = length + len(word)
+ selectlist.append(word)
+ else:
+ break
+ else:
+ break
+ temp = float(temp) / val / 10
+ print 'Got words with an averages of %(temp).2f %% lchars.' %vars()
+ # Select the returnlist from selectlist
+ val = val - 1
+ length = 0
+ while length < listlength:
+ word = selectlist[randint(0, val)]
+ length = length + len(word)
+ retlist.append(word)
+
+ return retlist
+
+ def GenArtWord(self, Wordlength):
+ """
+ GenArtWord(self, Wordlength)
+ Builds an artifical word (with length Wordlength) out of Levelchars and Permitchars.
+ Does it like: random(lchar) + random(pchar) + .....
+ """
+ ret = ""
+ while len(ret) < Wordlength:
+ ret = ret + self.llist[randint(0, len(self.llist) - 1)] + self.plist[randint(0, len(self.plist) - 1)]
+ return ret
+
+ def GetArtList(self, Listlength, Wordlength):
+ """
+ GetArtList(self, Listlength, Wordlength)
+ Buids an Wordlist with length Listlength out of artificial words.
+ See: self.GenArtWord()
+ """
+ length = 0
+ ret = []
+ while length < Listlength:
+ word = self.GenArtWord(Wordlength)
+ ret.append(word)
+ length = length + len(word)
+ return ret
+
+
+def main(argv):
+ Wordlist = []
+ UpcaseWordlist = []
+ # Reading the Wordlist
+ try:
+ wordfile = open(argv[1], 'r')
+ except IOError:
+ print "\nWordfile couldn't be opened.\n", DOCSTRING
+ return 1
+ # Create two Wordlists, one with first char lowered
+ # (more words for the first levels) and one like it ist read
+ for wordstring in wordfile.readlines():
+ wordstring = strip(wordstring)
+ if lower(wordstring) != wordstring:
+ UpcaseWordlist.append(wordstring)
+ Wordlist.append(lower(wordstring))
+ wordfile.close()
+
+ # Parse the configfile
+ # Creates a List Levelops with [(Options), ]
+ # Optiontuple contains (lchars, title, rows)
+ conf = ConfigParser.ConfigParser()
+ try:
+ file = open(argv[2],'r')
+ except IOError:
+ print '\nConfigfile could not be opened.\n', DOCSTRING
+ return 1
+ file.close()
+ conf.read(argv[2])
+ try:
+ Rowlength = conf.getint('Main', 'row_length')
+ except ConfigParser.MissingSectionHeaderError:
+ print '\nWrong configfile. See ktouchgen.py for Documentation.' + DOCSTRING
+ Levelrows = conf.getint('Main', 'level_rows')
+ Levelops = []
+ Levelnum = 1
+ section = 'Level' + str(Levelnum)
+ while conf.has_section(section):
+ lchars = []
+ try:
+ for char in strip(conf.get(section, 'lchars')):
+ lchars.append(char)
+ except ConfigParser.NoOptionError:
+ print '\nNo characters defined for level %(Levelnum)s !' %vars()
+ return 1
+ try:
+ title = conf.get(section, 'title')
+ except ConfigParser.NoOptionError:
+ title = join(lchars)
+ try:
+ rows = conf.getint(section, 'rows')
+ except ConfigParser.NoOptionError:
+ rows = Levelrows
+ try:
+ type = conf.getint(section, 'type')
+ except ConfigParser.NoOptionError:
+ type = 0
+
+ Levelops.append((lchars, title, rows, type))
+ Levelnum = Levelnum + 1
+ section = 'Level' + str(Levelnum)
+ print '\nConfiguration for %(Levelnum)s levels read. \n!!! Be aware, if the Levels are not numberd correctly \n!!! they will not be read completely!' %vars()
+
+ # Generate Output
+ try:
+ outfile = open(argv[3], 'w')
+ except IOError:
+ print "Outputfile could not be opened.\n", DOCSTRING
+ return 1
+ outfile.write('#########################################################\n' +\
+ '# Trainingfile generaded ' + time.ctime(time.time()) + '\n' +\
+ '# Program written by Hendrik Naumann <hn75@gmx.de>\n' +\
+ '# Inspired by Håvard Frøiland\'s version\n' +\
+ '#########################################################\n')
+ permit_chars = []
+ Levelnum = 0
+ for Option in Levelops:
+ cachestring = ""
+ Levelnum = Levelnum + 1
+ for new_char in Option[0]:
+ if new_char not in join(permit_chars,""):
+ permit_chars.extend(Option[0])
+ outfile.write('\n# Level %(Levelnum)s\n' %vars() + Option[1] + "\n")
+
+ print "Generating Level " + str(Levelnum)
+ print join(permit_chars,"")
+
+ # Generate a LevelList object and give the needed Wordlists
+ levelwordlist = LevelList (Option[0], permit_chars)
+ if Option[3] == 0:
+ if lower(join(permit_chars,"")) != join(permit_chars,""):
+ if upper(join(Option[0],"")) != join(Option[0],""):
+ levelwordlist.SelectWords(Wordlist)
+ levelwordlist.SelectWords(UpcaseWordlist)
+ else:
+ levelwordlist.SelectWords(Wordlist)
+ randomlist = levelwordlist.GetRandomList(Rowlength * Option[2])
+ else:
+ randomlist = levelwordlist.GetArtList(Rowlength * Option[2], Option[3])
+
+ # Write the randomlist
+ for word in randomlist:
+ cachestring = cachestring + " " + word
+ if len(cachestring) > Rowlength - 3:
+ outfile.write(strip(cachestring) + "\n")
+ cachestring = ""
+ outfile.close()
+ return 0
+
+if __name__ == "__main__":
+ if len(sys.argv) == 4:
+ main(sys.argv)
+ else:
+ print '\nWrong number of parameters\n' + DOCSTRING