line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Lingua::Sindarin::Dictionary; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
18289
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
42
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
38
|
|
5
|
1
|
|
|
1
|
|
15
|
use v5.12; |
|
1
|
|
|
|
|
9
|
|
|
1
|
|
|
|
|
40
|
|
6
|
1
|
|
|
1
|
|
557
|
use utf8; |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
3
|
|
7
|
1
|
|
|
1
|
|
191
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use namespace::autoclean; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has 'dictionary' => ( |
13
|
|
|
|
|
|
|
is => 'rw', |
14
|
|
|
|
|
|
|
isa => 'ArrayRef', |
15
|
|
|
|
|
|
|
); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub BUILD { |
18
|
|
|
|
|
|
|
my $self = shift; |
19
|
|
|
|
|
|
|
my $opt = shift; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
my %opt = %{$opt}; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
if ( $opt{'dict'} eq 'sindarin-english' ) { |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
open( my $file, '<:encoding(UTF-8)', 'data/sindeng.txt' ); |
26
|
|
|
|
|
|
|
$self->dictionary(&parse_file($file)); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
} elsif ( $opt{'dict'} eq 'english-sindarin' ) { |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
open( my $file, '<:encoding(UTF-8)', 'data/engsind.txt' ); |
31
|
|
|
|
|
|
|
$self->dictionary(&parse_file($file)); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
} else { |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
warn "Unknown option"; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub parse_file { |
41
|
|
|
|
|
|
|
my $file = shift; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
my @map; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
while ( my $line = <$file> ) { |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
if ( $line =~ m/^(\w+)[,-]?:\s(.+)/ ) { |
48
|
|
|
|
|
|
|
push(@map, $line); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
return \@map; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub search { |
57
|
|
|
|
|
|
|
my $self = shift; |
58
|
|
|
|
|
|
|
chomp (my $word = shift); |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
my @map = @{$self->dictionary}; |
61
|
|
|
|
|
|
|
my $result = ''; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
for my $entry ( @map ) { |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
if ( $entry =~ m/^($word)[,-]?:\s(.+)/i ) { |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
$result .= $2."\n"; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
if ( $result eq "" ) { |
72
|
|
|
|
|
|
|
say "Word not found"; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
return $result; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
1; |