1 |
dpavlin |
1.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 jfif; |
42 |
|
|
|
43 |
|
|
|
44 |
|
|
#-------------------------------------------------------------------------- |
45 |
|
|
# |
46 |
|
|
# Application Constants |
47 |
|
|
# |
48 |
|
|
|
49 |
|
|
# Field Names |
50 |
|
|
%jfif::FieldNames = ( |
51 |
|
|
'Title', 'Title', |
52 |
|
|
'Text', 'Text', |
53 |
|
|
); |
54 |
|
|
|
55 |
|
|
# Field Display Order |
56 |
|
|
@jfif::FieldDisplayOrder = ( |
57 |
|
|
'Title', |
58 |
|
|
'Text' |
59 |
|
|
); |
60 |
|
|
|
61 |
|
|
|
62 |
|
|
|
63 |
|
|
#-------------------------------------------------------------------------- |
64 |
|
|
# |
65 |
|
|
# Function: DocumentParser() |
66 |
|
|
# |
67 |
|
|
# Purpose: This function serves as a document parser |
68 |
|
|
# |
69 |
|
|
# Called by: DocumentFilter(), SummaryFilter() |
70 |
|
|
# |
71 |
|
|
# Parameters: $Database Database name |
72 |
|
|
# $DocumentID Document ID |
73 |
|
|
# $ItemName Item name |
74 |
|
|
# $MimeType Mime type |
75 |
|
|
# $DocumentRaw Raw document text |
76 |
|
|
# |
77 |
|
|
# Global Variables: |
78 |
|
|
# |
79 |
|
|
# Returns: A hash table of the document fields |
80 |
|
|
# |
81 |
|
|
sub DocumentParser { |
82 |
|
|
|
83 |
|
|
my ($Database, $DocumentID, $ItemName, $MimeType, $DocumentRaw) = @_; |
84 |
|
|
|
85 |
|
|
my (%Document, @DocumentLines, $DocumentLine); |
86 |
|
|
|
87 |
|
|
@DocumentLines = split(/\n/, $DocumentRaw); |
88 |
|
|
|
89 |
|
|
# Extract the document |
90 |
|
|
foreach $DocumentLine ( @DocumentLines ) { |
91 |
|
|
|
92 |
|
|
if ( !defined($Document{'Title'}) ) { |
93 |
|
|
$Document{'Title'} = $DocumentLine; |
94 |
|
|
} |
95 |
|
|
else { |
96 |
|
|
if ( defined($Document{'Text'}) ) { |
97 |
|
|
$Document{'Text'} .= "\n" . $DocumentLine; |
98 |
|
|
} |
99 |
|
|
else { |
100 |
|
|
$Document{'Text'} = $DocumentLine; |
101 |
|
|
} |
102 |
|
|
} |
103 |
|
|
} |
104 |
|
|
|
105 |
|
|
return (%Document); |
106 |
|
|
|
107 |
|
|
} |
108 |
|
|
|
109 |
|
|
|
110 |
|
|
|
111 |
|
|
|
112 |
|
|
#-------------------------------------------------------------------------- |
113 |
|
|
# |
114 |
|
|
# Function: DocumentFilter() |
115 |
|
|
# |
116 |
|
|
# Purpose: This function is the document filter |
117 |
|
|
# |
118 |
|
|
# Called by: external |
119 |
|
|
# |
120 |
|
|
# Parameters: $Database Database name |
121 |
|
|
# $DocumentID Document ID |
122 |
|
|
# $ItemName Item name |
123 |
|
|
# $MimeType Mime type |
124 |
|
|
# $DocumentRaw Raw document text |
125 |
|
|
# |
126 |
|
|
# Global Variables: %jfif::FieldNames, @jfif::FieldDisplayOrder |
127 |
|
|
# |
128 |
|
|
# Returns: The filtered document |
129 |
|
|
# |
130 |
|
|
sub DocumentFilter { |
131 |
|
|
|
132 |
|
|
my ($Database, $DocumentID, $ItemName, $MimeType, $DocumentRaw) = @_; |
133 |
|
|
|
134 |
|
|
my (%Document, $DocumentFinal, $FieldTag); |
135 |
|
|
|
136 |
|
|
|
137 |
|
|
if ( !defined($DocumentRaw) ) { |
138 |
|
|
return (undef); |
139 |
|
|
} |
140 |
|
|
|
141 |
|
|
|
142 |
|
|
%Document = &DocumentParser($Database, $DocumentID, $ItemName, $MimeType, $DocumentRaw); |
143 |
|
|
|
144 |
|
|
|
145 |
|
|
# Outer table |
146 |
|
|
$DocumentFinal = "<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%> \n"; |
147 |
|
|
$DocumentFinal .= "<TR><TD VALIGN=TOP ALIGN=LEFT>\n"; |
148 |
|
|
|
149 |
|
|
# Inner table |
150 |
|
|
$DocumentFinal .= "<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=2 WIDTH=100%> \n"; |
151 |
|
|
|
152 |
|
|
# Loop over each line in the document list |
153 |
|
|
foreach $FieldTag ( @jfif::FieldDisplayOrder ) { |
154 |
|
|
|
155 |
|
|
# Skip empty slots |
156 |
|
|
if ( !(defined($Document{$FieldTag}) && ($Document{$FieldTag} ne "")) ) { |
157 |
|
|
next; |
158 |
|
|
} |
159 |
|
|
|
160 |
|
|
# Print the data |
161 |
|
|
$DocumentFinal .= "<TR><TD VALIGN=TOP ALIGN=RIGHT BGCOLOR=\"#EEEEEE\" WIDTH=1%> $jfif::FieldNames{$FieldTag}: </TD><TD VALIGN=TOP ALIGN=LEFT> $Document{$FieldTag} </TD></TR>\n"; |
162 |
|
|
} |
163 |
|
|
|
164 |
|
|
|
165 |
|
|
# Image links |
166 |
|
|
$DocumentFinal .= "<TR><TD VALIGN=TOP ALIGN=RIGHT BGCOLOR=\"#EEEEEE\" WIDTH=1%> Images: </TD><TD VALIGN=TOP ALIGN=LEFT>"; |
167 |
|
|
$DocumentFinal .= "<A HREF=\"$ENV{'SCRIPT_NAME'}/GetDocument?Database=$Database&DocumentID=$DocumentID&ItemName=image&MimeType=image/jpeg\"> JPEG Image </A><BR>\n"; |
168 |
|
|
$DocumentFinal .= "<A HREF=\"$ENV{'SCRIPT_NAME'}/GetDocument?Database=$Database&DocumentID=$DocumentID&ItemName=image&MimeType=image/gif\"> GIF Image </A><BR>\n"; |
169 |
|
|
$DocumentFinal .= "</TD></TR>\n"; |
170 |
|
|
|
171 |
|
|
# End of inner table |
172 |
|
|
$DocumentFinal .= "</TABLE> \n"; |
173 |
|
|
|
174 |
|
|
# Thumbnail |
175 |
|
|
$DocumentFinal .= "</TD><TD VALIGN=TOP ALIGN=LEFT> Thumbnail: <A HREF=\"$ENV{'SCRIPT_NAME'}/GetDocument?Database=$Database&DocumentID=$DocumentID&ItemName=image&MimeType=image/jpeg\"><BR>"; |
176 |
|
|
$DocumentFinal .= "<IMG SRC=\"$ENV{'SCRIPT_NAME'}/GetDocument?Database=$Database&DocumentID=$DocumentID&ItemName=thumbnail&MimeType=image/jpeg\"></A> </TD></TR>\n"; |
177 |
|
|
|
178 |
|
|
# End of outer table |
179 |
|
|
$DocumentFinal .= "</TABLE> \n"; |
180 |
|
|
|
181 |
|
|
return ($DocumentFinal); |
182 |
|
|
|
183 |
|
|
} |
184 |
|
|
|
185 |
|
|
|
186 |
|
|
|
187 |
|
|
#-------------------------------------------------------------------------- |
188 |
|
|
# |
189 |
|
|
# Function: SummaryFilter() |
190 |
|
|
# |
191 |
|
|
# Purpose: This function is the summary filter |
192 |
|
|
# |
193 |
|
|
# Called by: external |
194 |
|
|
# |
195 |
|
|
# Parameters: $Database Database name |
196 |
|
|
# $DocumentID Document ID |
197 |
|
|
# $ItemName Item name |
198 |
|
|
# $MimeType Mime type |
199 |
|
|
# $DocumentRaw Raw document text |
200 |
|
|
# |
201 |
|
|
# Global Variables: none |
202 |
|
|
# |
203 |
|
|
# Returns: The filtered summary |
204 |
|
|
# |
205 |
|
|
sub SummaryFilter { |
206 |
|
|
|
207 |
|
|
my ($Database, $DocumentID, $ItemName, $MimeType, $DocumentRaw) = @_; |
208 |
|
|
|
209 |
|
|
my (%Document, $Summary); |
210 |
|
|
|
211 |
|
|
|
212 |
|
|
if ( !defined($DocumentRaw) ) { |
213 |
|
|
return (undef); |
214 |
|
|
} |
215 |
|
|
|
216 |
|
|
|
217 |
|
|
# Parse the document |
218 |
|
|
%Document = &DocumentParser($Database, $DocumentID, $ItemName, $MimeType, $DocumentRaw); |
219 |
|
|
|
220 |
|
|
|
221 |
|
|
# Select the summary text |
222 |
|
|
$Summary = $Document{'Text'}; |
223 |
|
|
|
224 |
|
|
# Clean the summary text |
225 |
|
|
if ( defined($Summary) ) { |
226 |
|
|
# First clean up the text |
227 |
|
|
if ( index($Summary, "\r\n") >= 0 ) { |
228 |
|
|
$Summary =~ s/\r//gs; |
229 |
|
|
} |
230 |
|
|
elsif ( index($Summary, "\r") >= 0 ) { |
231 |
|
|
$Summary =~ s/\r/\n/gs; |
232 |
|
|
} |
233 |
|
|
$Summary =~ s/\n/ /gs; |
234 |
|
|
$Summary =~ s/\s+/ /gs; |
235 |
|
|
$Summary = ucfirst($Summary); |
236 |
|
|
} |
237 |
|
|
|
238 |
|
|
return ($Summary); |
239 |
|
|
|
240 |
|
|
} |
241 |
|
|
|
242 |
|
|
|
243 |
|
|
|
244 |
|
|
#-------------------------------------------------------------------------- |
245 |
|
|
# |
246 |
|
|
# Function: RelevanceFeedbackFilter() |
247 |
|
|
# |
248 |
|
|
# Purpose: This function is the relevance filter |
249 |
|
|
# |
250 |
|
|
# Called by: external |
251 |
|
|
# |
252 |
|
|
# Parameters: $Database Database name |
253 |
|
|
# $DocumentID Document ID |
254 |
|
|
# $ItemName Item name |
255 |
|
|
# $MimeType Mime type |
256 |
|
|
# $DocumentRaw Raw document text |
257 |
|
|
# |
258 |
|
|
# Global Variables: none |
259 |
|
|
# |
260 |
|
|
# Returns: The filtered relevance feedback |
261 |
|
|
# |
262 |
|
|
sub RelevanceFeedbackFilter { |
263 |
|
|
|
264 |
|
|
my ($Database, $DocumentID, $ItemName, $MimeType, $DocumentRaw) = @_; |
265 |
|
|
|
266 |
|
|
return (&SummaryFilter($DocumentRaw)); |
267 |
|
|
|
268 |
|
|
} |
269 |
|
|
|
270 |
|
|
|
271 |
|
|
|
272 |
|
|
#-------------------------------------------------------------------------- |
273 |
|
|
|
274 |
|
|
1; |