This shows you the differences between two versions of the page.
— |
py_chi [2012/03/09 10:43] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== PyChi - The art of learning Python and Chinese at the same time. ====== | ||
+ | |||
+ | PyChi - It sounds almost like then name of a martial art-form and well, you could call it that, as the purpose of PyChi is to stimulate one of the most dangerous weapons know to man... the brain, in this case my brain, feeling like a rather blunt thing at the inception of this the newest of my many grand schemes. | ||
+ | |||
+ | You see, being married to a fantastic chinese woman, I had always been a bit saddned by going to visit the in laws and the rest of the family in China as my limited vocabulary was good for ordering tea, gum bao jiling and asking for the bill, adding wo shao bu hao jungua hua. | ||
+ | |||
+ | Knowing my humble abilities I figured it was time to something about two things I'd been procrastinating over for quite some time. | ||
+ | |||
+ | Over the course of some months I intended to become relatively proficient in two different languages, and during this process I would attempt to create applications that would help me understand Python as well as learning Chinese. | ||
+ | |||
+ | But wait there was more, for while I would be doing the aforementioned, | ||
+ | |||
+ | (Yes I know my sentences are insanely long at times). | ||
+ | |||
+ | It was a tall order I admit it but being keen on grand plans I decided to embark on an adventure that would take me straight into the fray. | ||
+ | |||
+ | <fs 0.6em>If you my dear reader still haven' | ||
+ | </fs> | ||
+ | |||
+ | |||
+ | Beginnings. | ||
+ | |||
+ | I'm quite a visual person and during my period of considering to learn Python I had stumbled across a series of videos on youtube by a user going by the handle thenewboston. | ||
+ | |||
+ | In the tutorials he calls himself bucky roberts, the video' | ||
+ | |||
+ | I figured that I'd begin by methodically sitting through all the tutorial sessions he had created in order to assimilate what I could visually about programming in Pyhton before I began my development project. | ||
+ | |||
+ | I had noticed that in the tutorials a really neat and simple IDE was used for Python programming and from browsing the 5 minute tutorial at python.org I was reminded that it was called IDLE, as I had by chance strayed across a video on the python.org site. | ||
+ | |||
+ | Trying to see if it was installed on my system I found that I needed to apt-get it as it was not installed. | ||
+ | |||
+ | But before I did that I figured that I'd find out which version of Python was installed on the machine, as I had noticed while browsing Synaptic Package Manager for anything Python related that my machine had in fact already some Python stuff installed and the 5 minute introduction boasted that it should be installed by default. | ||
+ | |||
+ | The machine was an Ubuntu 10.04 and scouring the web I quickly found the command for checking which version of Python you have installed on your Linux box. | ||
+ | |||
+ | python -V | ||
+ | |||
+ | I'm guessing it will be the same on other operating systems, but I couldn' | ||
+ | |||
+ | Anyway seeing that the version was Python 2.6.5 and discovering that IDLE wasn't installed already, I decided to install IDLE for the particular version, I did this using Synaptic the built in package manager, the easiest way to find and install programs for any operating system. | ||
+ | |||
+ | Anyway decided it was time to pour over the videos one by one until I reached the end. | ||
+ | |||
+ | I began on 24/06 - 2010 and ended on 04/07 - 2010. | ||
+ | |||
+ | ************* EDIT THIS TO EXPLAIN ABOUT TUTORIALS ************************* | ||
+ | Completed watching up to: 43 of 43 of the tutorials named Python Programming Tutorial by Youtube user thenewboston by bucky roberts | ||
+ | |||
+ | Completed watching up to: 14 of 14 of the tutorials named wxPython Programming Tutorial by Youtube user thenewboston by bucky roberts | ||
+ | |||
+ | Completed watching up to: 17 of 17 of the tutorials named Game Development Tutorial by Youtube user thenewboston by bucky roberts | ||
+ | ************* EDIT THIS TO EXPLAIN ABOUT TUTORIALS ************************* | ||
+ | |||
+ | So what did I learn from the above lessons, well that Pyhton is quite a flexible language, it combines the best of multiple programming paradigms. | ||
+ | |||
+ | You can work object oriented, but at the same time you have the functional programming aspect available, there is much less typing required than Java, which I love, one should always let the computer work for you and not only by suggesting what has to be typed by predictive typing, but by actually eliminating the need to type. | ||
+ | |||
+ | I mean compare these two. | ||
+ | |||
+ | To print something in java in the console I would have to write the following statement. | ||
+ | |||
+ | < | ||
+ | |||
+ | class HelloWorld | ||
+ | { | ||
+ | public static void main(String args[]) | ||
+ | { | ||
+ | | ||
+ | } | ||
+ | } | ||
+ | |||
+ | </ | ||
+ | |||
+ | Did you notice all the brackets and syntax needed for such a simple operation ? | ||
+ | |||
+ | In IDLE (The Python IDE) to get the same effect I would simply type: | ||
+ | |||
+ | < | ||
+ | |||
+ | print "Hello World!" | ||
+ | |||
+ | </ | ||
+ | |||
+ | And the IDE would promptly reward me with: | ||
+ | |||
+ | Hello World! | ||
+ | |||
+ | Somthing of a difference eh ? | ||
+ | |||
+ | Python also is able to figure out on its own if I am creating a string or an int. | ||
+ | |||
+ | Creating arrays/ | ||
+ | |||
+ | In Python I can create a list like this: | ||
+ | |||
+ | Question = ['What is a : ', | ||
+ | |||
+ | Here in one simple list I have both the question, the possibilities and the correct answer. | ||
+ | |||
+ | To retrieve the information a simple syntax like this can be used: | ||
+ | |||
+ | print Question[0]; | ||
+ | |||
+ | That would result in something like this: | ||
+ | |||
+ | What is a : | ||
+ | cat | ||
+ | Is it an animal type 1. | ||
+ | Is it a plant, type 2. | ||
+ | Is it a machine, type 3 | ||
+ | |||
+ | After this you could add a raw_input for the user to interact with the program and then perform checks to see if the value the user typed was correct etc. | ||
+ | |||
+ | You can check out the flashcard quiz program I'll decribe later in this text to see an implementation of a quiz using randomly selected questions chosen from a pool. | ||
+ | |||
+ | But to get back on track. | ||
+ | |||
+ | After going through the tutorials I felt confident that I was ready to embark on the next part of this adventure i.e. putting the both my ideas into code, as well as utilize the same code to help me practice my chinese. | ||
+ | |||
+ | I definitely had learned a lot from those online presentations. The big question was just, would developing a program in Python be as fast as in JAVA and how much of my thinking could I re-use but before I could begin contemplating using the foundation already laid for the flash cards JAVA version of our old PDS/Xbasic program. | ||
+ | |||
+ | But first I needed doing a little additional groundwork to implement phase two of my PyChi regimen. | ||
+ | |||
+ | The groundwork consisted of translating 900+ words already present in the standard dictionary of our old program. | ||
+ | |||
+ | I decided not to hire someone to do the translation and also to avoid cut and paste as much as possible. | ||
+ | |||
+ | Instead I would manually write the words I wanted translated as I wanted to try to trigger my brain using bodily functions in order to sharpen my abilities to form memories, thus making the translation process a little more challenging. | ||
+ | |||
+ | Yes I fully know cut and paste, or hiring a professional would have speeded up the process a whole lot, but this was not the purpose again, now was it ? | ||
+ | |||
+ | |||
+ | The translation process. | ||
+ | |||
+ | Being that I had to translate nearly 900 words I figured that I could do about 100 each day. This would be tested over a period of XXX days. | ||
+ | |||
+ | 100 words per day is quite a lot, so I knew that in order to speed up some of the process in particular regarding creating the dictionary file itself, I figured I might as well work a little smart and create an application that could assist me in building a dictionary file that was correctly formatted to be used for the flashcard trainer as well as other upcoming programs in the development pipeline of The Global Ability Initiative. | ||
+ | |||
+ | I decided to aim at what I refer to as v.2 of the dictionary file format, you can see an example of the style below. | ||
+ | |||
+ | < | ||
+ | |||
+ | Styling each line like this in an XML like syntax, was the suggestion of someone I only know as Davidos who had actually begun working on an android application on behalf of the Global Ability initiative, but had unfortunately been forced to quit in the midst of his efforts, due to the fact that he got a job and was no longer able to do freelance work. | ||
+ | |||
+ | So to assist me in the translation process I decided to create a tiny command line application that would take as parameters, the word or sentences I was typing, along with an image name. | ||
+ | |||
+ | What images you might wonder. Well we have a library of approx 900 images ready and named for each word/ | ||
+ | |||
+ | The images can be found at: [http:// | ||
+ | |||
+ | However after some experimentation trying to avoid writing the line quitapplication to break the loop, I decided to never mind fiddling about as I kept ending in infinite loops and simply get on with the task. (became quitapp though) | ||
+ | |||
+ | The program did what it was supposed to do anyway, and the need for any further fancy stuff could wait (so much for learning Python, it was time for learning some chinese), but before I skip to the learning chinese part, here's what the translation helper program ended up looking like after being massaged on the way: | ||
+ | |||
+ | < | ||
+ | |||
+ | print ' | ||
+ | |||
+ | print ' | ||
+ | |||
+ | s='' | ||
+ | img='' | ||
+ | originalwordsentence='' | ||
+ | |||
+ | fob=open(' | ||
+ | |||
+ | while 1: | ||
+ | if s==' | ||
+ | s = raw_input(' | ||
+ | img = raw_input(' | ||
+ | originalwordsentence = raw_input(' | ||
+ | fob.write('< | ||
+ | fob.close() | ||
+ | |||
+ | print ' | ||
+ | |||
+ | </ | ||
+ | |||
+ | Let me try to break down what the application does. | ||
+ | |||
+ | The first line is a simple print statement so that the CLI gives an indication of that the program has started. | ||
+ | |||
+ | The following two lines initiate the three strings that you will notice are used later to build our entry sentence. | ||
+ | |||
+ | The line after this creates a so called file object fob opening a file called textfile001.txt, | ||
+ | |||
+ | After this a while loop is initiated. | ||
+ | |||
+ | The line after this creates a condition to break out from the loop | ||
+ | |||
+ | The following two lines set the conditions for user input to be obtained from the command line. | ||
+ | |||
+ | Then next line writes what the user has typed to the text file we have opened weaving a text string from regular text and the raw input we have obtained in the previous two lines. | ||
+ | |||
+ | Once the break condition is met the program performs the next line of the code and closes the file object. | ||
+ | |||
+ | The last line prints a message in the CLI that the program has terminated. | ||
+ | |||
+ | The drawback with this program is that it will append a line with the word quitapp in the last line, one could create a parser that would parse the lines of the program and remove said line. | ||
+ | |||
+ | However I decided that I'd first try out a little translation, | ||
+ | |||
+ | For the translation work itself I searched for a site that displayed pinyin as this was important for me since I needed to understand Chinese and am at the time of writing unable to read Chinese characters. | ||
+ | |||
+ | I used the following site/s for the practice translation process: | ||
+ | |||
+ | http:// | ||
+ | |||
+ | http:// | ||
+ | |||
+ | The sites is really nice in that that it has both pinyin and traditional characters and spoken word as well in audio. | ||
+ | |||
+ | I like the former over googles as I do not need to ask for pinyin every time and I'm too lazy to begin fiddling with settings on google to personalize it. | ||
+ | |||
+ | But it was nice to have multiple sites as a cross reference and I can definately recommend using it as a potential source for learning Chinese, that and naturally the application that I have ended up creating in Python. | ||
+ | |||
+ | Begin translation phase on: 05/07 - 2010 | ||
+ | End translation phase on: __/__- 2010 | ||
+ | |||
+ | But back to the experience, my goal of 100 words per day was too high, my other goal to minimize cut and paste was also lofty at best, as cutting just those characters in pinyin that I had no clue how to replicate using my keyboard was more confusing that just cutting the entire word and trying to learn it in the process. | ||
+ | |||
+ | After translating just the first 20 words or so I realized what a momentous task it would be for me to finish but hoped I'd be able to do some sprints in the weekend and the upcoming holiday I had ahead. | ||
+ | |||
+ | [[chinese ukwords|Translation from English to Chinese]] | ||
+ | |||
+ | In a valiant attempt I figured I'd be using a windows machine as well, however as usual UTF-8 and Windows are not good friends and it seems Python for windows was default in ascii mode so I ditched the idea of using it directly on windows. Instead I opted to run a Virtual machine on the Windows system that way I could proceed without bothering about the differences and knowing that unicode issues should be fixed in Python 3 I figured it would be a waste of time at this point to bother fiddling with converting back and forth on the Windows system. | ||
+ | |||
+ | My holiday was spent caring for a tremendous toothache and not much work was done, went home again and yeah I admit it, I did not live up to my own plan, work, holidays more work and holidays, what can I say, a minor detour has also led to the creation of the beginnings of a mobile interface i.e an application capable of running on a touchsensitive | ||
+ | |||
+ | Before going on let me give a summary of the application. | ||
+ | |||
+ | The concept is simple the application displays a number of clickable icons based on the dictionary files available for the project, when clicked these icons produce a sound, voila instant communication on your mobile, and not just for disabled, you could take the application anywhere in the world and use it to communicate. | ||
+ | |||
+ | The main page of the prototype looks like this (a number of prototypes have gone before it but I'll just list one here so you get the idea, this one does 90% of what I had hoped the prototype could, it just needs to be rendered better sizewise and sound needs to be available on the mobile, it currently works in a browser on a regular computer under Linux (FireFox 3.6.12 / Ubuntu 10.04 "Lucid Lynx". | ||
+ | |||
+ | I shall gradually update the code so that it becomes more and more functional, I will not list any subpages unless they introduce some functionality that is not included in the main page. | ||
+ | |||
+ | < | ||
+ | |||
+ | < | ||
+ | div.floating-menu {position: | ||
+ | div.floating-menu2 {position: | ||
+ | |||
+ | </ | ||
+ | |||
+ | |||
+ | <div class=" | ||
+ | < | ||
+ | <img style=" | ||
+ | <a href=" | ||
+ | <a href=" | ||
+ | <a href=" | ||
+ | <a href=" | ||
+ | <a href=" | ||
+ | <a href=" | ||
+ | <a href=" | ||
+ | <a href=" | ||
+ | <img style=" | ||
+ | |||
+ | </ | ||
+ | </ | ||
+ | | ||
+ | <!-- Enabling playback of embedded sounds --> | ||
+ | | ||
+ | < | ||
+ | function GetSound(soundobj) { | ||
+ | var thissound= eval(" | ||
+ | thissound.Play(); | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | | ||
+ | |||
+ | | ||
+ | <table style=" | ||
+ | |||
+ | |||
+ | < | ||
+ | |||
+ | <tr> | ||
+ | |||
+ | <td style=" | ||
+ | |||
+ | | ||
+ | <td style=" | ||
+ | < | ||
+ | </ | ||
+ | <a href src> < | ||
+ | |||
+ | |||
+ | <td style=" | ||
+ | |||
+ | <td style=" | ||
+ | |||
+ | <td style=" | ||
+ | |||
+ | <td style=" | ||
+ | <td style=" | ||
+ | <td style=" | ||
+ | <td style=" | ||
+ | <td style=" | ||
+ | <td style=" | ||
+ | <td style=" | ||
+ | <td style=" | ||
+ | <td style=" | ||
+ | <td style=" | ||
+ | <td style=" | ||
+ | <td style=" | ||
+ | <td style=" | ||
+ | <td style=" | ||
+ | <td style=" | ||
+ | </tr> | ||
+ | <tr> | ||
+ | <td style=" | ||
+ | <td style=" | ||
+ | <td style=" | ||
+ | <td style=" | ||
+ | <td style=" | ||
+ | <td style=" | ||
+ | <td style=" | ||
+ | <td style=" | ||
+ | <td style=" | ||
+ | <td style=" | ||
+ | <td style=" | ||
+ | <td style=" | ||
+ | <td style=" | ||
+ | <td style=" | ||
+ | <td style=" | ||
+ | <td style=" | ||
+ | <td style=" | ||
+ | <td style=" | ||
+ | <td style=" | ||
+ | <td style=" | ||
+ | </tr> | ||
+ | <tr> | ||
+ | <td style=" | ||
+ | <td style=" | ||
+ | <td style=" | ||
+ | <td style=" | ||
+ | <td style=" | ||
+ | <td style=" | ||
+ | <td style=" | ||
+ | <td style=" | ||
+ | <td style=" | ||
+ | <td style=" | ||
+ | <td style=" | ||
+ | <td style=" | ||
+ | <td style=" | ||
+ | <td style=" | ||
+ | <td style=" | ||
+ | <td style=" | ||
+ | <td style=" | ||
+ | <td style=" | ||
+ | <td style=" | ||
+ | <td style=" | ||
+ | </tr> | ||
+ | <tr> | ||
+ | <td style=" | ||
+ | <td style=" | ||
+ | <td style=" | ||
+ | <td style=" | ||
+ | <td style=" | ||
+ | <td style=" | ||
+ | <td style=" | ||
+ | <td style=" | ||
+ | <td style=" | ||
+ | <td style=" | ||
+ | <td style=" | ||
+ | <td style=" | ||
+ | <td style=" | ||
+ | <td style=" | ||
+ | <td style=" | ||
+ | <td style=" | ||
+ | <td style=" | ||
+ | <td style=" | ||
+ | <td style=" | ||
+ | <td style=" | ||
+ | </tr> | ||
+ | |||
+ | </ | ||
+ | </ | ||
+ | |||
+ | <div class=" | ||
+ | < | ||
+ | <a href=" | ||
+ | <a href=" | ||
+ | <a href=" | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | |||
+ | </ | ||
+ | |||
+ | The play_soundname.wav.html construction with regards to the images will be replaced by a javascript structure some of which you already see implemented above whcih is looking like this: | ||
+ | |||
+ | < | ||
+ | |||
+ | < | ||
+ | function GetSound(soundobj) { | ||
+ | var thissound= eval(" | ||
+ | thissound.Play(); | ||
+ | } | ||
+ | </ | ||
+ | <!-- Generate table from below example --> | ||
+ | <embed src=" | ||
+ | enablejavascript=" | ||
+ | | ||
+ | <embed src=" | ||
+ | enablejavascript=" | ||
+ | | ||
+ | <!-- Basically do the above for every image when generating the HTML- | ||
+ | create variable based on soundname --> | ||
+ | |||
+ | <!-- Here is an examples for a link with the same properties as an image i.e. will play a sound when hovered over. | ||
+ | |||
+ | <a href="#" | ||
+ | |||
+ | Next one uncommented is the same just using an image --> | ||
+ | |||
+ | <PRE> | ||
+ | <UL> | ||
+ | <img src=" | ||
+ | </ | ||
+ | </UL> | ||
+ | |||
+ | |||
+ | |||
+ | <embed src=" | ||
+ | enablejavascript=" | ||
+ | |||
+ | <PRE> | ||
+ | <UL> | ||
+ | <img src=" | ||
+ | </ | ||
+ | </UL> | ||
+ | |||
+ | |||
+ | </ | ||
+ | |||
+ | I just need to generate said code with the [[parse3.py]] program listed above after which this section will be removed and the code above replaced with the final code. | ||
+ | |||
+ | |||
+ | For now I'll leave this code to speak for itself as this is not a study into HTML, but I figured that since the development is derived from my quest for mastery of PyChi I need to include it here, I shall if I get time look into giving a walkthrough once finish the PyChi part of the project. | ||
+ | |||
+ | Actually there is more to the above story, I was not supposed to do that part myself, my grand plan was to outsource the work, I had heard of a couple of places Freelancer.com and Vworker.com, | ||
+ | |||
+ | But the road to me doing it myself was troublesome to say the least, on one page I got a bid from a guy and he developed something like 40% of a finished application before he unfortunately had to drop the project as he got a job, the second guy I got hold of was a complete disaster, apparently he did not bother to read the page above, secondly he kept asking questions that were right before him if he had bothered to read the requirements and in the end he became fresh with me after which I pointed out that we were in an employer employee relationship and pointed out that he had gone far over the agreed deadline and that he should never ever refer to me as dude again. He became so upset that he told me to go bully someone else, I set up arbitration on the page and won. | ||
+ | |||
+ | What I have learned from this is that while it is a possibility to outsource your work you will need to do a great amount of planning before, divide your project into itty bitty parts, I can recommend reading about object oriented analysis and design, a lot of the stuff described in the following two books is pure gold first I'd like to recommend: | ||
+ | |||
+ | < | ||
+ | |||
+ | </ | ||
+ | |||
+ | Do put it in the shopping basket immediately and I'll earn a small fee taken out of Amazon' | ||
+ | |||
+ | The second recommendation for you today is: | ||
+ | < | ||
+ | <a href=" | ||
+ | </ | ||
+ | |||
+ | While it I believe is written before the UML 2.0 specifications came out I still believe it is a worthwile investment. | ||
+ | |||
+ | Okay now it is time for you to ask why am I promoting these two books ? | ||
+ | |||
+ | Sure the money would be nice, I will get a 1 digit % fee of the sales price if you buy it and don't navigate around before you click buy this item, but it so happens I have actually also read both the predecessor to Simon Bennet et ' | ||
+ | |||
+ | With regards to the weekend crash course, I noticed a fellow student having. I got my hands on it and after reading it I'd say that they two complement each other brilliantly, | ||
+ | |||
+ | So if you want to invest in good knowledge I'd say they are a good buy. | ||
+ | |||
+ | There sales promo done now back to PyChi... | ||
+ | |||
+ | In creating the application whether HTML based or Python based I needed to be able to browse the newly created XML' | ||
+ | |||
+ | But before being able to offer this wonderful backwards compatibility and additional dictionaries as well as the above HTML application I needed to be able to parse the contents of files from disc in furter detail than just reading one line at the time and creating another line, I needed to be able to extract words from within my tags and if I could do this I would subsequently also be able to search for other specifics in a file and create dictionaries from other sources than through the manual translation process already explained earlier in this text. | ||
+ | |||
+ | The parsing program explained: | ||
+ | |||
+ | This program basically reads a dictionary file and in the process parses each line for certain words that it subsequently uses to building a HTML syntax, the code could be done with more beauty, it is crude and ugly to say the least but it does what it is supposed to. Feel free to improve to make more clean and get back to me with the result, if I find it appealing and you are willing to hand it over FOC and with no strings attached I'll be happy to share with others here. | ||
+ | |||
+ | Oh and just a little backpeddling, | ||
+ | |||
+ | < | ||
+ | |||
+ | anyfilename = ' | ||
+ | f = open(anyfilename,' | ||
+ | output = [] | ||
+ | newoutput=[] | ||
+ | htmloutput=[] | ||
+ | for line in f: | ||
+ | if '' | ||
+ | output.append(line) | ||
+ | f.close() | ||
+ | |||
+ | |||
+ | ''' | ||
+ | count = 0 | ||
+ | number_of_lines = 0 | ||
+ | linenumber = 0 | ||
+ | |||
+ | for i in output: | ||
+ | |||
+ | count = count+1 | ||
+ | |||
+ | |||
+ | ''' | ||
+ | |||
+ | number_of_lines = count | ||
+ | |||
+ | for i in range(0, number_of_lines): | ||
+ | | ||
+ | ''' | ||
+ | ''' | ||
+ | | ||
+ | else: | ||
+ | print ' | ||
+ | print " " | ||
+ | print " " | ||
+ | ''' | ||
+ | print " | ||
+ | for i in range(0, number_of_lines): | ||
+ | search = '</ | ||
+ | output[i].find(search) | ||
+ | index = output[i].find(search) | ||
+ | | ||
+ | ''' | ||
+ | ''' | ||
+ | cut_text_from_string=output[i][13: | ||
+ | print ' \n' | ||
+ | print cut_text_from_string | ||
+ | if '' | ||
+ | newoutput.append(cut_text_from_string) | ||
+ | print 'We have now removed all heading text and trailing text after the ":" | ||
+ | print " | ||
+ | |||
+ | ''' | ||
+ | actual_imagefilename - Is the primary variable to find as most of the latter variables will depend upon it, this we | ||
+ | read from within the tags < | ||
+ | on | ||
+ | ''' | ||
+ | for i in range(0, number_of_lines): | ||
+ | search = '< | ||
+ | newoutput[i].find(search) | ||
+ | index = newoutput[i].find(search) | ||
+ | print search, "found at index", | ||
+ | indexvalue1=int(index) | ||
+ | print indexvalue1 | ||
+ | actual_soundfilename = newoutput[i][indexvalue1+11: | ||
+ | print actual_soundfilename | ||
+ | |||
+ | ''' | ||
+ | |||
+ | soundplayback = '< | ||
+ | print "This is the soundplayback / embed sentencegeneration" | ||
+ | |||
+ | ''' | ||
+ | the_HTML_playbackname_for_an_image = actual_soundfilename + ' | ||
+ | print the_HTML_playbackname_for_an_image | ||
+ | |||
+ | search2 = '</ | ||
+ | newoutput[i].find(search2) | ||
+ | index = newoutput[i].find(search2) | ||
+ | print search2, "found at index", | ||
+ | indexvalue2=int(index) | ||
+ | print indexvalue2 | ||
+ | an_alternate_title_for_the_image_for_HTML_purposes = newoutput[i][: | ||
+ | print an_alternate_title_for_the_image_for_HTML_purposes | ||
+ | the_title_of_the_image = an_alternate_title_for_the_image_for_HTML_purposes | ||
+ | print the_title_of_the_image + 'Is the text displayed on a mouseover' | ||
+ | | ||
+ | search3 = '</ | ||
+ | newoutput[i].find(search3) | ||
+ | index = newoutput[i].find(search3) | ||
+ | print search3, "found at index", | ||
+ | indexvalue3=int(index) | ||
+ | print indexvalue3 | ||
+ | actual_imagefilename = newoutput[i][indexvalue3-8: | ||
+ | print actual_imagefilename | ||
+ | |||
+ | an_alternate_title_for_the_image_for_HTML_purposes = 'This is the image for ' + an_alternate_title_for_the_image_for_HTML_purposes + ' ' + actual_imagefilename | ||
+ | |||
+ | print an_alternate_title_for_the_image_for_HTML_purposes | ||
+ | |||
+ | ''' | ||
+ | | ||
+ | generatedHTMLstring = soundplayback + ' <PRE> <UL> <td style=" | ||
+ | |||
+ | print generatedHTMLstring | ||
+ | |||
+ | htmloutput.append(generatedHTMLstring+' | ||
+ | |||
+ | anyfilename2 = ' | ||
+ | fob2 = open(anyfilename2,' | ||
+ | fob2.writelines(htmloutput) | ||
+ | fob2.close() | ||
+ | |||
+ | |||
+ | |||
+ | print "Hallo der" | ||
+ | ''' | ||
+ | ''' | ||
+ | ''' | ||
+ | |||
+ | </ | ||
+ | |||
+ | You will notice a lot of print statements, these are completely unnecessary however printing variables as you go along can help you keep an overview of what is happening, comment all of the print sentences out for speed optimization. And like I said feel free to improve and share as long as you do not hinder others to do the same. | ||
+ | |||
+ | A modification of this program will also enable the swift creation of XML' | ||
+ | |||
+ | The code below is to be used to popuate a list of filenames that will be associated with the danish dictionary where the lines are built like this: | ||
+ | |||
+ | Sometext someimagename.spr | ||
+ | |||
+ | or like this: | ||
+ | |||
+ | Sometext someimagename.pcx | ||
+ | |||
+ | or like this: | ||
+ | |||
+ | Sometext someimagename.pcx sonesoundfilename.wav | ||
+ | |||
+ | < | ||
+ | os.listdir ('/ | ||
+ | </ | ||
+ | |||
+ | |||
+ | |||
+ | WARNING PREDICTIVE WRITING!!!!!! | ||
+ | |||
+ | Some of these things I have done | ||
+ | |||
+ | Having translated the standard dictionary I turned to my better half to proof read my translation attempt, however wanting to do this cleverly as well I had to design another application, | ||
+ | |||
+ | The application is quite simple actually, it parses through the text one entry at the time, displays the image, displays the Chinese text and finally the English text. The interface has an OK button and an empty text field for entering text. | ||
+ | |||
+ | If no text is entered and user presses OK the application goes to the next line. | ||
+ | |||
+ | If new text is entered, the application writes that new text into the string in the correct place and then goes to the next line. | ||
+ | |||
+ | The application also saves a file summarizing the corrections and on which line the corrections were made. The application also counts how many lines it has parsed through. | ||
+ | |||
+ | This enables the user to start the application and say yes to skip to where the application last quit when the application starts as it checks the summary so that the user does not have to skip through work already checked. | ||
+ | |||
+ | |||
+ | While the dictionary was being checked I could begin phase 3, the creation of an application that would allow me to use the dictionary I had just finished building to actually practice the Chinese language. I would also be able to reuse parts of what I had learned from designing the proofreader application using it as part of the trainer. | ||
+ | |||
+ | PREDICTIVE WRITING ENDS!!!!!! | ||
+ | |||
+ | |||
+ | Building the application. | ||
+ | |||
+ | As I said earlier I had already covered a lot of ground in the program design I'd done for the JAVA application so I had an idea of what was needed to get things off the ground. Furthermore I had created a little code already for the former two applications made during the translation phase so I was good to go. | ||
+ | |||
+ | I decided on a simplistic approach, an application that read it's data from a text file, in a new meta format I had " | ||
+ | |||
+ | The aforementioned XML style approach being suggested by someone I only know by the name Dantevios, whom I met on a forum and was originally supposed to assist The Global Ability Initiative to build the aforementioned Android application. | ||
+ | |||
+ | I did not choose a database driven application as I wanted to first create a text based application as I could use this to create a better foundation for a database driven application and people without too fancy computer setup' | ||
+ | |||
+ | For sound am relying on good old SoX which I have done in the Java version as well, I do this because I know that will make it work on at least Linux and on several Windows platforms as well, possibly also on others as well as OSX. | ||
+ | |||
+ | SoX ? | ||
+ | |||
+ | SoX, is what the project home page calls the Swiss Army knife of sound processing programs. It is a command line utility able to handle an insane amount of sound formats as well as manipulate them. | ||
+ | |||
+ | For me the choice was obvious as sound implementation in Java had been a pain until I came across SoX which my brother had chosen earlier as well for our early applications and it would not require any additional plug in's or libraries for Python which I was in the process of learning. | ||
+ | |||
+ | Those interested in SoX can go to http:// | ||
+ | |||
+ | Design | ||
+ | |||
+ | Classes, in my early iteration of the semi abandoned Java project I had tried to create an overview of classes that would be needed for the program to work. | ||
+ | |||
+ | LIST CLASSES HERE - Write overview | ||
+ | |||
+ | As earlier mentioned I didn't want to go all the way to a database implementation so I decided on just writing the text parsing version of the program, this would also enable me to use said text parser as a data exchange tool in case people wanted to exchange data in text form rather than using databases etc. | ||
+ | |||
+ | I will go over each class and try to explain how I'm thinking the application ought to look using the MVC " | ||
+ | |||
+ | |||
+ | |NOTE TO SELF | ||
+ | |http:// | ||