/[webpac-proto]/search/filters/hci-bib.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /search/filters/hci-bib.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.1.1 - (show annotations) (vendor branch)
Thu May 18 13:10:43 2000 UTC (23 years, 10 months ago) by dpavlin
Branch: DbP, MAIN
CVS Tags: r0, HEAD
Changes since 1.1: +0 -0 lines
File MIME type: text/plain
initial import

1 #!/usr/bin/perl
2
3 #*****************************************************************************
4 # Copyright (C) 1993-2000, FS Consulting Inc. All rights reserved *
5 # *
6 # *
7 # This notice is intended as a precaution against inadvertent publication *
8 # and does not constitute an admission or acknowledgement that publication *
9 # has occurred or constitute a waiver of confidentiality. *
10 # *
11 # This software is the proprietary and confidential property *
12 # of FS Consulting, Inc. *
13 #*****************************************************************************
14
15 #--------------------------------------------------------------------------
16 #
17 # Author: Francois Schiettecatte (FS Consulting, Inc.)
18 # Creation Date: 3/17/1999
19
20
21 #--------------------------------------------------------------------------
22 #
23 # Description:
24 #
25 # This package implements the various filters for this database
26 #
27
28 #--------------------------------------------------------------------------
29 #
30 # Pragmatic modules
31 #
32
33 use strict;
34
35
36 #--------------------------------------------------------------------------
37 #
38 # Package definition
39 #
40
41 package hci_bib;
42
43
44 #--------------------------------------------------------------------------
45 #
46 # Application Constants
47 #
48
49 # Field Names
50 %hci_bib::FieldNames = (
51 'A', 'Author(s)',
52 'B', 'Book',
53 'C', 'City',
54 'D', 'Date',
55 'E', 'Editor',
56 'F', 'Footnote',
57 'G', 'Order Info',
58 'H', 'Commentary',
59 'I', 'Publisher',
60 'J', 'Journal',
61 'K', 'Keyword',
62 'L', 'Label',
63 'M', 'Bell',
64 'N', 'Issue',
65 'O', 'Other',
66 'P', 'Page',
67 'Q', 'Corporate',
68 'R', 'Report',
69 'S', 'Series',
70 'T', 'Title',
71 'U', 'Annotation',
72 'V', 'Volume',
73 'W', 'URL',
74 'X', 'Abstract',
75 'Y', 'Table of Contents',
76 'Z', 'Reference',
77 '$', 'Price',
78 '*', 'Copyright',
79 '^', 'Parts',
80 );
81
82
83
84 # Field Display Order
85 @hci_bib::FieldDisplayOrder = (
86 'M',
87 'L',
88 'T',
89 'S',
90 'E',
91 'Q',
92 'A',
93 'J',
94 'B',
95 'D',
96 'V',
97 'N',
98 'P',
99 'C',
100 'I',
101 'G',
102 '$',
103 'K',
104 '*',
105 'W',
106 'O',
107 'Y',
108 'X',
109 'R',
110 '.',
111 'F',
112 'H',
113 'U',
114 'Z',
115 '^'
116 );
117
118
119 #--------------------------------------------------------------------------
120 #
121 # Function: DocumentParser()
122 #
123 # Purpose: This function serves as a document parser
124 #
125 # Called by: DocumentFilter(), SummaryFilter()
126 #
127 # Parameters: $Database Database name
128 # $DocumentID Document ID
129 # $ItemName Item name
130 # $MimeType Mime type
131 # $DocumentRaw Raw document text
132 #
133 # Global Variables:
134 #
135 # Returns: A hash table of the document fields
136 #
137 sub DocumentParser {
138
139 my ($Database, $DocumentID, $ItemName, $MimeType, $DocumentRaw) = @_;
140
141 my (%Document, @DocumentLines, $DocumentLine);
142 my ($FieldTag, $FieldData, $Separator);
143
144 @DocumentLines = split(/\n/, $DocumentRaw);
145
146 # Extract the document
147 foreach $DocumentLine ( @DocumentLines ) {
148
149 # check if this is a new field?
150 if ( $DocumentLine =~ /%(.)\s*(.*)/ ) {
151 $FieldTag = $1;
152 $FieldData = $2;
153 $Separator = ";";
154 }
155 else {
156 $FieldData = $DocumentLine;
157 $Separator = "\n";
158 }
159
160 if ( defined($Document{$FieldTag}) ) {
161 $Document{$FieldTag} .= $Separator . $FieldData;
162 }
163 else {
164 $Document{$FieldTag} = $FieldData;
165 }
166 }
167
168 return (%Document);
169
170 }
171
172
173 #--------------------------------------------------------------------------
174 #
175 # Function: DocumentFilter()
176 #
177 # Purpose: This function is the document filter
178 #
179 # Called by: external
180 #
181 # Parameters: $Database Database name
182 # $DocumentID Document ID
183 # $ItemName Item name
184 # $MimeType Mime type
185 # $DocumentRaw Raw document text
186 #
187 # Global Variables: %hci_bib::FieldNames, @hci_bib::FieldDisplayOrder
188 #
189 # Returns: The filtered document
190 #
191 sub DocumentFilter {
192
193 my ($Database, $DocumentID, $ItemName, $MimeType, $DocumentRaw) = @_;
194
195 my (%Document, $DocumentFinal, $FieldTag, $CommaFlag);
196 my ($SearchTerm, @Authors, $Author, @AuthorNames, $AuthorName, @Keywords, $Keyword, @OrderNumbers, $OrderNumber);
197
198 if ( !defined($DocumentRaw) ) {
199 return (undef);
200 }
201
202
203 %Document = &DocumentParser($Database, $DocumentID, $ItemName, $MimeType, $DocumentRaw);
204
205 $DocumentFinal = "<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=2 WIDTH=100%> \n";
206 # $DocumentFinal .= "<TR><TD COLSPAN=2 VALIGN=TOP ALIGN=CENTER><H3> $Document{'T'} </H3></TD></TR> \n";
207
208
209 # Loop over each line in the document list
210 foreach $FieldTag ( @hci_bib::FieldDisplayOrder ) {
211
212 # Skip empty slots
213 if ( !(defined($Document{$FieldTag}) && ($Document{$FieldTag} ne "")) ) {
214 next;
215 }
216
217
218 # Print the row start
219 $DocumentFinal .= "<TR><TD VALIGN=TOP ALIGN=RIGHT BGCOLOR=\"#EEEEEE\" WIDTH=1%> $hci_bib::FieldNames{$FieldTag}: </TD><TD VALIGN=TOP ALIGN=LEFT> ";
220
221
222 # Print the field data, marking up if needed
223 if ( $FieldTag eq "A" ) {
224 $CommaFlag = 0;
225 @Authors = split(/;/, $Document{$FieldTag});
226 foreach $Author ( @Authors ) {
227 if ( $CommaFlag ) {
228 $DocumentFinal .= ", ";
229 }
230 $CommaFlag = 1;
231 $SearchTerm = $Author;
232 $SearchTerm =~ s/,//g;
233 @AuthorNames = split(/ /, $SearchTerm);
234 $SearchTerm = "";
235 foreach $AuthorName ( @AuthorNames ) {
236 if ( ! ($AuthorName =~ /^\w+\.$/) ) {
237 if ( $AuthorName ne "" ) {
238 $AuthorName .= " ";
239 }
240 $SearchTerm .= $AuthorName;
241 }
242 }
243 $SearchTerm =~ s/ /+/g;
244 $DocumentFinal .= "<A HREF=\"$ENV{'SCRIPT_NAME'}/GetSearchResults?Database=hci-bib&FieldName1=author&FieldContent1=%22$SearchTerm%22\"> $Author </A>";
245 }
246 }
247 elsif ( $FieldTag eq "K" ) {
248 $CommaFlag = 0;
249 @Keywords = split(/,/, $Document{$FieldTag});
250 foreach $Keyword ( @Keywords ) {
251 if ( $CommaFlag ) {
252 $DocumentFinal .= ", ";
253 }
254 $CommaFlag = 1;
255 $SearchTerm = $Keyword;
256 $SearchTerm =~ s/ /+/g;
257 $DocumentFinal .= "<A HREF=\"$ENV{'SCRIPT_NAME'}/GetSearchResults?Database=hci-bib&FieldName1=keyword&FieldContent1=%22$SearchTerm%22\"> $Keyword </A>";
258 }
259 }
260 elsif ( $FieldTag eq "W" ) {
261 $DocumentFinal .= "<A HREF=\"$Document{$FieldTag}\" TARGET=\"BlankWindow\"> $Document{$FieldTag} </A>";
262 }
263 elsif ( $FieldTag eq "Y" ) {
264 $DocumentFinal .= "<PRE>$Document{$FieldTag}</PRE>";
265 }
266 else {
267 $DocumentFinal .= "$Document{$FieldTag}";
268 }
269
270 $DocumentFinal .= "</TD></TR> \n";
271
272 }
273
274
275 # List any external links we may have
276 if ( defined($Document{'G'}) ) {
277
278 @OrderNumbers = split(/; /, $Document{'G'});
279
280 $DocumentFinal .= "<TR><TD COLSPAN=2> <HR WIDTH=50%> </TD></TR>";
281 $DocumentFinal .= "<TR><TD VALIGN=TOP ALIGN=LEFT> <B> External Links: </B> </TD><TD VALIGN=TOP ALIGN=LEFT><UL>";
282
283 foreach $OrderNumber ( @OrderNumbers ) {
284
285 if ( $OrderNumber =~ /ISBN\s*(\S*)/ ) {
286 $OrderNumber = $1;
287 $OrderNumber =~ s/-//g;
288 $DocumentFinal .= "<LI><A HREF=\"http://www.amazon.com/exec/obidos/ASIN/$OrderNumber\" TARGET=\"BlankWindow\"> Get this book from Amazon.com </A></LI>";
289 $DocumentFinal .= "<LI><A HREF=\"http://search.borders.com/fcgi-bin/db2www/search/search.d2w/Details?mediaType=Book&searchType=ISBNUPC&code=$OrderNumber\" TARGET=\"BlankWindow\"> Get this book from Borders </A></LI>";
290 $DocumentFinal .= "<LI><A HREF=\"http://shop.barnesandnoble.com/bookSearch/isbnInquiry.asp?isbn=$OrderNumber\" TARGET=\"BlankWindow\"> Get this book from Barnes & Noble </A></LI>";
291 }
292 }
293
294 $DocumentFinal .= "</UL></TD></TR>";
295 }
296
297 $DocumentFinal .= "</TABLE> \n";
298
299 return ($DocumentFinal);
300
301 }
302
303
304
305 #--------------------------------------------------------------------------
306 #
307 # Function: SummaryFilter()
308 #
309 # Purpose: This function is the summary filter
310 #
311 # Called by: external
312 #
313 # Parameters: $Database Database name
314 # $DocumentID Document ID
315 # $ItemName Item name
316 # $MimeType Mime type
317 # $DocumentRaw Raw document text
318 #
319 # Global Variables: none
320 #
321 # Returns: The filtered summary
322 #
323 sub SummaryFilter {
324
325 my ($Database, $DocumentID, $ItemName, $MimeType, $DocumentRaw) = @_;
326
327 my (%Document, $Summary);
328
329
330 if ( !defined($DocumentRaw) ) {
331 return (undef);
332 }
333
334
335 # Parse the document
336 %Document = &DocumentParser($Database, $DocumentID, $ItemName, $MimeType, $DocumentRaw);
337
338
339 # Select the abstract if available
340 if ( defined($Document{'X'}) ) {
341 $Summary = $Document{'X'};
342 }
343
344 # Select the table of contents if available
345 elsif ( defined($Document{'Y'}) ) {
346 $Summary = $Document{'Y'};
347 }
348
349 # Select the keywords if available
350 elsif ( defined($Document{'K'}) ) {
351 $Summary = $Document{'K'};
352 }
353
354
355 # Clean the summary text
356 if ( defined($Summary) ) {
357 # First clean up the text
358 if ( index($Summary, "\r\n") >= 0 ) {
359 $Summary =~ s/\r//gs;
360 }
361 elsif ( index($Summary, "\r") >= 0 ) {
362 $Summary =~ s/\r/\n/gs;
363 }
364 $Summary =~ s/\n/ /gs;
365 $Summary =~ s/\s+/ /gs;
366 $Summary = ucfirst($Summary);
367 }
368
369 return ($Summary);
370
371 }
372
373
374
375 #--------------------------------------------------------------------------
376 #
377 # Function: RelevanceFeedbackFilter()
378 #
379 # Purpose: This function is the relevance feedback filter
380 #
381 # Called by: external
382 #
383 # Parameters: $Database Database name
384 # $DocumentID Document ID
385 # $ItemName Item name
386 # $MimeType Mime type
387 # $DocumentRaw Raw document text
388 #
389 # Global Variables: none
390 #
391 # Returns: The filtered relevance feedback
392 #
393 sub RelevanceFeedbackFilter {
394
395 my ($Database, $DocumentID, $ItemName, $MimeType, $DocumentRaw) = @_;
396
397 my (%Document, $RelevanceFeedback);
398
399
400 if ( !defined($DocumentRaw) ) {
401 return (undef);
402 }
403
404
405 # Parse the document
406 %Document = &DocumentParser($Database, $DocumentID, $ItemName, $MimeType, $DocumentRaw);
407
408
409 # Select the abstract if available
410 if ( defined($Document{'X'}) ) {
411 $RelevanceFeedback = $Document{'X'};
412 }
413
414 # Select the table of contents if available
415 elsif ( defined($Document{'Y'}) ) {
416 $RelevanceFeedback = $Document{'Y'};
417 }
418
419 # Select the keywords if available
420 elsif ( defined($Document{'K'}) ) {
421 $RelevanceFeedback = $Document{'K'};
422 }
423
424 # Select the title if available
425 elsif ( defined($Document{'T'}) ) {
426 $RelevanceFeedback = $Document{'T'};
427 }
428
429 # Select the author if available
430 elsif ( defined($Document{'A'}) ) {
431 $RelevanceFeedback = $Document{'A'};
432 }
433
434 return ($RelevanceFeedback);
435
436 }
437
438
439
440 #--------------------------------------------------------------------------
441
442 1;

  ViewVC Help
Powered by ViewVC 1.1.26