se 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. #!/usr/bin/perl -w
  2. use strict;
  3. use warnings;
  4. use LWP::Simple;
  5. use Getopt::Long;
  6. use Pod::Usage;
  7. use File::Basename;
  8. binmode STDOUT, ":encoding(UTF-8)";
  9. sub usage;
  10. my $direction = 'encz.en';
  11. my $lines = 25;
  12. my $man = 0;
  13. my $help = 0;
  14. my $host = 'www.slovnik.cz';
  15. GetOptions(
  16. 'lines|l=i' => \$lines,
  17. 'direction|d=s' => \$direction,
  18. 'help|?|h' => \$help,
  19. 'man' => \$man
  20. ) or pod2usage(2);
  21. pod2usage(1) if $help;
  22. pod2usage(-exitstatus => 0, -verbose => 2) if $man;
  23. my $word = shift or usage;
  24. my $query = sprintf(
  25. '/bin/mld.fpl?vcb=%s&dictdir=%s&lines=%s',
  26. $word,
  27. $direction,
  28. $lines
  29. );
  30. my $url = "http://$host$query";
  31. my @lines = split m|\n|, get($url);
  32. @lines = grep m|class="pair"|, @lines;
  33. foreach (@lines) {
  34. s/<.*?>//g;
  35. print;
  36. print "\n";
  37. }
  38. sub usage {
  39. printf STDERR "usage: %s [options] word\n", basename($0); exit 1;
  40. }
  41. __END__
  42. =head1 NAME
  43. se - Translate en-* to/from cs-CZ and many other languages using
  44. www.slovnik.cz service
  45. =head1 SYNOPSIS
  46. B<se> [I<OPTIONS>] I<WORD>
  47. =head1 DESCRIPTION
  48. B<se> will take English word, compose a query to dictionary service at
  49. http://www.slovnik.cz/, fetch the English - Czech pairs and display them
  50. to stdout.
  51. Although English to Czech is default, using B<--direction> parameter
  52. you can translate Czech to English or even between Czech and many other
  53. languages.
  54. For I<WORD> with diacritics, you can provide it
  55. =over 8
  56. =item * directly if your terminal supports it (tested with few Czech words
  57. on Debian 6.0 with urxvt)
  58. =item * directly with diacritics stripped, or
  59. =item * using special notation described here:
  60. http://www.slovnik.cz/alternative_chars.html
  61. Few simple examples:
  62. =over 8
  63. =item * C<c<ert/ik> - c with caron, i with acute
  64. =item * C<pu@da> -- u with ring above
  65. =item * C<Bu:ro> -- u with diaeresis
  66. =item * C<c\eramique> -- e with grave
  67. =item * C<valdepen~as> -- n with tilde
  68. =back
  69. =back
  70. =head1 OPTIONS
  71. =over 8
  72. =item B<-d> I<DIR>, B<--direction=>I<DIR>
  73. Direction of translation. Aside from the default encz.en, it can be
  74. one of following:
  75. encz.en, encz.cz, gecz.ge, gecz.cz, frcz.fr, frcz.cz,
  76. itcz.it, itcz.cz, spcz.sp, spcz.cz, rucz.ru, rucz.cz,
  77. lacz.la, lacz.cz, eocz.eo, eocz.cz, eosk.eo, eosk.sk,
  78. plcz.pl, plcz.cz
  79. =item B<-l> I<LINES>, B<--lines=>I<LINES>
  80. Number of lines fetched fronm the service and displayed to stdout.
  81. Default is 25, but since www.slovnik.cz provides simplistic interface
  82. with only one term per line, so for words with lot of synonyms, you
  83. might want to specify more.
  84. =item B<--help>
  85. Prints a brief help message and exits.
  86. =item B<--man>
  87. Prints the manual page and exits.
  88. =back
  89. =head1 THANKS
  90. Big thanks to Martin Vi/t, LangSoft and everybody who contributed to
  91. existence of this awesome service.
  92. http://www.slovnik.cz/about.html
  93. I have been using www.slovnik.cz for B<many years> now, mostly as a custom
  94. search in Opera, so I grew so accustomed to its reliability and simple
  95. interface that I can't even imagine using anything else. (Or remember
  96. I ever had). I could never repay.
  97. =head1 AUTHOR
  98. ...of this scriptie: Alois Mahdal at zxcvb tec<ka cz
  99. =cut