Skip to content

Instantly share code, notes, and snippets.

@aero aero/kspell_old.pl

Created Apr 6, 2010
Embed
What would you like to do?
#!/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
You can’t perform that action at this time.