Text-Index
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/Text/Index.pm view on Meta::CPAN
$index->add_page($content);
$index->add_pages(@strings);
my @pages = $index->pages;
# Add keyword with equivalent derivates
$index->add_keyword('Hamilton function', 'Hamiltonian');
$index->add_keywords([$keyword, @derivates], ...);
my @keywords = $i->keywords;
# ->keywords returns an array reference for each keyword
# (see ->add_keywords syntax)
my $index = $i->generate_index;
# Or for a single keyword:
my @page_list = $i->find_keyword($keyword);
my @page_list2 = $i->find_keyword($keyword, @derivates);
=head1 DESCRIPTION
This (simple) module searches for keywords in a set of pages and creates
an index.
=head2 EXPORT
None.
=head2 METHODS
This is a list of public methods.
=over 2
=item new
Returns a new Text::Index object. When called on an
existing object, C<new> clones that object (deeply).
=cut
sub new {
my $proto = shift;
my $class = ref($proto)||$proto;
my $self = {
keywords => {},
pages => [],
};
if (_INSTANCE($proto, __PACKAGE__)) {
@{$self->{pages}} = $proto->pages;
foreach ($proto->keywords) {
my $clone = {
key => $_->[0],
deriv => [ @{ $_->[1] } ],
};
$self->{keywords}{$_->[0]} = $clone;
}
}
return bless $self => $class;
}
=item add_page
Adds a page to the index object. The page is expected to be
a string of text passed in as first argument.
Returns the Text::Index object for convenience of
method chaining.
=cut
sub add_page {
my $self = shift;
my $page = shift;
push @{$self->{pages}}, $page;
return $self;
}
=item add_pages
Adds a number of pages to the index object.
All arguments are treated as pages. See C<add_page>.
=cut
sub add_pages {
my $self = shift;
push @{$self->{pages}}, @_;
return $self;
}
=item pages
Returns all registered pages as a list.
=cut
sub pages {
my $self = shift;
return @{$self->{pages}};
}
=item add_keyword
Adds a new keyword to the index. First argument must be the
keyword to add. Following the keyword may be any number of
alternative names / string which should be treated to be equal
to the keyword.
Returns the Text::Index object for convenience.
=cut
sub add_keyword {
my $self = shift;
my $keyword = shift;
my @deriv = @_;
view all matches for this distributionview release on metacpan - search on metacpan
( run in 1.304 second using v1.00-cache-2.02-grep-82fe00e-cpan-d29e8ade9f55 )