Debian Codegraph @

bin/tax2thesaurus

raw
1 #!/usr/bin/perl -s
2
3 use strict;
4 my @tab=(-1);
5 my @ant=("_top");
6 my $ind;
7 my $inda=0;
8
9 binmode(STDOUT,":utf8");
10 @ARGV = ("-") unless @ARGV;
11 for my $file (@ARGV){
12 open(F,$file) or die("cant open $file\n");
13 print "%enc utf8\n\n";
14 while(<F>){ chomp;
15 if(/%enc(oding)?\s+(latin1)/){next}
16 if(/%enc(oding)?\s+(utf8)/i) {binmode(F,":utf8");next}
17 my $termo;
18 next unless /\w/;
19 if(/^([ .-]*)(\S.*)/){
20 $termo = $2;
21 $ind = length($1);
22 ## print STDERR "Deb: $_($termo/$ind)\n";
23 if ($ind <= $inda) {
24 while(@tab and $ind <= $tab[-1]){ pop(@tab); pop(@ant);}
25 }
26 push (@tab,$ind);
27 push (@ant,$termo);
28 print "\n$termo\nBT ",$ant[-2] ||"?","\n#lev ", @ant -1,"\n";
29 $inda = $ind;
30 }
31 }
32 close F;
33 }
34
35
36 __END__
37
38 =head1 NAME
39
40 tax2thesaurus - indented taxonomy to thesaurus
41
42 =head1 SYNOPSIS
43
44 tax2thesaurus file.tax > file.the
45
46 =head1 DESCRIPTION
47
48 A top term C<_top> is added to the taxonomy.
49
50 =head2 example of the taxonomy format
51
52 science
53 physics
54 dynamics
55 math
56 algebra
57 trignometry
58 literature
59
60 =head2 Correspondent output
61
62 science
63 BT _top
64 #lev 1
65
66 physics
67 BT science
68 #lev 2
69
70 dynamics
71 BT physics
72 #lev 3
73
74 math
75 BT science
76 #lev 2
77
78 algebra
79 BT math
80 #lev 3
81
82 trignometry
83 BT math
84 #lev 3
85
86 literature
87 BT _top
88 #lev 1
89
90 =head1 AUTHOR
91
92 J.Joao Almeida, [email protected]
93
94 =head1 SEE ALSO
95
96 perl(1).
97
98 =cut
99
100 __END__
101
102 Geografia Política
103 América
104 América Central
105 Belize
106 Costa Rica
107 El Salvador
108 Guatemala
109 Honduras
110 Nicarágua
111 Panamá
112 América Do Norte
113 Canadá
114 Alberta
115