/[Semantic-Engine]/EPrints/search.cgi
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /EPrints/search.cgi

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3 by dpavlin, Fri Jun 29 09:21:11 2007 UTC revision 11 by dpavlin, Fri Jun 29 16:58:42 2007 UTC
# Line 15  use CGI; Line 15  use CGI;
15  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
16  use EPrints;  use EPrints;
17  use Cwd qw/abs_path/;  use Cwd qw/abs_path/;
18    use lib '/home/dpavlin/stem-hr/';
19    use StemHR;
20    
21    my $debug = 1;
22    
23  my $abs_path = abs_path( $0 );  my $abs_path = abs_path( $0 );
24  $abs_path =~ s!/[^/]*$!/!;  #!fix-vim  $abs_path =~ s!/[^/]*$!/!;  #!fix-vim
# Line 22  $abs_path =~ s!/[^/]*$!/!;  #!fix-vim Line 26  $abs_path =~ s!/[^/]*$!/!;  #!fix-vim
26  #############################################################  #############################################################
27  my $COLLECTION = 'EPrints';  my $COLLECTION = 'EPrints';
28  my ( @TERMS, @RESULTS );  my ( @TERMS, @RESULTS );
29  my ( $RESULTS_TO_DISPLAY, $TERMS_TO_DISPLAY ) = ( 10, 10 );  my ( $RESULTS_TO_DISPLAY, $TERMS_TO_DISPLAY ) = ( 20, 20 );
30  #############################################################  #############################################################
31    
32    
# Line 33  my $cgi = new CGI; Line 37  my $cgi = new CGI;
37  my $start = $cgi->param( 'start' ) || 0;  my $start = $cgi->param( 'start' ) || 0;
38  my $query = $cgi->param( 'query' ) || '';  my $query = $cgi->param( 'query' ) || '';
39  my $similar = $cgi->param( 'similar' ) || '';  my $similar = $cgi->param( 'similar' ) || '';
40    my $slogovi = $cgi->param( 'slogovi' );
41    my $stem = $cgi->param( 'stem' );
42    
43  my $charset='iso-8859-2';  my $charset='iso-8859-2';
44    
45    my $full_query = $query;
46    $full_query .= " " . EPrints::slogovi( $query ) if ($slogovi);
47    $full_query .= " " . StemHR->stem( $query ) if ($stem);
48    
49  ##############################  ##############################
50  #       Start the HTML output  #       Start the HTML output
# Line 54  print qq|<?xml version="1.0" encoding="$ Line 63  print qq|<?xml version="1.0" encoding="$
63      <p>      <p>
64        <input type="text" name="query" value="$query" />        <input type="text" name="query" value="$query" />
65        <input type="submit" />        <input type="submit" />
66              |, $cgi->checkbox( -name => 'stem' ), $cgi->checkbox( -name => 'slogovi' ), qq|
67      </p>\n|;      </p>\n|;
68    
69    
# Line 70  if( $query || $similar ) { Line 80  if( $query || $similar ) {
80    
81      my ($results, $terms);      my ($results, $terms);
82          if ( $query ) {          if ( $query ) {
83          ($results, $terms) = $semantic->semantic_search( $query );          ($results, $terms) = $semantic->semantic_search( $full_query );
84          } else {          } else {
85          ($results, $terms) = $semantic->find_similar( $similar );          ($results, $terms) = $semantic->find_similar( $similar );
86          }          }
87    
88  warn "results = ",dump( $results );  warn "results = ",dump( $results ) if $debug;
89  warn "terms = ",dump( $terms );  warn "terms = ",dump( $terms ) if $debug;
90                    
91          ##################################          ##################################
92          #       TERM BASED CALCULATIONS          #       TERM BASED CALCULATIONS
93          ##################################          ##################################
94          my @sorted_terms = sort { $terms->{$b} <=> $terms->{$a} } keys %$terms;          my @sorted_terms = sort { $terms->{$b} <=> $terms->{$a} } keys %$terms;
95          my @top_terms = splice( @sorted_terms, $start, $TERMS_TO_DISPLAY );          my @top_terms = splice( @sorted_terms, $start, $TERMS_TO_DISPLAY );
96            
97    warn "top_terms = ", dump( @top_terms ) if $debug;
98    
99            print "<p>Full query: $full_query</p>\n";
100          print "<p>Related Terms: ". ( join ", ", @top_terms ) ."</p>\n";          print "<p>Related Terms: ". ( join ", ", @top_terms ) ."</p>\n";
101          print "<hr />\n";          print "<hr />\n";
102    
# Line 97  warn "terms = ",dump( $terms ); Line 110  warn "terms = ",dump( $terms );
110      my @sorted_results = sort { $results->{$b} <=> $results->{$a} } keys %$results;      my @sorted_results = sort { $results->{$b} <=> $results->{$a} } keys %$results;
111          my @display_results = splice( @sorted_results, $start, $RESULTS_TO_DISPLAY );          my @display_results = splice( @sorted_results, $start, $RESULTS_TO_DISPLAY );
112                    
113  warn dump( @display_results );    warn "display results = ", dump( @display_results ) if $debug;
114                    
115          ##################################          ##################################
116          #       Access the storage engine to          #       Access the storage engine to
# Line 107  warn dump( @display_results ); Line 120  warn dump( @display_results );
120          print $semantic->paginate( "?query=$query;similar=$similar", $start, scalar keys %$results, $RESULTS_TO_DISPLAY);          print $semantic->paginate( "?query=$query;similar=$similar", $start, scalar keys %$results, $RESULTS_TO_DISPLAY);
121          foreach my $id ( @display_results ){          foreach my $id ( @display_results ){
122                  EPrints->id( $id );                  EPrints->id( $id );
123          print "<p>$i. <b>", EPrints->lookup( 'title' ), "</b> <em>", sprintf("%.2f",$results->{$id}), "</em> <a href=\"?similar=$id\">similar</a></p>\n";                  print "<p>$i. <b>", EPrints->lookup( 'title' ), "</b>";
124          print "<p>";                  print "| score: <em>", sprintf("%.2f",$results->{$id}), "</em> | id: $id | <a href=\"?similar=$id\">similar</a> | ";
125                    my ($type,$uri) = split(/;/, EPrints->lookup( 'fileinfo', 'archive' ));
126                    print qq|<a href="$uri">$type</a>|;
127                    print "</p>\n";
128                    print "<p>";
129  #               print $semantic->summarize($id);  #               print $semantic->summarize($id);
130                    print "</p><p>Keywords: ", EPrints->lookup('keywords'), "</p><p>";
131                  print "<small>", EPrints->lookup('abstract'), "</small>";                  print "<small>", EPrints->lookup('abstract'), "</small>";
132                  print "</p>\n";                  print "</p>\n";
133          $i++;                  $i++;
134          }          }
135    
136  }        }      

Legend:
Removed from v.3  
changed lines
  Added in v.11

  ViewVC Help
Powered by ViewVC 1.1.26