Created
April 6, 2010 08:59
-
-
Save aero/357372 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use LWP::UserAgent; | |
use Encode qw/encode decode from_to/; | |
my $ua = LWP::UserAgent->new; | |
my $text = $ARGV[0]; | |
my $unitext = decode('utf8', $text); | |
$text = encode('euc-kr', $unitext); | |
my $req = HTTP::Request->new(POST => 'http://speller.cs.pusan.ac.kr/WebSpell_ISAPI.dll?Check'); | |
$req->content_type('application/x-www-form-urlencoded'); | |
$req->content("text1=$text"); | |
my $res = $ua->request($req); | |
die unless $res->is_success; | |
my $content = $res->as_string; | |
my ($table) = $content =~ m{<table border=1.*?>(.*?)</table>}s; | |
my @rows = $table =~ m{<tr>(.*?)</tr>}sg; | |
my @items; | |
foreach my $row (@rows) { | |
my %item; | |
@item{qw/incorrect correct comment/} = | |
( map { $_ =~s/<.*?br>/\n/g; | |
$_ =~s/\[ NARAINFOTECH.*?\]//; | |
$_ = decode('euc-kr',$_); | |
$_ } $row =~ m{<td.*?>(.*?)</td>}sg )[0..2]; | |
$unitext =~ m/$item{incorrect}/g; | |
$item{position} = ( pos $unitext ) - ( length $item{incorrect} ); | |
push @items, \%item; | |
} | |
binmode STDOUT, ':encoding(UTF-8)'; | |
print "(",$_->{position},")",$_->{incorrect}," -> ",$_->{correct},"\n", | |
$_->{comment},"\n-------------------------------\n" for @items; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment