Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@aero
Created April 6, 2010 08:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aero/357372 to your computer and use it in GitHub Desktop.
Save aero/357372 to your computer and use it in GitHub Desktop.
#!/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