line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# ROADS Thesaurus Object |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# Author: jon@net.lut.ac.uk |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
# $Id: ISO.pm,v 1.4 1998/10/21 13:31:40 jon Exp jon $ |
7
|
|
|
|
|
|
|
# |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
package Text::Thesaurus::ISO; |
10
|
1
|
|
|
1
|
|
1548
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
42
|
|
11
|
1
|
|
|
1
|
|
7
|
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
2480
|
|
12
|
|
|
|
|
|
|
require Exporter; |
13
|
|
|
|
|
|
|
@ISA = qw(Exporter AutoLoader); |
14
|
|
|
|
|
|
|
$VERSION = "1.0"; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
my($debug) = 0; # turn debugging off normally |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# Constructor method |
19
|
|
|
|
|
|
|
sub new { |
20
|
0
|
|
|
0
|
1
|
|
my $this = shift; |
21
|
0
|
|
|
|
|
|
my $isofile = @_; |
22
|
0
|
|
0
|
|
|
|
my $class = ref($this) || $this; |
23
|
0
|
|
|
|
|
|
my $self = {}; |
24
|
0
|
|
|
|
|
|
bless $self, $class; |
25
|
|
|
|
|
|
|
|
26
|
0
|
0
|
|
|
|
|
if(defined($isofile)) { |
27
|
0
|
|
|
|
|
|
$self->open($isofile); |
28
|
|
|
|
|
|
|
} |
29
|
0
|
|
|
|
|
|
return $self; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# method to open a theasaurus |
33
|
|
|
|
|
|
|
sub open { |
34
|
0
|
|
|
0
|
1
|
|
my($self) = shift; |
35
|
0
|
|
|
|
|
|
my($isofile) = @_; |
36
|
|
|
|
|
|
|
|
37
|
0
|
0
|
|
|
|
|
if(!dbmopen(%{$$self{"termdbm"}} ,"$isofile.term",undef)) { |
|
0
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
$self->reopen($isofile); |
39
|
|
|
|
|
|
|
} else { |
40
|
0
|
0
|
|
|
|
|
CORE::open(THESFILE,$isofile) || return(undef); |
41
|
0
|
|
|
|
|
|
dbmopen(%{$$self{"broaddbm"}} ,"$isofile.broad",0666); |
|
0
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# method to reopen a theasaurus, rebuilding the database structures. |
46
|
|
|
|
|
|
|
sub reopen { |
47
|
0
|
|
|
0
|
1
|
|
my($self) = shift; |
48
|
0
|
|
|
|
|
|
my($isofile) = @_; |
49
|
0
|
|
|
|
|
|
my($first,$line,$term,@terms,$position,@broadterms,$mainterm); |
50
|
|
|
|
|
|
|
|
51
|
0
|
0
|
|
|
|
|
CORE::open(THESFILE,$isofile) || return(undef); |
52
|
0
|
|
|
|
|
|
dbmopen(%{$$self{"termdbm"}} ,"$isofile.term",0666); |
|
0
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
dbmopen(%{$$self{"broaddbm"}} ,"$isofile.broad",0666); |
|
0
|
|
|
|
|
|
|
54
|
0
|
0
|
|
|
|
|
warn "About to undef DBM files\n" if($debug); |
55
|
0
|
|
|
|
|
|
undef(%{$$self{"termdbm"}}); |
|
0
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
undef(%{$$self{"broaddbm"}}); |
|
0
|
|
|
|
|
|
|
57
|
0
|
0
|
|
|
|
|
warn "Done undef DBM files\n" if($debug); |
58
|
0
|
|
|
|
|
|
$first = 0; |
59
|
0
|
|
|
|
|
|
while($line = ) { |
60
|
0
|
|
|
|
|
|
$line =~ s/[\n\r]//g; |
61
|
0
|
0
|
|
|
|
|
if($line eq "\$\$") { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
62
|
0
|
0
|
|
|
|
|
if($first) { |
63
|
0
|
|
|
|
|
|
foreach $term (@terms) { |
64
|
0
|
|
|
|
|
|
$term=~s/^\s+//; |
65
|
0
|
|
|
|
|
|
$term=~s/\s+$//; |
66
|
0
|
0
|
|
|
|
|
warn "Adding $term to termdbm\n" if($debug); |
67
|
0
|
|
|
|
|
|
$$self{"termdbm"}->{"$term"} = $position; |
68
|
|
|
|
|
|
|
} |
69
|
0
|
|
|
|
|
|
foreach $term (@broadterms) { |
70
|
0
|
|
|
|
|
|
$term=~s/^\s+//; |
71
|
0
|
|
|
|
|
|
$term=~s/\s+$//; |
72
|
0
|
0
|
|
|
|
|
warn "Adding $term to broaddbm\n" if($debug); |
73
|
0
|
0
|
|
|
|
|
if(!defined($$self{"broaddbm"}->{"$term"})){ |
74
|
0
|
|
|
|
|
|
$$self{"broaddbm"}->{"$term"} = $mainterm; |
75
|
|
|
|
|
|
|
} else { |
76
|
0
|
|
|
|
|
|
$$self{"broaddbm"}->{"$term"} = |
77
|
|
|
|
|
|
|
$$self{"broaddbm"}->{"$term"}.",$mainterm"; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
} |
81
|
0
|
|
|
|
|
|
$first = 1; |
82
|
0
|
|
|
|
|
|
$position = tell THESFILE; |
83
|
0
|
0
|
|
|
|
|
warn "Position is now $position\n" if($debug); |
84
|
0
|
|
|
|
|
|
$mainterm = ""; |
85
|
0
|
|
|
|
|
|
@terms = (); |
86
|
0
|
|
|
|
|
|
@broadterms = (); |
87
|
|
|
|
|
|
|
} elsif ($line =~ /TERM\s+(.*)/) { |
88
|
0
|
|
|
|
|
|
push(@terms,$1); |
89
|
0
|
|
|
|
|
|
$mainterm = $1; |
90
|
|
|
|
|
|
|
} elsif ($line =~ /ALT\s+(.*)/) { |
91
|
0
|
|
|
|
|
|
my($alt) = $1; |
92
|
0
|
|
|
|
|
|
$alt =~ s/^\s*ALTERNATE:\s*//; |
93
|
0
|
|
|
|
|
|
push(@terms,$alt); |
94
|
|
|
|
|
|
|
} elsif ($line =~ /UKALT\s+(.*)/) { |
95
|
0
|
|
|
|
|
|
my($alt) = $1; |
96
|
0
|
|
|
|
|
|
$alt =~ s/^\s*UK ALTERNATE:\s*//g; |
97
|
0
|
|
|
|
|
|
push(@terms,$alt); |
98
|
|
|
|
|
|
|
} elsif ($line =~ /UK\s+(.*)/) { |
99
|
0
|
|
|
|
|
|
my($alt) = $1; |
100
|
0
|
|
|
|
|
|
$alt =~ s/^\s*UK:\s*//g; |
101
|
0
|
|
|
|
|
|
push(@terms,$alt); |
102
|
|
|
|
|
|
|
} elsif ($line =~ /UF\s+(.*)/) { |
103
|
0
|
|
|
|
|
|
push(@terms,$1); |
104
|
|
|
|
|
|
|
} elsif ($line =~ /BT\s+(.*)/) { |
105
|
0
|
|
|
|
|
|
push(@broadterms,$1); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
# method to get details of an input term |
111
|
|
|
|
|
|
|
sub terminfo { |
112
|
0
|
|
|
0
|
1
|
|
my($self) = shift; |
113
|
0
|
|
|
|
|
|
my($inputterm) = @_; |
114
|
0
|
|
|
|
|
|
my($position,$line); |
115
|
0
|
|
|
|
|
|
my(%thesaurusrecord); |
116
|
|
|
|
|
|
|
|
117
|
0
|
|
|
|
|
|
$position = $$self{"termdbm"}->{"$inputterm"}; |
118
|
0
|
0
|
|
|
|
|
warn "Position for term $inputterm is $position\n" if($debug); |
119
|
0
|
|
|
|
|
|
seek(THESFILE,$position,0); |
120
|
0
|
|
|
|
|
|
while($line = ) { |
121
|
0
|
|
|
|
|
|
$line =~ s/[\r\n]+$//; |
122
|
0
|
0
|
|
|
|
|
if($line =~ /^\$\$/) { |
123
|
0
|
|
|
|
|
|
last; |
124
|
|
|
|
|
|
|
} |
125
|
0
|
0
|
|
|
|
|
if ($line =~ /([a-zA-Z0-9]+)\s+(.*)/) { |
126
|
0
|
|
|
|
|
|
my($attrib) = $1; |
127
|
0
|
|
|
|
|
|
my($value) = $2; |
128
|
|
|
|
|
|
|
|
129
|
0
|
0
|
|
|
|
|
$value =~ s/^ALTERNATE:\s*// if($attrib eq "ALT"); |
130
|
0
|
0
|
|
|
|
|
$value =~ s/^SCOPE NOTE:\s*// if($attrib eq "SN"); |
131
|
0
|
0
|
|
|
|
|
$value =~ s/^UK ALTERNATE:\s*// if($attrib eq "UKALT"); |
132
|
0
|
0
|
|
|
|
|
if(!defined($thesaurusrecord{"$attrib"})) { |
133
|
0
|
|
|
|
|
|
$thesaurusrecord{"$attrib"} = $value; |
134
|
|
|
|
|
|
|
} else { |
135
|
0
|
|
|
|
|
|
my($old) = $thesaurusrecord{"$attrib"}; |
136
|
0
|
|
|
|
|
|
$thesaurusrecord{"$attrib"} = "$old\n$value"; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
0
|
|
|
|
|
|
return(%thesaurusrecord); |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
# method to get a list of broader terms from an input term |
146
|
|
|
|
|
|
|
sub broader { |
147
|
0
|
|
|
0
|
1
|
|
my($self) = shift; |
148
|
0
|
|
|
|
|
|
my($inputterm) = @_; |
149
|
0
|
|
|
|
|
|
my(%fullrecord); |
150
|
|
|
|
|
|
|
|
151
|
0
|
|
|
|
|
|
%fullrecord = $self->terminfo($inputterm); |
152
|
0
|
|
|
|
|
|
return(split("\n",$fullrecord{"BT"})); |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
# method to get a list of narrower terms from an input term |
156
|
|
|
|
|
|
|
sub narrower { |
157
|
0
|
|
|
0
|
1
|
|
my($self) = shift; |
158
|
0
|
|
|
|
|
|
my($inputterm) = @_; |
159
|
|
|
|
|
|
|
|
160
|
0
|
|
|
|
|
|
return(split(",",$$self{"broaddbm"}->{"$inputterm"})); |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
# method to return the date that the record was entered |
164
|
|
|
|
|
|
|
sub dateentered { |
165
|
0
|
|
|
0
|
1
|
|
my($self) = shift; |
166
|
0
|
|
|
|
|
|
my($inputterm) = @_; |
167
|
0
|
|
|
|
|
|
my(%record); |
168
|
|
|
|
|
|
|
|
169
|
0
|
|
|
|
|
|
%record = $self->terminfo($inputterm); |
170
|
0
|
0
|
|
|
|
|
if(defined($record{"DATENT"})) { |
171
|
0
|
|
|
|
|
|
return($record{"DATENT"}); |
172
|
|
|
|
|
|
|
} else { |
173
|
0
|
|
|
|
|
|
return(undef); |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
# method to return the date that the record was last changed |
178
|
|
|
|
|
|
|
sub datechanged { |
179
|
0
|
|
|
0
|
1
|
|
my($self) = shift; |
180
|
0
|
|
|
|
|
|
my($inputterm) = @_; |
181
|
0
|
|
|
|
|
|
my(%record); |
182
|
|
|
|
|
|
|
|
183
|
0
|
|
|
|
|
|
%record = $self->terminfo($inputterm); |
184
|
0
|
0
|
|
|
|
|
if(defined($record{"DATCHG"})) { |
185
|
0
|
|
|
|
|
|
return($record{"DATCHG"}); |
186
|
|
|
|
|
|
|
} else { |
187
|
0
|
|
|
|
|
|
return(undef); |
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
} |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
# method to get a list of alternatives terms from an input term |
192
|
|
|
|
|
|
|
sub alternatives { |
193
|
0
|
|
|
0
|
1
|
|
my($self) = shift; |
194
|
0
|
|
|
|
|
|
my($inputterm) = @_; |
195
|
0
|
|
|
|
|
|
my(%record); |
196
|
|
|
|
|
|
|
my(@alternatives); |
197
|
|
|
|
|
|
|
|
198
|
0
|
|
|
|
|
|
%record = $self->terminfo($inputterm); |
199
|
0
|
|
|
|
|
|
@alternatives = split("\n",$record{"TERM"}); |
200
|
0
|
|
|
|
|
|
push(@alternatives, split("\n",$record{"ALT"})); |
201
|
0
|
|
|
|
|
|
push(@alternatives, split("\n",$record{"UK"})); |
202
|
0
|
|
|
|
|
|
push(@alternatives, split("\n",$record{"UF"})); |
203
|
0
|
|
|
|
|
|
return(@alternatives); |
204
|
|
|
|
|
|
|
} |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
# method to return a list of source information statements |
207
|
|
|
|
|
|
|
sub sources { |
208
|
0
|
|
|
0
|
1
|
|
my($self) = shift; |
209
|
0
|
|
|
|
|
|
my($inputterm) = @_; |
210
|
0
|
|
|
|
|
|
my(%record); |
211
|
|
|
|
|
|
|
my(@sources); |
212
|
|
|
|
|
|
|
|
213
|
0
|
|
|
|
|
|
%record = $self->terminfo($inputterm); |
214
|
0
|
|
|
|
|
|
@sources = split("\n",$record{"SOURCE"}); |
215
|
0
|
|
|
|
|
|
return(@sources); |
216
|
|
|
|
|
|
|
} |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
# method to return a list of links to other terms |
219
|
|
|
|
|
|
|
sub links { |
220
|
0
|
|
|
0
|
1
|
|
my($self) = shift; |
221
|
0
|
|
|
|
|
|
my($inputterm) = @_; |
222
|
0
|
|
|
|
|
|
my(%record); |
223
|
|
|
|
|
|
|
my(@links); |
224
|
|
|
|
|
|
|
|
225
|
0
|
|
|
|
|
|
%record = $self->terminfo($inputterm); |
226
|
0
|
|
|
|
|
|
@links = split("\n",$record{"LINK"}); |
227
|
0
|
|
|
|
|
|
return(@links); |
228
|
|
|
|
|
|
|
} |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
# method to return the scope note, which usually describes the term in |
231
|
|
|
|
|
|
|
# natural language. |
232
|
|
|
|
|
|
|
sub scopenote { |
233
|
0
|
|
|
0
|
1
|
|
my($self) = shift; |
234
|
0
|
|
|
|
|
|
my($inputterm) = @_; |
235
|
0
|
|
|
|
|
|
my(%record); |
236
|
|
|
|
|
|
|
my(@sn); |
237
|
|
|
|
|
|
|
|
238
|
0
|
|
|
|
|
|
%record = $self->terminfo($inputterm); |
239
|
0
|
|
|
|
|
|
@sn = split("\n",$record{"SN"}); |
240
|
0
|
|
|
|
|
|
return(@sn); |
241
|
|
|
|
|
|
|
} |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
# method to return the history behind a term's entry in the thesaurus |
244
|
|
|
|
|
|
|
sub history { |
245
|
0
|
|
|
0
|
1
|
|
my($self) = shift; |
246
|
0
|
|
|
|
|
|
my($inputterm) = @_; |
247
|
0
|
|
|
|
|
|
my(%record); |
248
|
|
|
|
|
|
|
my(@sn); |
249
|
|
|
|
|
|
|
|
250
|
0
|
|
|
|
|
|
%record = $self->terminfo($inputterm); |
251
|
0
|
|
|
|
|
|
@sn = split("\n",$record{"HN"}); |
252
|
0
|
|
|
|
|
|
return(@sn); |
253
|
|
|
|
|
|
|
} |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
1; |
256
|
|
|
|
|
|
|
__END__ |