# HG changeset patch # User Igor Chubin # Date 1332850606 -7200 # Node ID 53ba2847501ff99f31f92194dbb14a8a8799f4c4 # Parent 5a003076eb11745b9826e00c536f5969a70d6bb3 added misc scripts diff -r 5a003076eb11 -r 53ba2847501f misc/de-shell --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/misc/de-shell Tue Mar 27 14:16:46 2012 +0200 @@ -0,0 +1,42 @@ + +make_wordlist() +{ + cp -R stardict-GR-LingvoUniversal-2.4.2 /tmp/ + cd /tmp/stardict-GR-LingvoUniversal-2.4.2/ + mv GR-Universal.dict.dz GR-Universal.dict.gz + gunzip GR-Universal.dict.gz + /usr/lib/stardict-tools/stardict2txt GR-Universal.ifo ~/Langs/Deutsch/GR-Universal.txt + cat ~/Langs/Deutsch/GR-Universal.txt | expand| sed 's/ *<.*//; s/ *$//' > ~/Langs/Deutsch/word-list.txt +} + +if [ "$1" = init ] +then + cd /usr/share/stardict/dic/ + make_wordlist + exit 0 +fi + +TEMP=`mktemp /tmp/nw-shell-XXXXXX` +WORD_LIST=~/Langs/Deutsch/word-list.txt +rlwrap -f ${WORD_LIST} sh -c ' + while true; + do + printf "\033[01;33m > " ; + read word options || { exit; printf "\033[00m" ; } ; + if [ "$word" = grep ] + then + grep "$options" "'"${WORD_LIST}"'" + elif [ "$word" = vf ] + then + verbformen "$options" + elif [ "$word" = "#" ] + then + printf "\033[00mWelcome to session >>"$options"<<\n" ; + echo $word $options >> ~/Langs/Deutsch/de-shell.log + else + printf "\033[00m" ; + echo $word >> ~/Langs/Deutsch/de-shell.log + de $word; + fi + done' +rm $TEMP diff -r 5a003076eb11 -r 53ba2847501f misc/memo-word-changer --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/misc/memo-word-changer Tue Mar 27 14:16:46 2012 +0200 @@ -0,0 +1,150 @@ +#!/usr/bin/perl + +our $change_matix = ''; + +our $change_matrix = ' +um über mit von vom nach zum zur in an auf +der das des dem den ein einer einem einen eines +'; + +our $change_matrix = ' +router network ip route +'; + +if (open(FILE, $ARGV[0])) { + local $/; + $change_matrix = ; +} +shift @ARGV; + +my $BaseURL = $ARGV[0]; +shift; + +my $Subdir = $ARGV[0]; +shift; + +my $StateFile = $ARGV[0]; +shift; + +sub load_state() +{ + my %state; + my $entries = 0; + if (open(FILE, "$StateFile")) { + while() { + chomp; + my ($k,$v) = split /\s+/, $_, 2; + $state{$k} = $v; + $entries += 1; + } + } + $state{"ENTRIES"} = $entries; + return \%state; +} + +@colors = qw(ccccff 7aedaa ddeecc ffccee); + +our %change_matrix; +our %color; +our $dropdown_number = 0; + +$i = 0; +for (split /\n/, $change_matrix){ + next if /^\s*$/; + my @words = sort(split /\s+/); + for my $kw (@words) { + $change_matrix{$kw} = [ "???", @words ]; + $color{$kw} = $colors[$i%@colors]; + } + # uppercase + for (@words) { + s/(.)(.*)/\U$1\E$2/; + } + for my $kw (@words) { + $change_matrix{$kw} = [ "???", @words ]; + $color{$kw} = $colors[$i%@colors]; + } + $i += 1; +}; + +#for (keys(%change_matrix)) { +# print "$_ => ".join(", ", @{$change_matrix{$_}})."\n"; +# print "$_ => ".$color{$_}."\n"; +#} +our $CorrectAnswers = 0; + +sub generate_drop_down($$) +{ + my $word = $_[0]; + my %state = %{$_[1]}; + + my $name = "dropdown$dropdown_number"; + my $value = $state{$name}; + $dropdown_number += 1; + my @variants = @{$change_matrix{$word}}; + $options = join("", map {my $selected = ""; $selected='selected="selected"' if $_ eq $value; ""} @variants); + my $color = $color{$word}; + if ($word eq $value) { + $color = "ffffff"; + $CorrectAnswers += 1; + } + if ($color) { + $color = "background:#$color"; + } + my $disabled = ""; + if ($value eq $word) { + $disabled = "disabled"; + } + my $onchange = "onchange='javascript:myAlert(\"$name\", this.form.$name, \"$word\")'"; + return "
"; +} +sub highlight_word($$$) +{ + my $tag = $_[0]; + my $text = $_[1]; + my $state = $_[2]; + + if ($tag=~/^<[aA]/) { + return $tag.$text; + } + my $re = join("|", keys(%change_matrix)); + $text =~ s@(^|[;> ])($re)(?=([ <]|$))@"$1".generate_drop_down($2, $state)@egms; + return $tag.$text; +} + +my $state = load_state(); +#my %a = %{$state}; +#print join(", ", keys(%a)),"\n"; + +$jquery = ""; +local $/; +$text = <>; +$text =~ s@()(.*?)()@$2@g; +$text =~ s@(.*)(]*>)@$2@ims; +my $before_body = $1; +$text =~ s@(]*>)@$1@ims; +$text =~ s/(<.*?>)([^<]*)(?=<)/highlight_word($1, $2, $state)/egms; +$text = $before_body.$text; + +my $wrong_answers = $$state{"ENTRIES"} - $CorrectAnswers; +$info_div = " +
+ $wrong_answers   + $CorrectAnswers   + $dropdown_number +
"; + +$text =~ s@(]*>)@$jquery$1$info_div@i; +$text =~ s@(]*>)@$1@i; +print $text; diff -r 5a003076eb11 -r 53ba2847501f misc/memo.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/misc/memo.js Tue Mar 27 14:16:46 2012 +0200 @@ -0,0 +1,42 @@ +var memo_state = { + 'initialized' : 0, + 'answers' : {}, + }; + +function memo_init() { + memo_state.initialized = 1; +} +function memo_saveState() { + if (memo_state.initialized == 1) { + $.post("http://xgu.ru/memo/post/state/"+memo_subdir, memo_state.answers); + } +} +function memo_saveAnswer(key, value) { + if (memo_state.initialized == 1) { + var entry = {}; + entry[key] = value; + $.post("http://xgu.ru/memo/post/state/"+memo_subdir, entry); + } +} +function myAlert(name, dropdown, correct_answer) { + var myindex = dropdown.selectedIndex; + var SelValue = dropdown.options[myindex].value; + memo_state.answers[name] = SelValue; + if (SelValue == correct_answer) { + dropdown.style.backgroundColor = '#ffffff'; + dropdown.disabled = true; + + var x = $("#correct_answers").html(); + $("#correct_answers").html(parseInt(x) + 1); + + x = $("#yet_to_answer").html(); + $("#yet_to_answer").html(parseInt(x) - 1); + } + else { + var x = $("#wrong_answers").html(); + $("#wrong_answers").html(parseInt(x) + 1); + } + //memo_saveState(); + memo_saveAnswer(name, SelValue); + return true; +} diff -r 5a003076eb11 -r 53ba2847501f misc/one-word-voc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/misc/one-word-voc Tue Mar 27 14:16:46 2012 +0200 @@ -0,0 +1,35 @@ + +cat < /dev/null +Как работает? +---------------- + +Слова, которые мы должны обрабатывать поступают на стандартный поток ввода. +* Удаляем из них комментарии. +* Размножаем слова, которые, возможно, находятся не в нормальной форме. + Например, слова, заканчивающиеся на te. +* Прогоняем через прогу, которая разложит их по категориям. +* Разложенные по категориям слова прогоняем ещё раз. +EOF + +word_multiplier() +{ + cat +} + +new-words -l de -R 95 -n -c -a "$@" \ +| grep -v ^# | awk '{print $2}' | word_multiplier \ +| while read word +do + de-short "$word" +done \ +| perl ~/hg/new-words/misc/categorized.pl \ +| while read word +do + if echo $word | fgrep -q "|" + then + w="$(echo $word | awk '{print $1}')" + a="`de-super-short $w`"; [ -n "$a" ] && echo $w " | " $a + else + echo "$word" + fi +done diff -r 5a003076eb11 -r 53ba2847501f misc/word-changer.pl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/misc/word-changer.pl Tue Mar 27 14:16:46 2012 +0200 @@ -0,0 +1,87 @@ +our $change_matrix = ' +um über mit von vom nach zum zur in an auf +der das des dem den ein einer einem einen eines +'; + +@colors = qw(ccccff 7aedaa ddeecc ffccee); + +our %change_matrix; +our %color; +our $dropdown_number = 0; + +$i = 0; +for (split /\n/, $change_matrix){ + next if /^\s*$/; + my @words = sort(split /\s+/); + for my $kw (@words) { + $change_matrix{$kw} = [ "???", @words ]; + $color{$kw} = $colors[$i%@colors]; + } + # uppercase + for (@words) { + s/(.)(.*)/\U$1\E$2/; + } + for my $kw (@words) { + $change_matrix{$kw} = [ "???", @words ]; + $color{$kw} = $colors[$i%@colors]; + } + $i += 1; +}; + +for (keys(%change_matrix)) { + print "$_ => ".join(", ", @{$change_matrix{$_}})."\n"; + print "$_ => ".$color{$_}."\n"; +} + +sub generate_drop_down($) +{ + my $name = "dropdown$dropdown_number"; + $dropdown_number += 1; + my $word = $_[0]; + my @variants = @{$change_matrix{$word}}; + $options = join("", map {""} @variants); + my $color = $color{$word}; + if ($color) { + $color = "background:#$color"; + } + my $onchange = "onchange='javascript:myAlert(this.form.$name, \"$word\")'"; + return "
"; +} +sub highlight_word($$) +{ + my $tag = $_[0]; + my $text = $_[1]; + if ($tag=~/^<[aA]/) { + return $tag.$text; + } + my $re = join("|", keys(%change_matrix)); + #$text =~ s@ ([Aa]uf) @@g; + $text =~ s@(^|[;> ])($re)(?=([ <]|$))@"$1".generate_drop_down($2)@eg; + return $tag.$text; +} + +$jquery = ""; +local $/; +$text = <>; +$text =~ s@()(.*?)()@$2@g; +$text =~ s/(<.*?>)([^<]*)(?=<)/highlight_word($1, $2)/eg; +$info_div = " +
+ 0   + 0   + $dropdown_number +
"; + +$text =~ s@(]*>)@$jquery$1$info_div@i; +print $text;