- 论坛徽章:
- 5
|
一个思路 ( 没有 充分考虑 细节 及 效能 ):
请自行捉摸, 捉摸 ~ {:2_179:}- CHECK: [ Egypt|the|capital ]
- Egypt 埃及 = ok
- capital 首都 = ok
- CHECK: [ Tripoli|Tripoli ]
- Tripoli 的里波里 = ok
- Tripoli 的里波里 = ok
- CHECK: [ after|their|airport ]
- airport 机场 = ok
- CHECK: [ where|militias|week ]
- FAIL !! check next sentence
- militias 民兵 = ok
- week 星期 = ok
- ========================
- match @C[ 0 .. 1 ]
- ------------------------
- Egypt's state media is also reporting the deaths of 23 Egyptians in the Libyan capital, Tripoli, after a rocket hit their home near the airport, where deadly fighting between rival militias is entering a third week.
- 埃及国家电台也报道说,有23名埃及人在利比亚首都的里波里丧生,此前一枚火箭弹击中了这些埃及人在机场附近的住所。当地对立民兵组织之间的激战已经进入了第三个星期。
- ------------------------
- CHECK: [ Egypt|the|capital ]
- Egypt 埃及 = ok
- capital 首都 = ok
- CHECK: [ Tripoli|Tripoli ]
- Tripoli 的里波里 = ok
- Tripoli 的里波里 = ok
- CHECK: [ after|their|airport ]
- airport 机场 = ok
- CHECK: [ where|militias|week ]
- FAIL !! check next sentence
- militias 民兵 = ok
- week 星期 = ok
- ========================
- match @C[ 2 .. 3 ]
- ------------------------
- Egypt's state media is also reporting the deaths of 23 Egyptians in the Libyan capital, Tripoli, after a rocket hit their home near the airport, where deadly fighting between rival militias is entering a third week.
- 埃及国家电台也报道说,有23名埃及人在利比亚首都的里波里丧生,此前一枚火箭弹击中了这些埃及人在机场附近的住所。当地对立民兵组织之间的激战已经进入了第三个星期。
- ------------------------
复制代码- #!/usr/bin/perl
- use 5.010;
- my %dic = qw[
- Egypt 埃及
- state 国家
- media 电台
- reporting 报道
- deaths 丧生
- Egyptians 埃及人
- Libyan 利比亚
- capital 首都
- Tripoli 的里波里
- rocket 火箭
- hit 击中
- home 住所
- near 附近
- airport 机场
- fighting 激战
- rival 对立
- militias 民兵
- entering 进入
- third 第三
- week 星期
- ];
- my @E = (
- q[Egypt's state media is also reporting the deaths of 23 Egyptians in the Libyan capital, Tripoli, after a rocket hit their home near the airport, where deadly fighting between rival militias is entering a third week.],
- q[Egypt's state media is also reporting the deaths of 23 Egyptians in the Libyan capital, Tripoli, after a rocket hit their home near the airport, where deadly fighting between rival militias is entering a third week.],
- );
- my @C = (
- q[埃及国家电台也报道说,有23名埃及人在利比亚首都的里波里丧生,此前一枚火箭弹击中了这些埃及人在机场附近的住所。],
- q[当地对立民兵组织之间的激战已经进入了第三个星期。],
- q[埃及国家电台也报道说,有23名埃及人在利比亚首都的里波里丧生,此前一枚火箭弹击中了这些埃及人在机场附近的住所。],
- q[当地对立民兵组织之间的激战已经进入了第三个星期。],
- );
- my $i = 0;
- for my $e (@E) {
- my $begin = $i;
- my @sentence = map { [/\w+/g] } split /,/, $e;
- for my $ws (@sentence) {
- my $index = $#{$ws} >= 3 ? [ 0, $#{$ws} / 2, -1 ] : [ 0, -1 ];
- my @word = @$ws[@$index];
- my $ok = 0;
- say "CHECK: [ ", join( '|', @word ) . ' ]';
- NEXT: for my $w (@word) {
- ++$ok and next unless exists $dic{$w};
- my $c = $dic{$w};
- if ( $C[$i] =~ /$c/ ) {
- say "$w\t$c = ok";
- $ok++;
- }
- }
- unless ( $ok > @word * 2 / 3 ) {
- say "FAIL !!\tcheck next sentence";
- ++$i and goto NEXT;
- }
- sleep 1;
- }
- say '=' x 24;
- say "match\t\@C[ $begin .. $i ]";
- say '-' x 24;
- say $e;
- say @C[ $begin .. $i++ ];
- say '-' x 24;
- }
复制代码 |
|