/usr/lib/perl5/KinoSearch1/Analysis/Stopalizer.pm is in libkinosearch1-perl 1.00-1build3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | package KinoSearch1::Analysis::Stopalizer;
use strict;
use warnings;
use KinoSearch1::Util::ToolSet;
use base qw( KinoSearch1::Analysis::Analyzer );
BEGIN {
__PACKAGE__->init_instance_vars(
# constructor params / members
stoplist => undef,
);
}
use Lingua::StopWords;
sub init_instance {
my $self = shift;
my $language = $self->{language} = lc( $self->{language} );
# verify a supplied stoplist
if ( defined $self->{stoplist} ) {
croak("stoplist must be a hashref")
unless reftype( $self->{stoplist} ) eq 'HASH';
}
else {
# create a stoplist if language was supplied
if ( $language =~ /^(?:da|de|en|es|fr|it|nl|no|pt|ru|sv)$/ ) {
$self->{stoplist} = Lingua::StopWords::getStopWords($language);
}
# No Finnish stoplist, though we have a stemmmer.
elsif ( $language eq 'fi' ) {
$self->{stoplist} = {};
}
else {
confess "Invalid language: '$language'";
}
}
}
1;
__END__
__XS__
MODULE = KinoSearch1 PACKAGE = KinoSearch1::Analysis::Stopalizer
SV*
analyze(self_hash, batch_sv)
HV *self_hash;
SV *batch_sv;
PREINIT:
TokenBatch *batch;
CODE:
Kino1_extract_struct( batch_sv, batch, TokenBatch*,
"KinoSearch1::Analysis::TokenBatch");
Kino1_Stopalizer_analyze(self_hash, batch);
SvREFCNT_inc(batch_sv);
RETVAL = batch_sv;
OUTPUT: RETVAL
__H__
#ifndef H_KINOSEARCH_ANALYSIS_STOPALIZER
#define H_KINOSEARCH_ANALYSIS_STOPALIZER 1
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include "KinoSearch1AnalysisToken.h"
#include "KinoSearch1AnalysisTokenBatch.h"
#include "KinoSearch1UtilVerifyArgs.h"
TokenBatch* Kino1_Stopalizer_analyze(HV*, TokenBatch*);
#endif /* include guard */
__C__
#include "KinoSearch1AnalysisStopalizer.h"
TokenBatch*
Kino1_Stopalizer_analyze(HV* self_hash, TokenBatch *batch) {
SV **sv_ptr;
HV *stoplist_hv;
Token *token;
sv_ptr = hv_fetch(self_hash, "stoplist", 8, 0);
if (sv_ptr == NULL)
Kino1_confess("no element 'stoplist'");
if (!SvROK(*sv_ptr))
Kino1_confess("not a hashref");
stoplist_hv = (HV*)SvRV(*sv_ptr);
Kino1_Verify_extract_arg(self_hash, "stoplist", 8);
while (Kino1_TokenBatch_next(batch)) {
token = batch->current;
if (hv_exists(stoplist_hv, token->text, token->len)) {
token->len = 0;
}
}
Kino1_TokenBatch_reset(batch);
return batch;
}
__POD__
=head1 NAME
KinoSearch1::Analysis::Stopalizer - suppress a "stoplist" of common words
=head1 SYNOPSIS
my $stopalizer = KinoSearch1::Analysis::Stopalizer->new(
language => 'fr',
);
my $polyanalyzer = KinoSearch1::Analysis::PolyAnalyzer->new(
analyzers => [ $lc_normalizer, $tokenizer, $stopalizer, $stemmer ],
);
=head1 DESCRIPTION
A "stoplist" is collection of "stopwords": words which are common enough to be
of little value when determining search results. For example, so many
documents in English contain "the", "if", and "maybe" that it may improve both
performance and relevance to block them.
# before
@token_texts = ('i', 'am', 'the', 'walrus');
# after
@token_texts = ('', '', '', 'walrus');
=head1 CONSTRUCTOR
=head2 new
my $stopalizer = KinoSearch1::Analysis::Stopalizer->new(
language => 'de',
);
# or...
my $stopalizer = KinoSearch1::Analysis::Stopalizer->new(
stoplist => \%stoplist,
);
new() takes two possible parameters, C<language> and C<stoplist>. If
C<stoplist> is supplied, it will be used, overriding the behavior indicated by
the value of C<language>.
=over
=item
B<stoplist> - must be a hashref, with stopwords as the keys of the hash and
values set to 1.
=item
B<language> - must be the ISO code for a language. Loads a default stoplist
supplied by L<Lingua::StopWords|Lingua::StopWords>.
=back
=head1 SEE ALSO
L<Lingua::StopWords|Lingua::StopWords>
=head1 COPYRIGHT
Copyright 2005-2010 Marvin Humphrey
=head1 LICENSE, DISCLAIMER, BUGS, etc.
See L<KinoSearch1> version 1.00.
=cut
|