--- trunk/Estraier.pm 2006/01/04 21:51:01 14 +++ trunk/Estraier.pm 2006/01/04 22:24:57 15 @@ -4,22 +4,8 @@ use strict; use warnings; -require Exporter; - -our @ISA = qw(Exporter); - -our %EXPORT_TAGS = ( 'all' => [ qw( -) ] ); - -our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); - -our @EXPORT = qw( -); - our $VERSION = '0.00'; -use Carp; - =head1 NAME Search::Estraier - pure perl module to use Hyper Estraier search engine @@ -41,17 +27,35 @@ =cut +=head2 _s + +Remove multiple whitespaces from string, as well as whitespaces at beginning or end + + my $text = $self->_s(" this is a text "); + $text = 'this is a text'; + +=cut + +sub _s { + my $text = $_[1] || return; + $text =~ s/\s\s+/ /gs; + $text =~ s/^\s+//; + $text =~ s/\s+$//; + return $text; +} + package Search::Estraier::Document; use Carp qw/croak confess/; +use Search::Estraier; +our @ISA = qw/Search::Estraier/; + =head1 Search::Estraier::Document This class implements Document which is collection of attributes (key=value), vectors (also key value) display text and hidden text. -Document for HyperEstraier - =head2 new Create new document, empty or from draft. @@ -128,9 +132,9 @@ while (my ($name, $value) = each %{ $attrs }) { if (! defined($value)) { - delete( $self->{attrs}->{_s($name)} ); + delete( $self->{attrs}->{ $self->_s($name) } ); } else { - $self->{attrs}->{_s($name)} = _s($value); + $self->{attrs}->{ $self->_s($name) } = $self->_s($value); } } @@ -151,7 +155,7 @@ my $text = shift; return unless defined($text); - push @{ $self->{dtexts} }, _s($text); + push @{ $self->{dtexts} }, $self->_s($text); } @@ -168,7 +172,7 @@ my $text = shift; return unless defined($text); - push @{ $self->{htexts} }, _s($text); + push @{ $self->{htexts} }, $self->_s($text); } =head2 id @@ -280,6 +284,10 @@ $doc->delete; +This function is addition to original Ruby API, and since it was included in C wrappers it's here as a +convinience. Document objects which go out of scope will be destroyed +automatically. + =cut sub delete { @@ -295,23 +303,42 @@ } -=head2 _s -Remove multiple whitespaces from string, as well as whitespaces at beginning or end +package Search::Estraier::Condition; - my $text = _s(" this is a text "); - $text = 'this is a text'; +use Search::Estraier; +our @ISA = qw/Search::Estraier/; + +my $options = { + # check N-gram keys skipping by three + SURE => 1 << 0, + # check N-gram keys skipping by two + USUAL => 1 << 1, + # without TF-IDF tuning + FAST => 1 << 2, + # with the simplified phrase + AGITO => 1 << 3, + # check every N-gram key + NOIDF => 1 << 4, + # check N-gram keys skipping by one + SIMPLE => 1 << 10, +}; + +=head1 Search::Estraier::Condition + +=head2 new + + my $cond = new Search::HyperEstraier::Condition; =cut -sub _s { - my $text = shift || return; - $text =~ s/\s\s+/ /gs; - $text =~ s/^\s+//; - $text =~ s/\s+$//; - return $text; -} +sub new { + my $class = shift; + my $self = {}; + bless($self, $class); + $self ? return $self : return undef; +} package Search::Estraier::Master; @@ -326,7 +353,7 @@ { package RequestAgent; - @ISA = qw(LWP::UserAgent); + our @ISA = qw(LWP::UserAgent); sub new { my $self = LWP::UserAgent::new(@_); @@ -387,7 +414,7 @@ =head1 COPYRIGHT AND LICENSE -Copyright (C) 2005 by Dobrica Pavlinusic +Copyright (C) 2005-2006 by Dobrica Pavlinusic This library is free software; you can redistribute it and/or modify it under the GPL v2 or later.