| 1 |
#!/usr/bin/perl |
| 2 |
# Written by Jon Dehdari 2004-2006 |
| 3 |
# Perl 5.8 |
| 4 |
# Arabic Morphological Analyzer CGI |
| 5 |
# The license is the GPL v. 2 (See http://www.fsf.org for details) |
| 6 |
|
| 7 |
use strict; |
| 8 |
use utf8; |
| 9 |
#use diagnostics; |
| 10 |
#binmode(STDOUT, ":utf8"); |
| 11 |
#use LWP::Simple qw(!head); |
| 12 |
use CGI qw(:standard); #must use this full line |
| 13 |
$CGI::POST_MAX=50000; |
| 14 |
my $query = new CGI; |
| 15 |
|
| 16 |
my $input_type = param ("input_type"); |
| 17 |
my $output_type = param ("output_type"); |
| 18 |
my $use_web_page = param ("use_web_page"); |
| 19 |
my $web_page = param ("web_page"); |
| 20 |
my $use_file = param ("use_file"); |
| 21 |
my $uploaded_file = param ("uploaded_file"); |
| 22 |
my $text_from = param ("text_from"); |
| 23 |
#my $input_type = "1"; |
| 24 |
#my $use_file = "false"; |
| 25 |
#my $uploaded_file = "false"; |
| 26 |
#my $use_web_page = "false"; |
| 27 |
#my $web_page = "false"; |
| 28 |
my $text_from_new; |
| 29 |
my @charx; |
| 30 |
my $charx; |
| 31 |
my $input_rtl; |
| 32 |
|
| 33 |
unless ($input_type eq 'roman') { $input_rtl = "true"; } |
| 34 |
|
| 35 |
|
| 36 |
if ($input_type eq "utf8" || $output_type eq "utf8") { print $query->header( -charset => 'UTF-8'); } |
| 37 |
else { print $query->header( -charset => 'windows-1256'); } |
| 38 |
|
| 39 |
|
| 40 |
print( |
| 41 |
'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//AR">', |
| 42 |
"\n", |
| 43 |
'<html lang="ar">', |
| 44 |
"\n", |
| 45 |
"\n", |
| 46 |
# "<style>\n", |
| 47 |
# " body \{ text-align\:right \}\n", |
| 48 |
# "<\/style>\n", |
| 49 |
"<head>\n", |
| 50 |
); |
| 51 |
if ($input_type eq "utf8" || $output_type eq "utf8") { print '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">'; } |
| 52 |
if ($input_type eq "cp1256") { print '<meta http-equiv="Content-Type" content="text/html; charset=windows-1256">'; } |
| 53 |
print( |
| 54 |
"\n", |
| 55 |
"<title>Buckwalter Arabic Morphological Analyzer<\/title>\n", |
| 56 |
"<\/head>\n", |
| 57 |
"<body>\n", |
| 58 |
); |
| 59 |
|
| 60 |
# For getting web page stuff |
| 61 |
if ($use_web_page eq "--noroman") { |
| 62 |
$text_from = ""; # Clears out residue from the web form |
| 63 |
#$text_from = get "$web_page" or warn $!; |
| 64 |
#print("$text_from"); |
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
elsif ($use_file eq "true") { |
| 69 |
$text_from = ""; # Clears out residue from the web form |
| 70 |
while (my $line = <$uploaded_file> ) { |
| 71 |
$text_from = $text_from . $line ; |
| 72 |
} |
| 73 |
#if (length $text_from > 40000 ) { |
| 74 |
# die "Your uploaded file is too big.<br/></td></tr></table></html>\n"; |
| 75 |
#} |
| 76 |
} |
| 77 |
|
| 78 |
if ($use_web_page ne "--noroman" && $use_file ne "true") { |
| 79 |
my $formated_text_from = "$text_from"; |
| 80 |
$formated_text_from =~ s/\n/<br\/>\n/g; #changes newline to <br>for from text |
| 81 |
#print("$formated_text_from"); |
| 82 |
} |
| 83 |
|
| 84 |
$text_from =~ s/(?<!\&#\w{4})[;]/ _$1_ /g; #Preserves punctuation for semicolon except for unicode decimal &#....; |
| 85 |
$text_from =~ s/([.,?!])/ _$1_ /g; #Preserves punctuation |
| 86 |
|
| 87 |
|
| 88 |
chomp $text_from; |
| 89 |
my $word = $text_from; |
| 90 |
#print "text_from: $text_from<br>"; |
| 91 |
|
| 92 |
print "\n"; |
| 93 |
#print '<div style="font-family: Monospace">'; |
| 94 |
print "\n<pre>\n"; |
| 95 |
$word =~ s/</</g; # even <pre> doesn't like "<" |
| 96 |
print "$word<br/>\n"; |
| 97 |
$word =~ s/</</g; # change "<" back to "<" |
| 98 |
#$word =~ s/\n/<br\/>\n/g; |
| 99 |
$word =~ s/"/\\"/g; |
| 100 |
$word =~ s/\brm\b|\bmv\b|passwd|shadow|etc|var|cat//g; # some security measures |
| 101 |
|
| 102 |
my $out = `echo -e "$word" | ./aramorph_fast.pl -i $input_type 2>/dev/null `; |
| 103 |
|
| 104 |
$out =~ s/</</g; |
| 105 |
print $out; |
| 106 |
print "\n</pre>\n<br/>\n"; |
| 107 |
#print '</div>'; |
| 108 |
|
| 109 |
|
| 110 |
print <<EOF; |
| 111 |
<hr align="left" width="620" /><br/><br/> |
| 112 |
<form action="aramorph_fast.cgi" method="post" enctype="multipart/form-data"> |
| 113 |
<acronym title="Note: Copying and Pasting often changes the encoding type.">Encoding</acronym>: |
| 114 |
<select name="input_type"> |
| 115 |
<option value="dt">Dil's Transliteration</option> |
| 116 |
<option value="roman">Buckwalter Transliteration</option> |
| 117 |
<option value="utf8" selected="selected">UTF-8</option> |
| 118 |
<!-- <option value="unidec">Unicode Decimal</option> --> |
| 119 |
<option value="cp1256">Windows 1256</option> |
| 120 |
<!-- <option value="uniname">Unicode Name</option> --> |
| 121 |
<!-- <option value="iso88596">ISO 8859-6</option> --> |
| 122 |
<!-- <option value="arabtex">ArabTeX</option> --> |
| 123 |
</select> |
| 124 |
|
| 125 |
<!-- <input name="use_web_page" type="checkbox" value="true"> Use Web Page: <input name="web_page" type="text" maxlength="511" size="41" value="http://"> --> <br/><br/> |
| 126 |
<input name="use_file" type="checkbox" value="true"> Upload Text File: <input name="uploaded_file" type="file" size="30"> |
| 127 |
<br/><br/> |
| 128 |
Text:<br/> |
| 129 |
<textarea name="text_from" maxlength="800" wrap="virtual" rows="05" cols="60"></textarea> |
| 130 |
<br/><br/> |
| 131 |
<input type="submit" value="Submit"><br/><br/> |
| 132 |
</form> |
| 133 |
EOF |
| 134 |
; |
| 135 |
|
| 136 |
|
| 137 |
#} # ends foreach (@word) |
| 138 |
|
| 139 |
print( "\n<br\/>\n<\/body>\n<\/html>\n"); |