/[Search-Estraier]/trunk/Estraier.pm
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 /trunk/Estraier.pm

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

revision 14 by dpavlin, Wed Jan 4 21:51:01 2006 UTC revision 15 by dpavlin, Wed Jan 4 22:24:57 2006 UTC
# Line 4  use 5.008; Line 4  use 5.008;
4  use strict;  use strict;
5  use warnings;  use warnings;
6    
 require Exporter;  
   
 our @ISA = qw(Exporter);  
   
 our %EXPORT_TAGS = ( 'all' => [ qw(  
 ) ] );  
   
 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );  
   
 our @EXPORT = qw(  
 );  
   
7  our $VERSION = '0.00';  our $VERSION = '0.00';
8    
 use Carp;  
   
9  =head1 NAME  =head1 NAME
10    
11  Search::Estraier - pure perl module to use Hyper Estraier search engine  Search::Estraier - pure perl module to use Hyper Estraier search engine
# Line 41  implementation. It also includes methods Line 27  implementation. It also includes methods
27    
28  =cut  =cut
29    
30    =head2 _s
31    
32    Remove multiple whitespaces from string, as well as whitespaces at beginning or end
33    
34     my $text = $self->_s(" this  is a text  ");
35     $text = 'this is a text';
36    
37    =cut
38    
39    sub _s {
40            my $text = $_[1] || return;
41            $text =~ s/\s\s+/ /gs;
42            $text =~ s/^\s+//;
43            $text =~ s/\s+$//;
44            return $text;
45    }
46    
47  package Search::Estraier::Document;  package Search::Estraier::Document;
48    
49  use Carp qw/croak confess/;  use Carp qw/croak confess/;
50    
51    use Search::Estraier;
52    our @ISA = qw/Search::Estraier/;
53    
54  =head1 Search::Estraier::Document  =head1 Search::Estraier::Document
55    
56  This class implements Document which is collection of attributes  This class implements Document which is collection of attributes
57  (key=value), vectors (also key value) display text and hidden text.  (key=value), vectors (also key value) display text and hidden text.
58    
 Document for HyperEstraier  
   
59  =head2 new  =head2 new
60    
61  Create new document, empty or from draft.  Create new document, empty or from draft.
# Line 128  sub add_attr { Line 132  sub add_attr {
132    
133          while (my ($name, $value) = each %{ $attrs }) {          while (my ($name, $value) = each %{ $attrs }) {
134                  if (! defined($value)) {                  if (! defined($value)) {
135                          delete( $self->{attrs}->{_s($name)} );                          delete( $self->{attrs}->{ $self->_s($name) } );
136                  } else {                  } else {
137                          $self->{attrs}->{_s($name)} = _s($value);                          $self->{attrs}->{ $self->_s($name) } = $self->_s($value);
138                  }                  }
139          }          }
140    
# Line 151  sub add_text { Line 155  sub add_text {
155          my $text = shift;          my $text = shift;
156          return unless defined($text);          return unless defined($text);
157    
158          push @{ $self->{dtexts} }, _s($text);          push @{ $self->{dtexts} }, $self->_s($text);
159  }  }
160    
161    
# Line 168  sub add_hidden_text { Line 172  sub add_hidden_text {
172          my $text = shift;          my $text = shift;
173          return unless defined($text);          return unless defined($text);
174    
175          push @{ $self->{htexts} }, _s($text);          push @{ $self->{htexts} }, $self->_s($text);
176  }  }
177    
178  =head2 id  =head2 id
# Line 280  Empty document object Line 284  Empty document object
284    
285    $doc->delete;    $doc->delete;
286    
287    This function is addition to original Ruby API, and since it was included in C wrappers it's here as a
288    convinience. Document objects which go out of scope will be destroyed
289    automatically.
290    
291  =cut  =cut
292    
293  sub delete {  sub delete {
# Line 295  sub delete { Line 303  sub delete {
303  }  }
304    
305    
 =head2 _s  
306    
307  Remove multiple whitespaces from string, as well as whitespaces at beginning or end  package Search::Estraier::Condition;
308    
309   my $text = _s(" this  is a text  ");  use Search::Estraier;
310   $text = 'this is a text';  our @ISA = qw/Search::Estraier/;
311    
312    my $options = {
313            # check N-gram keys skipping by three
314            SURE => 1 << 0,
315            # check N-gram keys skipping by two
316            USUAL => 1 << 1,
317            # without TF-IDF tuning
318            FAST => 1 << 2,
319            # with the simplified phrase
320            AGITO => 1 << 3,
321            # check every N-gram key
322            NOIDF => 1 << 4,
323            # check N-gram keys skipping by one
324            SIMPLE => 1 << 10,
325    };
326    
327    =head1 Search::Estraier::Condition
328    
329    =head2 new
330    
331      my $cond = new Search::HyperEstraier::Condition;
332    
333  =cut  =cut
334    
335  sub _s {  sub new {
336          my $text = shift || return;          my $class = shift;
337          $text =~ s/\s\s+/ /gs;          my $self = {};
338          $text =~ s/^\s+//;          bless($self, $class);
         $text =~ s/\s+$//;  
         return $text;  
 }  
339    
340            $self ? return $self : return undef;
341    }
342    
343    
344  package Search::Estraier::Master;  package Search::Estraier::Master;
# Line 326  Controll node master. This requires user Line 353  Controll node master. This requires user
353    
354  {  {
355          package RequestAgent;          package RequestAgent;
356          @ISA = qw(LWP::UserAgent);          our @ISA = qw(LWP::UserAgent);
357    
358          sub new {          sub new {
359                  my $self = LWP::UserAgent::new(@_);                  my $self = LWP::UserAgent::new(@_);
# Line 387  Dobrica Pavlinusic, E<lt>dpavlin@rot13.o Line 414  Dobrica Pavlinusic, E<lt>dpavlin@rot13.o
414    
415  =head1 COPYRIGHT AND LICENSE  =head1 COPYRIGHT AND LICENSE
416    
417  Copyright (C) 2005 by Dobrica Pavlinusic  Copyright (C) 2005-2006 by Dobrica Pavlinusic
418    
419  This library is free software; you can redistribute it and/or modify  This library is free software; you can redistribute it and/or modify
420  it under the GPL v2 or later.  it under the GPL v2 or later.

Legend:
Removed from v.14  
changed lines
  Added in v.15

  ViewVC Help
Powered by ViewVC 1.1.26