IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Dec 1, 2004, 12:34:23 PM (22 years ago)
Author:
jhoblitt
Message:

only use source code I hold the copyright on for examples
LaTeX formatting
document formatting
grammar and spelling fixes
misc example corrections
misc corrections
moved example source code to appendix
added several new programming practices

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/doc/misc/buildIndex.pl

    r2471 r2591  
    55# $Id: buildIndex.pl,v 1.1 2004/04/20 22:16:17 jhoblitt Exp $
    66
     7use 5.008;
     8
    79use strict;
    810use warnings;
    911
    10 use vars qw( $VERSION );
    11 $VERSION = '0.01';
     12our $VERSION = '0.01';
    1213
    1314use File::Basename qw();
     
    2122use Pod::Usage qw( pod2usage );
    2223
    23 my ($verbose, $help, $path, $index_dir);
     24my ($verbose, $help, $path, $indexDir);
    2425GetOptions(
    2526    'verbose' => \$verbose,
    2627    'path=s'  => \$path,
    27     'index=s' => \$index_dir,
     28    'index=s' => \$indexDir,
    2829    )
    2930    or pod2usage(2);
     
    3233pod2usage(-msg => "Required option: --path|-p", -exitval => 2) unless $path;
    3334
    34 $index_dir = $path . "/.index" unless defined $index_dir;
     35$indexDir = $path . "/.index" unless defined $indexDir;
    3536
    3637##my $stripper = HTML::Strip->new;
    3738
    3839my $writer = Plucene::Index::Writer->new(
    39     $index_dir,
     40    $indexDir,
    4041    Plucene::Plugin::Analyzer::PorterAnalyzer->new(),
    4142    1    # Create the index from scratch
     
    4445my $doc = Plucene::Document->new;
    4546
    46 foreach my $file_name (File::Find::Rule->file->name(qr/^msg\d+\.html/)->in($path)) {
    47     print "indexing: $file_name\n" if $verbose;
    48     $writer->add_document(parse_mhonarc_html($file_name));
     47foreach my $filename (File::Find::Rule->file->name(qr/^msg\d+\.html/)->in($path)) {
     48    print "indexing: $filename\n" if $verbose;
     49    $writer->add_document(parseMhonarcHtml($filename));
    4950}
    5051
    51 sub parse_mhonarc_html
     52sub parseMhonarcHtml
    5253{
    53     my $file_name = shift;
    54 
    55     my $tree = HTML::TreeBuilder->new_from_file($file_name);
     54    my $filename = shift;
     55
     56    my $tree = HTML::TreeBuilder->new_from_file($filename);
    5657    my $doc  = Plucene::Document->new;
    5758
    58     $doc->add(Plucene::Document::Field->Keyword(file_name => File::Basename::basename($file_name),));
     59    $doc->add(Plucene::Document::Field->Keyword(file_name => File::Basename::basename($filename),));
    5960
    6061    # get the header values for to, cc, from, date, and subject
    6162
    6263    # find the <div> tag labeled header
    63     my $header_tag = $tree->look_down(_tag => "div", id => "header");
     64    my $headerTag = $tree->look_down(_tag => "div", id => "header");
    6465
    6566    my %headers;
    6667
    67     foreach my $row_node ($header_tag->look_down(_tag => "tr")) {
     68    foreach my $rowNode ($headerTag->look_down(_tag => "tr")) {
    6869
    6970        # process each row of the header
    7071
    7172        # get name of header field
    72         my $name_node = $row_node->look_down(_tag => "td");
    73         my $name = lc($name_node->look_down(_tag => "em")->as_text);
    74         $name_node->delete;
     73        my $nameNode = $rowNode->look_down(_tag => "td");
     74        my $name = lc($nameNode->look_down(_tag => "em")->as_text);
     75        $nameNode->delete;
    7576
    7677        # get content of header field
    77         my $content_node = $row_node->look_down(_tag => "td");
    78         my $content      = $content_node->as_text;
     78        my $contentNode = $rowNode->look_down(_tag => "td");
     79        my $content     = $contentNode->as_text;
    7980
    8081        # index "cc" as part of "to"
     
    9091
    9192    # find the <div> tag labeled content
    92     my $content_tag = $tree->root->look_down(_tag => "div", id => "content");
     93    my $contentTag = $tree->root->look_down(_tag => "div", id => "content");
    9394
    9495    # index message body
    9596    print "\tadding to index content\n" if $verbose;
    96     $doc->add(Plucene::Document::Field->UnStored(content => $content_tag->as_text));
     97    $doc->add(Plucene::Document::Field->UnStored(content => $contentTag->as_text));
    9798
    9899    return $doc;
     
    105106=head1 NAME
    106107
    107 build_index.pl - generate Plucene/Lucene index of MHonarc archives
     108buildIndex.pl - generate Plucene/Lucene index of MHonarc archives
    108109
    109110=head1 SYNOPSIS
    110111
    111     build_index.pl --path dir [--index dir] [--verbose]
     112    buildIndex.pl --path dir [--index dir] [--verbose]
    112113
    113114    or
    114115
    115     build_index.pl -p dir [-i dir] [-v]
     116    buildIndex.pl -p dir [-i dir] [-v]
    116117
    117118    or
    118119
    119     build_index.pl [--help | -h | -? | --version]
     120    buildIndex.pl [--help | -h | -? | --version]
    120121
    121122=head1 DESCRIPTION
     
    148149=back
    149150
    150 =head1 DEVELOPERS
     151=head1 DEVELOPER NOTES
    151152
    152153The parser extracts the C<to>, C<cc>, C<from>, C<subject>, and C<date> headers
     
    201202Place - Suite 330, Boston, MA  02111-1307, USA.
    202203
    203 The full text of the license can be found in the LICENSE file included with
    204 this module, or in the L<perlgpl> Pod as supplied with Perl 5.8.1 and later.
     204The full text of the license can be found in the L<perlgpl> Pod as supplied
     205with Perl 5.8.1 and later.
    205206
    206207=head1 SEE ALSO
Note: See TracChangeset for help on using the changeset viewer.