Monday, 14 January 2008

Vocabulary Reminder

Learning language is hard, it takes lots of effort to memorise various words, expressions and idioms. I realized that on a daily basis [at work] I could learn english if only I had an application that would distrub me and present a word, expression or idiom and it's polish transaction every x minites.
The key here is that it cannot be a dictionary from the internet, it needs to be my personal dictionary. I realize I cannot learn language by studying random words from a dictionary. My strategy is different, when I stumble across a word or an expression that I don't know I jot it down and then I look it up in dictionary along with an example. Rigid dicipline pays off, now I have three notebooks full of words from books, articles, Internet, movies from public television. Speaking of TV I really like Digitial Terrestial Television [DTT] in the uk as you can turn on subtitles for movies and programs and you can fit many channels in one analog channel band. Depending on encryption you can fit more than 8 channels, if there are just radio channels, number is huge thanks to using encryption. This is all MPEG2, so imagine if in future this will be replaced by MPEG4 or its successor, huge potential.

So much for a digression. Speaking of Vocabulary Reminder I already learned basics of ruby so I decided I will try this scripting language for proof of concept application. I used gtk (ruby gtk bindings) and in about half an hour or less I had a working proof of concept application. Parsing of XML is about 2-3 lines of code! I have created xml file and started process of transfering my private vocabulary from paper notebooks to xml.

I have lots of plans to improve application and design it properly, introduce 'I remember' and 'I forgot' buttons that will provide data on whether a priority for a certain word should be increased during word selection process. I am planning to use a roulette wheel algorithm for that purpouse, which is quite popular in genetics algorithms when individual units need to be selected in gene selection process. I also need to investigate glade app and whether I could use it to design a gtk form.

Ruby code:
require 'gtk2'
require 'rexml/document'

#author: Mateusz Szczap (Mateusz.Szczap@gmail.com)
#version: alpha 0.1

def show_window(english_word,polish_word,example_sentence)
Gtk.init
window = Gtk::Window.new()
window.set_title("Vocabulary Reminder")
window.set_window_position(Gtk::Window::POS_CENTER)
window.set_default_size(800,800)

vbox = Gtk::VBox.new
hbox = Gtk::HBox.new

english_label = Gtk::Label.new
english_label.selectable = true
english_label.set_markup("#{english_word}")

polish_label = Gtk::Label.new
polish_label.selectable = true
polish_label.set_markup("#{polish_word}")

example_label = Gtk::Label.new
example_label.set_markup("#{example_sentence}")

button = Gtk::Button.new("I remember!")
button.signal_connect('clicked') {
#window.destroy
}

hbox.add(english_label)
hbox.add(polish_label)

vbox.add(hbox)
vbox.add(example_label)
vbox.add(button)

window.add(vbox)

window.signal_connect('destroy') {
Gtk.main_quit
}

window.show_all

Gtk.main

end

def every_n_seconds(n)
loop do
before = Time.now
yield
interval = n-(Time.now-before)
sleep(interval) if interval > 0
end
end

def randomize(doc)
no_of_elements = doc.root.elements.size
random_index = (1+rand(no_of_elements))

return random_index
end

def lookup_random_voc
doc = REXML::Document.new(File.open('vocabulary.xml'))
random_index = randomize(doc)

english_word = doc.root.elements[random_index].attributes['english']
polish_word = doc.root.elements[random_index].attributes['polish']
example_word = doc.root.elements[random_index].attributes['example']

return english_word,polish_word,example_word

end

every_n_seconds(5*60) {
english_word,polish_word,example_word = lookup_random_voc
show_window(english_word,polish_word,example_word)
}
end of ruby code

You can alter the code in every_n_seconds and instead replace 5 with your desired number of minutes to display a screen.

Example of vocabulary.xml


No comments: