| 1 |
#!/usr/bin/perl |
| 2 |
# Written by Jon Dehdari 2004-2005 |
| 3 |
# Perl 5.8 |
| 4 |
# Arabic LG Syntax Parser |
| 5 |
# The license is the GPL (www.fsf.org) |
| 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, not just CGI |
| 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 $width = param ("width"); |
| 19 |
my $root_only = param ("root_only"); |
| 20 |
my $preserve_links = param ("preserve_links"); |
| 21 |
my $use_web_page = param ("use_web_page"); |
| 22 |
my $web_page = param ("web_page"); |
| 23 |
my $use_file = param ("use_file"); |
| 24 |
my $uploaded_file = param ("uploaded_file"); |
| 25 |
my $text_from = param ("text_from"); |
| 26 |
#my $input_type = "1"; |
| 27 |
#my $text_from = "\u{d986}\u{d8a7}\u{d986}\u{d987}\u{d8a7}"; |
| 28 |
#my $text_from = "\u{0646}\u{0627}\u{0646}\u{0647}\u{0627}"; |
| 29 |
#my $text_from = "نانها"; |
| 30 |
#my $text_from = "قدومي بفارغ الصبر"; |
| 31 |
#my $preserve_links = 0; |
| 32 |
#my $use_file = "false"; |
| 33 |
#my $uploaded_file = "false"; |
| 34 |
#my $use_web_page = "false"; |
| 35 |
#my $web_page = "false"; |
| 36 |
#my $remove_stops = "false"; |
| 37 |
my $text_from_new; |
| 38 |
my @charx; |
| 39 |
my $charx; |
| 40 |
my $input_rtl; |
| 41 |
|
| 42 |
if ($input_type =~ /[^0]/) { $input_rtl = "true"; } |
| 43 |
|
| 44 |
|
| 45 |
if ($input_type eq "utf8" || $output_type eq "utf8") { print $query->header( -charset => 'UTF-8'); } |
| 46 |
else { print $query->header( -charset => 'windows-1256'); } |
| 47 |
|
| 48 |
|
| 49 |
print( |
| 50 |
'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//FA">', |
| 51 |
"\n", |
| 52 |
'<html lang="en">', |
| 53 |
"\n", |
| 54 |
"\n", |
| 55 |
# "<style>\n", |
| 56 |
# " body \{ text-align\:right \}\n", |
| 57 |
# "<\/style>\n", |
| 58 |
"<head>\n", |
| 59 |
); |
| 60 |
if ($input_type eq "utf8" || $output_type eq "utf8") { print '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">'; } |
| 61 |
if ($input_type eq "cp1256") { print '<meta http-equiv="Content-Type" content="text/html; charset=windows-1256">'; } |
| 62 |
print( |
| 63 |
"\n", |
| 64 |
"<title>Arabic LG Syntax Parser<\/title>\n", |
| 65 |
"<\/head>\n", |
| 66 |
"<body>\n", |
| 67 |
); |
| 68 |
|
| 69 |
# For getting web page stuff |
| 70 |
if ($use_web_page eq "--noroman") { |
| 71 |
$text_from = ""; # Clears out residue from the web form |
| 72 |
#$text_from = get "$web_page" or warn $!; |
| 73 |
#print("$text_from"); |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
elsif ($use_file eq "true") { |
| 78 |
$text_from = ""; # Clears out residue from the web form |
| 79 |
while (my $line = <$uploaded_file> ) { |
| 80 |
$text_from = $text_from . $line ; |
| 81 |
} |
| 82 |
#if (length $text_from > 40000 ) { |
| 83 |
# die "Your uploaded file is too big.<br/></td></tr></table></html>\n"; |
| 84 |
#} |
| 85 |
} |
| 86 |
|
| 87 |
if ($use_web_page ne "--noroman" && $use_file ne "true") { |
| 88 |
my $formated_text_from = "$text_from"; |
| 89 |
$formated_text_from =~ s/\n/<br\/>\n/g; #changes newline to <br>for from text |
| 90 |
#print("$formated_text_from"); |
| 91 |
} |
| 92 |
|
| 93 |
$text_from =~ s/(?<!\&#\w{4})[;]/ _$1_ /g; #Preserves punctuation for semicolon except for unicode decimal &#....; |
| 94 |
$text_from =~ s/([.,?!])/ _$1_ /g; #Preserves punctuation |
| 95 |
|
| 96 |
|
| 97 |
chomp $text_from; |
| 98 |
my $word = $text_from; |
| 99 |
#print "text_from: $text_from<br>"; |
| 100 |
|
| 101 |
print "\n"; |
| 102 |
#print '<div style="font-family: Monospace">'; |
| 103 |
print "\n<pre>\n"; |
| 104 |
$word =~ s/</</g; # even <pre> doesn't like "<" |
| 105 |
print "$word<br/>\n"; |
| 106 |
$word =~ s/</</g; # change "<" back to "<" |
| 107 |
#$word =~ s/\n/<br\/>\n/g; |
| 108 |
$word =~ s/"/\\"/g; |
| 109 |
$word =~ s/\brm\b|\bmv\b|passwd|shadow|etc|var|cat//g; # some security measures |
| 110 |
|
| 111 |
#my $lgout = `echo -e '!width=$width\n$word\n' | ./aramorph_fast.pl -i $input_type | /usr/bin/lgparser /home/jon/public_html/arabiclg/4.0.dict 2>/dev/null `; |
| 112 |
my $lgout = `echo -e "$word" | ./aramorph_fast.pl -i $input_type 2>/dev/null | ./buck2lg.sh | (echo -e '!width=$width\n' ; cat) | /usr/bin/link-grammar ../4.0.dict 2>/dev/null | egrep -v 'Opening|RETURN|I can|\+\+Time|width set to' `; |
| 113 |
|
| 114 |
#$lgout =~ s/I can't interpret.*\n//g; |
| 115 |
$lgout =~ s/linkparser\>//g; |
| 116 |
$lgout =~ s/</</g; |
| 117 |
print $lgout; |
| 118 |
print "\n</pre>\n<br/>\n"; |
| 119 |
#print '</div>'; |
| 120 |
|
| 121 |
|
| 122 |
print <<EOF; |
| 123 |
<hr align="left" width="620" /><br/><br/> |
| 124 |
<form action="arabiclg.cgi" method="post" enctype="multipart/form-data"> |
| 125 |
<acronym title="Note: Copying and Pasting often changes the encoding type.">Encoding</acronym>: |
| 126 |
<select name="input_type"> |
| 127 |
<option value="roman">Romanized Buckwalter</option> |
| 128 |
<option value="utf8" selected="selected">UTF-8</option> |
| 129 |
<!-- <option value="0">Unicode Decimal</option> --> |
| 130 |
<option value="cp1256">Windows 1256</option> |
| 131 |
<!-- <option value="7">ISO 8859-6</option> --> |
| 132 |
<!-- <option value="8">ArabTeX</option> --> |
| 133 |
</select> |
| 134 |
Width: |
| 135 |
<input type="text" name="width" maxlength="3" value="150" > |
| 136 |
<!-- <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/> --> |
| 137 |
<!-- <input name="use_file" type="checkbox" value="true"> Upload Text File: <input name="uploaded_file" type="file" size="29"> --> |
| 138 |
<br/><br/> |
| 139 |
Text:<br/> |
| 140 |
<textarea name="text_from" maxlength="200" wrap="virtual" rows="03" cols="60"></textarea> |
| 141 |
<br/><br/> |
| 142 |
<input type="submit" value="Submit"><br/><br/> |
| 143 |
</form> |
| 144 |
EOF |
| 145 |
; |
| 146 |
|
| 147 |
|
| 148 |
#} # ends foreach (@word) |
| 149 |
|
| 150 |
print( "\n<br\/>\n<\/body>\n<\/html>\n"); |