/[local]/search/filters/default.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

Annotation of /search/filters/default.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.6 - (hide annotations)
Fri Oct 25 17:40:50 2002 UTC (16 years, 8 months ago) by dpavlin
Branch: MAIN
Changes since 1.5: +1 -1 lines
File MIME type: text/plain
fixed &

1 dpavlin 1.1 #!/usr/bin/perl
2    
3     #--------------------------------------------------------------------------
4     #
5     # Author: Dobrica Pavlinusic
6     # Creation Date: 2002-03-17
7    
8    
9     #--------------------------------------------------------------------------
10     #
11     # Description:
12     #
13     # This package implements the various filters for this database
14     #
15    
16     #--------------------------------------------------------------------------
17     #
18     # Pragmatic modules
19     #
20    
21     use strict;
22    
23    
24     #--------------------------------------------------------------------------
25     #
26     # Package definition
27     #
28    
29     package default;
30    
31    
32     #--------------------------------------------------------------------------
33     #
34     # Application Constants
35     #
36    
37     #--------------------------------------------------------------------------
38     #
39     # Function: DocumentParser()
40     #
41     # Purpose: This function serves as a document parser
42     #
43     # Called by: DocumentFilter(), SummaryFilter()
44     #
45     # Parameters: $Database Database name
46     # $DocumentID Document ID
47     # $ItemName Item name
48     # $MimeType Mime type
49     # $DocumentRaw Raw document text
50     #
51     # Global Variables:
52     #
53     # Returns: A hash table of the document fields
54     #
55     sub DocumentParser {
56    
57     my ($Database, $DocumentID, $ItemName, $MimeType, $DocumentRaw) = @_;
58    
59     my (%Document, @DocumentLines, $DocumentLine);
60     my ($FieldTag, $FieldData, $Separator);
61    
62     @DocumentLines = split(/\n/, $DocumentRaw);
63    
64     # Extract the document
65     foreach $DocumentLine ( @DocumentLines ) {
66     # check if this is a new field?
67     if ( $DocumentLine =~ /%(\S+)\s*(.*)/ ) {
68     $FieldTag = $1;
69     $FieldData = $2;
70     if ($default::Separator{$FieldTag}) {
71     $Separator = $default::Separator{$FieldTag};
72     } else {
73     $Separator = ";";
74     }
75     }
76     else {
77     $FieldData = $DocumentLine;
78     $Separator = "\n";
79     }
80    
81     if ( defined($Document{$FieldTag}) ) {
82     $Document{$FieldTag} .= $Separator . $FieldData;
83     }
84     else {
85     $Document{$FieldTag} = $FieldData;
86     }
87     }
88    
89     return (%Document);
90    
91     }
92    
93    
94     #--------------------------------------------------------------------------
95     #
96     # Function: DocumentFilter()
97     #
98     # Purpose: This function is the document filter
99     #
100     # Called by: external
101     #
102     # Parameters: $Database Database name
103     # $DocumentID Document ID
104     # $ItemName Item name
105     # $MimeType Mime type
106     # $DocumentRaw Raw document text
107     #
108     # Global Variables: %default::FieldNames, @default::FieldDisplayOrder
109     #
110     # Returns: The filtered document
111     #
112     sub DocumentFilter {
113    
114     my ($Database, $DocumentID, $ItemName, $MimeType, $DocumentRaw) = @_;
115    
116     my (%Document, $DocumentFinal, $FieldTag, $CommaFlag);
117     my ($SearchTerm, @Authors, $Author, @AuthorNames, $AuthorName, @Keywords, $Keyword, @OrderNumbers, $OrderNumber);
118    
119     if ( !defined($DocumentRaw) ) {
120     return (undef);
121     }
122    
123    
124     %Document = &DocumentParser($Database, $DocumentID, $ItemName, $MimeType, $DocumentRaw);
125    
126     $DocumentFinal = "<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=2 WIDTH=100%> \n";
127     # $DocumentFinal .= "<TR><TD COLSPAN=2 VALIGN=TOP ALIGN=CENTER><H3> $Document{'T'} </H3></TD></TR> \n";
128    
129     # Loop over each line in the document list
130     foreach $FieldTag ( @default::FieldDisplayOrder ) {
131 dpavlin 1.4
132     # print "-- $FieldTag = $Document{$FieldTag} --";
133 dpavlin 1.1
134     # Skip empty slots
135     if ( !(defined($Document{$FieldTag}) && ($Document{$FieldTag} ne "")) ) {
136     next;
137     }
138    
139    
140     # Print the row start
141     $DocumentFinal .= "<TR><TD VALIGN=TOP ALIGN=RIGHT BGCOLOR=\"#EEEEEE\" WIDTH=\"130\"> $default::FieldNames{$FieldTag}: </TD><TD VALIGN=TOP ALIGN=LEFT> ";
142    
143 dpavlin 1.3 sub html_enc {
144     my $tmp = $_[0];
145 dpavlin 1.6 $tmp =~ s/&/&amp;/g;
146 dpavlin 1.3 $tmp =~ s/</&lt;/g;
147     $tmp =~ s/>/&gt;/g;
148     # fix some tags
149     $tmp =~ s/&lt;br&gt;/<br>/gi;
150     return $tmp;
151     }
152    
153 dpavlin 1.5 # format URI
154     if ( $FieldTag eq "856" ) {
155     my $alt = $Document{$FieldTag};
156     if (length $alt > $default::max_display_url_len ) {
157     $alt = substr($alt,0,$default::max_display_url_len)."...";
158     }
159     $DocumentFinal .= "<A HREF=\"$Document{$FieldTag}\" TARGET=\"BlankWindow\">$alt</A>";
160 dpavlin 1.2
161 dpavlin 1.5 } else {
162     $DocumentFinal .= html_enc($Document{$FieldTag});
163 dpavlin 1.1 }
164    
165     $DocumentFinal .= "</TD></TR> \n";
166    
167     }
168    
169    
170     # List any external links we may have
171     if ( defined($Document{'G'}) ) {
172    
173     @OrderNumbers = split(/; /, $Document{'G'});
174    
175     $DocumentFinal .= "<TR><TD COLSPAN=2> <HR WIDTH=50%> </TD></TR>";
176     $DocumentFinal .= "<TR><TD VALIGN=TOP ALIGN=LEFT> <B> External Links: </B> </TD><TD VALIGN=TOP ALIGN=LEFT><UL>";
177    
178     foreach $OrderNumber ( @OrderNumbers ) {
179    
180     if ( $OrderNumber =~ /ISBN\s*(\S*)/ ) {
181     $OrderNumber = $1;
182     $OrderNumber =~ s/-//g;
183     $DocumentFinal .= "<LI><A HREF=\"http://www.amazon.com/exec/obidos/ASIN/$OrderNumber\" TARGET=\"BlankWindow\"> Get this book from Amazon.com </A></LI>";
184     $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>";
185     $DocumentFinal .= "<LI><A HREF=\"http://shop.barnesandnoble.com/bookSearch/isbnInquiry.asp?isbn=$OrderNumber\" TARGET=\"BlankWindow\"> Get this book from Barnes & Noble </A></LI>";
186     }
187     }
188    
189     $DocumentFinal .= "</UL></TD></TR>";
190     }
191    
192     $DocumentFinal .= "</TABLE> \n";
193    
194     return ($DocumentFinal);
195    
196     }
197    
198    
199    
200     #--------------------------------------------------------------------------
201     #
202     # Function: SummaryFilter()
203     #
204     # Purpose: This function is the summary filter
205     #
206     # Called by: external
207     #
208     # Parameters: $Database Database name
209     # $DocumentID Document ID
210     # $ItemName Item name
211     # $MimeType Mime type
212     # $DocumentRaw Raw document text
213     #
214     # Global Variables: none
215     #
216     # Returns: The filtered summary
217     #
218     sub SummaryFilter {
219    
220     my ($Database, $DocumentID, $ItemName, $MimeType, $DocumentRaw) = @_;
221    
222     my (%Document, $Summary);
223    
224    
225     if ( !defined($DocumentRaw) ) {
226     return (undef);
227     }
228    
229    
230     # Parse the document
231     %Document = &DocumentParser($Database, $DocumentID, $ItemName, $MimeType, $DocumentRaw);
232    
233    
234     # Select the abstract if available
235     if ( defined($Document{'X'}) ) {
236     $Summary = $Document{'X'};
237     }
238    
239     # Select the table of contents if available
240     elsif ( defined($Document{'Y'}) ) {
241     $Summary = $Document{'Y'};
242     }
243    
244     # Select the keywords if available
245     elsif ( defined($Document{'K'}) ) {
246     $Summary = $Document{'K'};
247     }
248    
249    
250     # Clean the summary text
251     if ( defined($Summary) ) {
252     # First clean up the text
253     if ( index($Summary, "\r\n") >= 0 ) {
254     $Summary =~ s/\r//gs;
255     }
256     elsif ( index($Summary, "\r") >= 0 ) {
257     $Summary =~ s/\r/\n/gs;
258     }
259     $Summary =~ s/\n/ /gs;
260     $Summary =~ s/\s+/ /gs;
261     $Summary = ucfirst($Summary);
262     }
263    
264     return ($Summary);
265    
266     }
267    
268    
269    
270     #--------------------------------------------------------------------------
271     #
272     # Function: RelevanceFeedbackFilter()
273     #
274     # Purpose: This function is the relevance feedback filter
275     #
276     # Called by: external
277     #
278     # Parameters: $Database Database name
279     # $DocumentID Document ID
280     # $ItemName Item name
281     # $MimeType Mime type
282     # $DocumentRaw Raw document text
283     #
284     # Global Variables: none
285     #
286     # Returns: The filtered relevance feedback
287     #
288     sub RelevanceFeedbackFilter {
289    
290     my ($Database, $DocumentID, $ItemName, $MimeType, $DocumentRaw) = @_;
291    
292     my (%Document, $RelevanceFeedback);
293    
294    
295     if ( !defined($DocumentRaw) ) {
296     return (undef);
297     }
298    
299    
300     # Parse the document
301     %Document = &DocumentParser($Database, $DocumentID, $ItemName, $MimeType, $DocumentRaw);
302    
303    
304     # Select the abstract if available
305     if ( defined($Document{'X'}) ) {
306     $RelevanceFeedback = $Document{'X'};
307     }
308    
309     # Select the table of contents if available
310     elsif ( defined($Document{'Y'}) ) {
311     $RelevanceFeedback = $Document{'Y'};
312     }
313    
314     # Select the keywords if available
315     elsif ( defined($Document{'K'}) ) {
316     $RelevanceFeedback = $Document{'K'};
317     }
318    
319     # Select the title if available
320     elsif ( defined($Document{'T'}) ) {
321     $RelevanceFeedback = $Document{'T'};
322     }
323    
324     # Select the author if available
325     elsif ( defined($Document{'A'}) ) {
326     $RelevanceFeedback = $Document{'A'};
327     }
328    
329     return ($RelevanceFeedback);
330    
331     }
332    
333    
334    
335     #--------------------------------------------------------------------------
336    
337     1;

  ViewVC Help
Powered by ViewVC 1.1.26