인간이 할 수 있습니까?
farsidebag
far sidebag
farside bag
far side bag
뿐만 아니라 당신은, 당신이 가장 가능성의 의미를 알아 내기 위해 통계적 방법을 사용 할 수있는 사전을 사용해야합니까 (선택의 인간의 언어, 신 금지, 실제 HMM 또는 ...) 도움이 될 수있는 통계 작업을 수행하는 방법에 대한
, 나는 다른,하지만 관련 문제를 해결 박사 피터 노빅로 변신 맞춤법 검사 코드의
21 라인 :
http://norvig.com/spell-correct.html
을
(he 모든 for 루프를 한 줄로 접어서 속임수를 사용합니다.하지만 여전히).
업데이트이는 내 머리에 갇혀, 그래서 나는 오늘을 출산했다있어.이 코드는 로버트 갬블 (Robert Gamble)이 설명한 것과 비슷한 방식으로 분할하지만 제공된 사전 파일에서 단어 빈도를 기반으로 결과를 정렬합니다 (현재 도메인이나 영어를 나타내는 일부 텍스트로 예상 됨). 위의 링크 된 Norvig의 .txt와 누락 된 단어를 충당하기 위해 사전을 catted).
주파수 차이가 엄청나지 않는 한 두 단어의 조합은 대부분 3 개의 단어 조합을 이길 것입니다.
은 내 블로그
http://squarecog.wordpress.com/2008/10/19/splitting-words-joined-into-a-single-string/ 에 약간의 변경이 코드를 게시하고이 코드의 언더 버그에 대해 조금 썼다 .. 난 그냥 조용히 그것을 해결하기 위해 유혹했지만, 이 전에 로그 트릭을 보지 못한 일부 사람들 데 도움이 될 수 있습니다 생각 : 귀하의 단어에 http://squarecog.wordpress.com/2009/01/10/dealing-with-underflow-in-joint-probability-calculations/
출력을, 플러스 몇 가지 내 자신의 - "orcore"로 무슨주의 :
perl splitwords.pl big.txt words
answerveal: 2 possibilities
- answer veal
- answer ve al
wickedweather: 4 possibilities
- wicked weather
- wicked we at her
- wick ed weather
- wick ed we at her
liquidweather: 6 possibilities
- liquid weather
- liquid we at her
- li quid weather
- li quid we at her
- li qu id weather
- li qu id we at her
driveourtrucks: 1 possibilities
- drive our trucks
gocompact: 1 possibilities
- go compact
slimprojector: 2 possibilities
- slim projector
- slim project or
orcore: 3 possibilities
- or core
- or co re
- orc ore
코드 :
#!/usr/bin/env perl
use strict;
use warnings;
sub find_matches($);
sub find_matches_rec($\@\@);
sub find_word_seq_score(@);
sub get_word_stats($);
sub print_results([email protected]);
sub Usage();
our(%DICT,$TOTAL);
{
my($dict_file, $word_file) = @ARGV;
($dict_file && $word_file) or die(Usage);
{
my $DICT;
($DICT, $TOTAL) = get_word_stats($dict_file);
%DICT = %$DICT;
}
{
open(my $WORDS, '<', $word_file) or die "unable to open $word_file\n";
foreach my $word (<$WORDS>) {
chomp $word;
my $arr = find_matches($word);
local $_;
# Schwartzian Transform
my @sorted_arr =
map { $_->[0] }
sort { $b->[1] <=> $a->[1] }
map {
[ $_, find_word_seq_score(@$_) ]
}
@$arr;
print_results($word, @sorted_arr);
}
close $WORDS;
}
}
sub find_matches($){
my($string) = @_;
my @found_parses;
my @words;
find_matches_rec($string, @words, @found_parses);
return @found_parses if wantarray;
return \@found_parses;
}
sub find_matches_rec($\@\@){
my($string, $words_sofar, $found_parses) = @_;
my $length = length $string;
unless($length){
push @$found_parses, $words_sofar;
return @$found_parses if wantarray;
return $found_parses;
}
foreach my $i (2..$length){
my $prefix = substr($string, 0, $i);
my $suffix = substr($string, $i, $length-$i);
if(exists $DICT{$prefix}){
my @words = (@$words_sofar, $prefix);
find_matches_rec($suffix, @words, @$found_parses);
}
}
return @$found_parses if wantarray;
return $found_parses;
}
## Just a simple joint probability
## assumes independence between words, which is obviously untrue
## that's why this is broken out -- feel free to add better brains
sub find_word_seq_score(@){
my(@words) = @_;
local $_;
my $score = 1;
foreach (@words){
$score = $score * $DICT{$_}/$TOTAL;
}
return $score;
}
sub get_word_stats($){
my ($filename) = @_;
open(my $DICT, '<', $filename) or die "unable to open $filename\n";
local $/= undef;
local $_;
my %dict;
my $total = 0;
while (<$DICT>){
foreach (split(/\b/, $_)) {
$dict{$_} += 1;
$total++;
}
}
close $DICT;
return (\%dict, $total);
}
sub print_results([email protected]){
#('word', [qw'test one'], [qw'test two'], ...)
my ($word, @combos) = @_;
local $_;
my $possible = scalar @combos;
print "$word: $possible possibilities\n";
foreach (@combos) {
print ' - ', join(' ', @$_), "\n";
}
print "\n";
}
sub Usage(){
return "$0 /path/to/dictionary /path/to/your_words";
}
순진한 구현은 "위크 에디 날씨" –
안녕하세요 최적의 솔루션을 반환합니다, 나는 EMR 질문에 대한 귀하의 답변을보고 건강 관리 IT에 관한 몇 가지 질문으로 연락 할 수 있을지 궁금해 한 점에 유의하십시오. –