spln2016:diario4
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| spln2016:diario4 [2016/03/09 16:46] – created ambs | spln2016:diario4 [2016/03/09 16:51] (current) – ambs | ||
|---|---|---|---|
| Line 48: | Line 48: | ||
| - | ### Scripting | + | === Scripting |
| Começamos por criar um exemplo básico do uso da biblioteca Jspell dentro do perl. | Começamos por criar um exemplo básico do uso da biblioteca Jspell dentro do perl. | ||
| Line 54: | Line 54: | ||
| $ cat jspell.pl | $ cat jspell.pl | ||
| - | ```perl | ||
| - | # | ||
| - | | + | # |
| - | use strict; | + | |
| + | | ||
| + | use strict; | ||
| + | use Lingua:: | ||
| + | use Data:: | ||
| + | |||
| + | my $dic = Lingua:: | ||
| + | |||
| + | my @analysis = $dic -> fea(" | ||
| + | |||
| + | use Data:: | ||
| + | print Dumper(\@analysis); | ||
| - | use Lingua::Jspell; | + | Resultdo: |
| - | use Data:: | + | |
| - | + | ||
| - | my $dic = Lingua:: | + | |
| - | + | ||
| - | my @analysis = $dic -> fea(" | + | |
| - | + | ||
| - | use Data:: | + | |
| - | print Dumper(\@analysis); | + | |
| - | ``` | + | |
| $ perl jspell.pl | $ perl jspell.pl | ||
| - | ```perl | + | |
| - | $VAR1 = [ | + | |
| { | { | ||
| ' | ' | ||
| Line 98: | Line 97: | ||
| } | } | ||
| ]; | ]; | ||
| - | ``` | ||
| Agora que já conseguimos dar uso à biblioteca, vamos agora usá-la para descobrir os radicais das palavras no dicionário português e contar a frequência de cada radical. | Agora que já conseguimos dar uso à biblioteca, vamos agora usá-la para descobrir os radicais das palavras no dicionário português e contar a frequência de cada radical. | ||
| Line 104: | Line 102: | ||
| $ cat jspell2.pl | $ cat jspell2.pl | ||
| - | ```perl | ||
| - | # | ||
| - | use warnings; | ||
| - | use strict; | ||
| - | use Lingua:: | + | Contagem de lemas... |
| - | use Data:: | + | |
| - | use Memoize; | + | # |
| - | memoize(' | + | |
| - | + | use warnings; | |
| - | my $dic = Lingua:: | + | use strict; |
| - | + | ||
| - | my (%oco, $c); | + | use Lingua:: |
| - | + | use Data:: | |
| - | while (<>) { | + | |
| - | next if /^</; | + | |
| - | + | memoize(' | |
| - | while ( / | + | |
| + | my $dic = Lingua:: | ||
| + | my (%oco, $c); | ||
| + | |||
| + | while (<>) { | ||
| + | next if /^</; | ||
| + | | ||
| + | | ||
| + | my $word = $&; | ||
| | | ||
| - | my $word = $&; | + | |
| - | + | for my $rad (@rad) { | |
| - | | + | $oco{$rad}++; |
| - | for my $rad (@rad){ | + | } |
| - | $oco{$rad}++; | + | |
| } | } | ||
| + | } | ||
| + | |||
| + | for my $rad (sort { $oco{$b} <=> $oco{$a}} keys %oco){ | ||
| + | print " | ||
| + | } | ||
| + | |||
| + | sub radicais { | ||
| + | my $word = shift; | ||
| + | return $dic -> rad($word); | ||
| } | } | ||
| - | } | + | Resultado: |
| - | + | ||
| - | for my $rad (sort { $oco{$b} <=> $oco{$a}} keys %oco){ | + | |
| - | print " | + | |
| - | } | + | |
| - | + | ||
| - | sub radicais { | + | |
| - | my $word = shift; | + | |
| - | return $dic -> rad($word); | + | |
| - | } | + | |
| - | ``` | + | |
| $ perl jspell.pl | head | $ perl jspell.pl | head | ||
| - | + | | |
| o 121406 | o 121406 | ||
| de | de | ||
spln2016/diario4.1457542013.txt.gz · Last modified: 2016/03/09 16:46 by ambs