1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303
|
# ###################################################################### Otakar Smrz, 2007/10/05
#
# ElixirFM Online Interface ####################################################################
# $Id: CGI.pm 946 2010-04-12 19:27:23Z smrz $
package ElixirFM::CGI;
use strict;
our $VERSION = join '.', '1.1', q $Revision: 946 $ =~ /(\d+)/;
use base 'CGI::Application::FastCGI';
use CGI::Fast ':standard';
use base 'Exporter';
our @EXPORT = (qw 'display_header display_headline display_welcome display_footline display_footer',
qw 'escape quote revert',
qw '@modes %memoize %enc_hash @enc_list');
our @modes = qw 'home resolve inflect derive lookup';
our %memoize = ();
our %enc_hash = ( 'ArabTeX' => 'TeX',
'Buckwalter' => 'Tim',
'Unicode' => 'UTF' );
our @enc_list = reverse sort keys %enc_hash;
sub setup {
my $c = shift;
no strict;
$c->run_modes('home' => \&{__PACKAGE__ . '::main'}, map { $_ => \&{__PACKAGE__ . '::' . (ucfirst $_) . '::main'} } @modes[1 .. @modes - 1]);
use strict;
$c->mode_param('mode');
$c->start_mode('home');
}
# use base 'CGI::Application::FastCGI';
sub run {
my $self = shift;
my $request = FCGI::Request();
$self->fastcgi($request);
while ($request->Accept >= 0) {
$self->reset_query;
$self->CGI::Application::run;
last if $self->reinit();
}
}
sub reinit {
return -M $0 < 0;
}
sub escape ($) {
my $text = shift;
$text =~ s/\&/\&/g;
$text =~ s/\</\</g;
$text =~ s/\>/\>/g;
return $text;
}
sub quote ($) {
return $_[0] eq '' ? '""' : $_[0];
}
sub revert ($) {
my $text = shift;
$text =~ s/\>/\>/g;
$text =~ s/\</\</g;
$text =~ s/\&/\&/g;
return $text;
}
sub display_header ($) {
my $c = shift;
my $q = $c->query();
my $r;
$q->charset('utf-8');
$r .= $q->start_html(-title => "ElixirFM 1.1 Online Interface", -encoding => $q->charset(),
-meta => { 'keywords' => join ' ', 'Arabic morphological analyzer analysis generator generation',
'morphology lexicon dictionary lookup inflection derivation rules grammar language' },
-style => [ {-src => 'http://quest.ms.mff.cuni.cz/elixir/elixir.css', -type => 'text/css'},
{-src => 'http://quest.ms.mff.cuni.cz/elixir/listexpander/listexpander.css', -type => 'text/css'} ],
-script => [ {-src => 'http://quest.ms.mff.cuni.cz/elixir/elixir.js', -type => 'text/javascript'},
{-src => 'http://quest.ms.mff.cuni.cz/elixir/listexpander/listexpander.js', -type => 'text/javascript'} ]);
return $r;
}
sub display_headline ($) {
my $c = shift;
my $q = $c->query();
my $m = $q->param($c->mode_param());
my $r;
$r .= $q->h1($q->a({'href' => 'http://sourceforge.net/projects/elixir-fm/'}, "ElixirFM 1.1"), ( $m eq 'home' ? ('Online', 'Interface') : (ucfirst $m, 'Online') ));
$r .= $q->div({-class => "menu"},
map { $q->param($c->mode_param()) eq $_ ? $q->span(ucfirst $_) : $q->a({'href' => 'index.fcgi?mode=' . $_}, ucfirst $_) } @modes);
return $r;
}
sub display_welcome ($) {
my $c = shift;
my $q = $c->query();
my $r;
$r .= $q->p("Welcome to the online interface to",
$q->a({-href => 'http://sourceforge.net/projects/elixir-fm/'}, "ElixirFM") . ", the implementation of",
$q->a({-href => 'http://ufal.mff.cuni.cz/~smrz/elixir-thesis.pdf'}, "Functional Arabic Morphology"),
"written in Haskell and Perl.");
$r .= $q->p("ElixirFM can work in four different modes. This request is processed by the",
$q->code($q->param($c->mode_param())), "method of the morphological system.");
return $r;
}
sub display_footline ($) {
my $c = shift;
my $q = $c->query();
my $r;
$r .= $q->p({'style' => 'margin-top: 30px'},
"(C) Otakar Smrz 2010, Viktor Bielicky 2010, Tim Buckwalter 2002. GNU General Public License",
$q->a({-href => 'http://www.gnu.org/licenses/'}, "GNU GPL 3") . ".");
$r .= $q->p("ElixirFM is an", $q->a({-href => 'http://sourceforge.net/projects/elixir-fm/'}, "open-source online"), "project.",
"You can contribute to its development with your suggestions!");
$r .= $q->p("Contact", $q->a({-href => 'http://ufal.mff.cuni.cz/~smrz/'}, "otakar.smrz"), "at",
$q->a({-href => 'http://ufal.mff.cuni.cz/'}, "mff.cuni.cz") . ",",
"Institute of Formal and Applied Linguistics, Charles University in Prague.");
return $r;
}
sub display_footer ($) {
my $c = shift;
my $q = $c->query();
my $r;
$r .= $q->p( # {'style' => 'height: 31px'},
# $q->a({'style' => 'float: right',
# 'href' => "http://jigsaw.w3.org/css-validator/check?uri=referer"},
# $q->img({'border' => "0",
# 'src' => "http://www.w3.org/Icons/valid-css2",
# 'alt' => "Valid CSS level 2.1",
# 'height' => "31", 'width' => "88"})),
# $q->a({'style' => 'float: right',
# 'href' => "http://validator.w3.org/check?uri=referer"},
# $q->img({'border' => "0",
# 'src' => "http://www.w3.org/Icons/valid-xhtml10",
# 'alt' => "Valid XHTML 1.0 Transitional",
# 'height' => "31", 'width' => "88"})),
$q->a({'style' => 'float: right',
'href' => "http://sourceforge.net/projects/elixir-fm/"},
$q->img({'border' => "0",
'style' => 'margin-bottom: 20px',
'src' => "http://sflogo.sourceforge.net/sflogo.php?group_id=181087&type=13",
'alt' => "ElixirFM at SourceForge.net",
'height' => "30", 'width' => "120"})) );
$r .= $q->script({-type => 'text/javascript', -src => 'http://api.yamli.com/js/yamli_api.js'}, "");
$r .= $q->script({-type => 'text/javascript'}, join ' ', split ' ', q {
if (typeof(Yamli) == "object") {
Yamli.init({ uiLanguage: "en", startMode: "onOrUserDefault",
settingsPlacement: 'inside',
showTutorialLink: false, showDirectionLink: false });
elixirYamli('');
}
});
$r .= $q->end_html();
return $r;
}
sub show_param ($@) {
my $q = shift;
return join '', map { '&' . $_ . '=' . $q->param($_) } @_;
}
require ElixirFM::CGI::Resolve;
require ElixirFM::CGI::Inflect;
require ElixirFM::CGI::Derive;
require ElixirFM::CGI::Lookup;
sub main ($) {
my $c = shift;
my $q = $c->query();
my $r = '';
$q->param($c->mode_param(), 'home');
$r .= display_header $c;
$r .= display_headline $c;
$r .= $q->p("Welcome to the online interface to",
$q->a({-href => 'http://sourceforge.net/projects/elixir-fm/'}, "ElixirFM") . ", the implementation of",
$q->a({-href => 'http://ufal.mff.cuni.cz/~smrz/elixir-thesis.pdf'}, "Functional Arabic Morphology"),
"written in Haskell and Perl.");
$r .= $q->p("ElixirFM can process words of", $q->a({-href => 'http://en.wikipedia.org/wiki/Dictionary_of_Modern_Written_Arabic'},
"Modern Written Arabic"), "using four different modes.", "Here, you can learn how to use these modes for various purposes.");
$r .= $q->p("ElixirFM is further documented at", $q->a({-href => 'http://elixir-fm.wiki.sourceforge.net/'},
"ElixirFM Wiki") . ".",
"The multiple scripts of this site are best viewed with", $q->a({-href => 'http://sourceforge.net/projects/dejavu/'},
"DejaVu Fonts") . ".");
$r .= $q->h2($q->a({-href => 'index.fcgi?mode=resolve'}, 'Resolve'));
$r .= $q->p("This mode provides tokenization and morphological analysis of the inserted text,",
"even if you omit some symbols or do not spell everything correctly.");
$r .= $q->p("You can experiment with entering the text in various notations.");
# $r .= $q->p("You can check the 'Fuzzy Notation' option due to which the resolution of the input words is less strict.");
$r .= $q->h2($q->a({-href => 'index.fcgi?mode=inflect'}, 'Inflect'));
$r .= $q->p("This mode lets you inflect words into the forms required by context.",
"You only need to define the grammatical parameters of the expected word forms.");
$r .= $q->p("You can either enter natural language descriptions, or you can specify the parameters using the positional morphological tags.");
$r .= $q->h2($q->a({-href => 'index.fcgi?mode=derive'}, 'Derive'));
$r .= $q->p("This mode lets you derive words of similar meaning but different grammatical category.",
"You only need to tell the desired grammatical categories.");
$r .= $q->p("You can either enter natural language descriptions, or you can specify the parameters using the positional morphological tags.");
$r .= $q->h2($q->a({-href => 'index.fcgi?mode=lookup'}, 'Lookup'));
$r .= $q->p("This mode can lookup lexical entries by the citation form and nests of entries by the root,",
"and lets you search also in the English translations.");
$r .= $q->p("You can try enclosing the text in quotes or parentheses if needed.");
$r .= display_footline $c;
$r .= display_footer $c;
return $r;
}
1;
|