class HelloWorld
{
public static void main(String args[])
{
System.out.println("Hello World!");
}
}
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/lists in JAVA, particularly mixed lists of integers ans strings can be an ardous deal and retrieveing information from them can be a pain.
In Python I can create a list like this:
Question = ['What is a : ',2,'Cat', 'Is it an animal type 1. ','Is it a plant, type 2. ','Is it a machine, type 3']
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];print Question[2];print Question[3]; print Question[4]; print Question[5];
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.
print 'Welcome to the translation helper interface'
print 'Welcome to the translation helper interface'
s=''
img=''
originalwordsentence=''
fob=open('./textfile001.txt', 'a')
while 1:
if s=='quitapp':break
s = raw_input('Type word/sentence to be translated here: ')
img = raw_input('Type image number here: ')
originalwordsentence = raw_input('Type english text and number here: ')
fob.write(''+s+' P'+img+'.png P'+img+'.wav Original word/sentence: ' + originalwordsentence + ':\n')
fob.close()
print 'Program terminated'
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, the a is for append, other syntax is read 'r' and write 'w' which would either let your read or write the file in question.
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, then I'd consider refining the application.
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://www.instantspeakchinese.com/dictionary/compound.cfm?from=1&searchType=3&english=speak&CFID=45132803&CFTOKEN=34905409
http://translate.google.com
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 based on TADA... HTML code to make it as portable as possible.
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.
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:
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, I ran a test project on Freelancer with regards to a Checz dictionary that worked out splendidly and I figured I'd try to run fyrst a QT project for the above and then an Android project you can find a complete explanation of the application on http://globability.org/wiki/doku.php?id=mobile_pointing_tablet I might go back and do it as a Python application but for now it stays in the HTML realm which has also forced me to learn some useful stuff in Python.
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:
Object-Oriented Systems Analysis and Design
Do put it in the shopping basket immediately and I'll earn a small fee taken out of Amazon's profit on the book, you'd be helping me to continue helping and entertaining you if you do so, do not navigate away before you pressed the icon to add to shopping cart or my ID might be lost.
The second recommendation for you today is:
UML Weekend Crash Course
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 'al's book (i.e. an earlier edition) and have to admit that I absolutely loved the earlier edition which was taught in my Computer Sciences class, if you read this Flemming you are truly a superb teacher!!! However I figured I'd rather recommend a 4'th edition as techniques evolve and even better methods must have surfaced since I went to school a few years ago.
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, the weekend course by being a easy to follow introduction giving you a really good overview and the (expensive) book being the thorough detailed journey into object oriented system analysis and design.
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'ish file, I also knew that once I mastered parsing the XML'ish file I could apply the same techniques on the original dictionary files and thus have 9 complete dictionaries updated to reflect the new syntax which makes it possible to create backwards compatibility for future products and even makes it possible for anyone to utilize the newest possible dictionaries if their applications just browse for what is between tags of a specific line and thus populate their applications with data.
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, I have tried to make the code self explanatory using variable names describing what I am doing anf commenting a lot in the code itself so I hope that is enough to make it clear what is happening.
anyfilename = 'textfile001.txt'
f = open(anyfilename,'r')
output = []
newoutput=[]
htmloutput=[]
for line in f:
if '' in line:
output.append(line)
f.close()
'''determine length of list and then set number_of_lines to this value'''
count = 0
number_of_lines = 0
linenumber = 0
for i in output:
count = count+1
'''Now we have the number of lines'''
number_of_lines = count
for i in range(0, number_of_lines):
'''print "gubblegub" '''
'''print output[i] '''
else:
print 'Reading the information into output complete now we should perform string operation'
print " "
print " "
'''First assignment clean output for anything after : in each line'''
print "Innerloop beginning, finding all instances of ':'"
for i in range(0, number_of_lines):
search = ''
output[i].find(search)
index = output[i].find(search)
'''print search, "found at index", index'''
'''Now we cut the end of every sentence of output'''
cut_text_from_string=output[i][13:index]
print ' \n'
print cut_text_from_string
if '' in line:
newoutput.append(cut_text_from_string)
print 'We have now removed all heading text and trailing text after the ":" '
print "innerloop 2 complete and we can begin stripping down further in order to build our HTML"
'''
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 ??? of the line in question, once we have that we are ready to move
on
'''
for i in range(0, number_of_lines):
search = ''
newoutput[i].find(search)
index = newoutput[i].find(search)
print search, "found at index", index
indexvalue1=int(index)
print indexvalue1
actual_soundfilename = newoutput[i][indexvalue1+11:indexvalue1+11+8]
print actual_soundfilename
'''create sentence for soundplayback script'''
soundplayback = ''
print "This is the soundplayback / embed sentencegeneration" + soundplayback
'''Use actual_soundfilename to create the_HTML_playbackname_for_an_image '''
the_HTML_playbackname_for_an_image = actual_soundfilename + '.html'
print the_HTML_playbackname_for_an_image
search2 = ''
newoutput[i].find(search2)
index = newoutput[i].find(search2)
print search2, "found at index", index
indexvalue2=int(index)
print indexvalue2
an_alternate_title_for_the_image_for_HTML_purposes = newoutput[i][:indexvalue2]
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", index
indexvalue3=int(index)
print indexvalue3
actual_imagefilename = newoutput[i][indexvalue3-8:indexvalue3]
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
'''if condition needed for number so that 0 is padded before'''
generatedHTMLstring = soundplayback + '
'
print generatedHTMLstring
htmloutput.append(generatedHTMLstring+'\n')
anyfilename2 = 'htmltablefile001.txt'
fob2 = open(anyfilename2,'w')
fob2.writelines(htmloutput)
fob2.close()
print "Hallo der"
'''Open fob for HTML in append mode'''
'''Write values of our HTML code to fob'''
'''Close the fob'''
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'ish styled dictionary files for our flashcard quiz program from all the dictionaries available already, which would be a tremendous boon as there are 8 or nine of them available already and in turn those can be turned into HTML for the mobile pointing tablet application so even if it was a detour it has been worth the delay.
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 ('/home/ep/data/data20100509/globability/xtrajava_n_more/soundbites_dk/')
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 proofreader.
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 "developed" in order to make parsing easier for an application programmer that was to make a so called sound board program for the Android platform for my dearest FOSS project The Global Ability Initiative.
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's would be able to participate in the translation efforts and running the program created even if they did not know how or have the resources to have a DB running in the background.
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://sox.sourceforge.net/Docs/Features to learn more, I will not go into the many features and formats of SoX, as I believe it is quite redundant for me to repeat what is said elsewhere.
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 "pattern" (MVC = Model View Controller).
|NOTE TO SELF
|http://en.wikipedia.org/wiki/Multicast - Put in swarmwiki