Changeset 1920

Show
Ignore:
Timestamp:
03/04/07 21:32:53 (1 year ago)
Author:
karpet
Message:

reorg namespaces and add stubs for indexer, etc.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • libswish3/trunk/bindings/perl/3.xs

    r1914 r1920  
    4444static char * callback_method = "handler"; 
    4545static HV * SubClasses       = (HV*)NULL; 
    46 static int nClasses          = 7; 
     46static int nClasses          = 5;   /* match Classes[] ?? */ 
    4747static char * Classes[]      = {  
    4848        "Doc",  
     
    215215 
    216216/*************************************************************************************/ 
    217  
    218 MODULE = SWISH::3               PACKAGE = SWISH::3       
     217MODULE = SWISH::3       PACKAGE = SWISH::3 
     218 
     219PROTOTYPES: disable 
     220 
     221SV* 
     222xml2_version(self) 
     223    SV* self; 
     224     
     225    CODE: 
     226        RETVAL = newSVpvn( LIBXML_DOTTED_VERSION, strlen(LIBXML_DOTTED_VERSION) ); 
     227         
     228    OUTPUT: 
     229        RETVAL 
     230         
     231         
     232SV* 
     233swish_version(self) 
     234    SV* self; 
     235     
     236    CODE: 
     237        RETVAL = newSVpvn( SWISH_VERSION, strlen(SWISH_VERSION) ); 
     238         
     239    OUTPUT: 
     240        RETVAL     
     241         
     242# ********************************************************************************* 
     243 
     244MODULE = SWISH::3               PACKAGE = SWISH::3::Parser       
    219245 
    220246PROTOTYPES: enable 
    221247                     
     248void 
     249_make_subclasses (self) 
     250    SV * self 
     251     
     252        PREINIT: 
     253        char* class; 
     254         
     255        CODE: 
     256        class = sv_reftype(SvRV(self), 1); 
     257        //printf("parent class is %s\n", class); 
     258            _make_subclasses(class); 
     259 
    222260 
    223261void 
     
    241279        RETVAL 
    242280         
    243  
    244 SV* 
    245 libxml2_version(self) 
    246     SV* self; 
    247      
    248     CODE: 
    249         RETVAL = newSVpvn( LIBXML_DOTTED_VERSION, strlen(LIBXML_DOTTED_VERSION) ); 
    250          
    251     OUTPUT: 
    252         RETVAL 
    253          
    254          
    255 void 
    256 _make_subclasses (self) 
    257     SV * self 
    258      
    259         PREINIT: 
    260         char* class; 
    261          
    262         CODE: 
    263         class = sv_reftype(SvRV(self), 1); 
    264         //printf("parent class is %s\n", class); 
    265             _make_subclasses(class); 
    266              
    267281 
    268282void 
     
    345359# ******************************************************************************* 
    346360     
    347 MODULE = SWISH::3               PACKAGE = SWISH::3::Word 
     361MODULE = SWISH::3               PACKAGE = SWISH::3::Parser::Word 
    348362 
    349363PROTOTYPES: disable 
     
    399413# ******************************************************************************* 
    400414     
    401 MODULE = SWISH::3               PACKAGE = SWISH::3::Doc 
     415MODULE = SWISH::3               PACKAGE = SWISH::3::Parser::Doc 
    402416 
    403417PROTOTYPES: disable 
     
    484498# ******************************************************************************* 
    485499     
    486 MODULE = SWISH::3               PACKAGE = SWISH::3::Property 
     500MODULE = SWISH::3               PACKAGE = SWISH::3::Parser::Property 
    487501 
    488502PROTOTYPES: disable 
     
    492506# ******************************************************************************* 
    493507     
    494 MODULE = SWISH::3               PACKAGE = SWISH::3::WordList 
     508MODULE = SWISH::3               PACKAGE = SWISH::3::Parser::WordList 
    495509 
    496510PROTOTYPES: disable 
     
    523537# ******************************************************************************* 
    524538     
    525 MODULE = SWISH::3               PACKAGE = SWISH::3::Data 
     539MODULE = SWISH::3               PACKAGE = SWISH::3::Parser::Data 
    526540 
    527541PROTOTYPES: disable 
  • libswish3/trunk/bindings/perl/MANIFEST

    r1914 r1920  
    77t/SWISH-3.t 
    88lib/SWISH/3.pm 
    9 lib/SWISH/3/Doc.pm 
    10 lib/SWISH/3/Property.pm 
    11 lib/SWISH/3/MetaName.pm 
    12 lib/SWISH/3/Word.pm 
    13 lib/SWISH/3/WordList.pm 
     9lib/SWISH/3/Parser.pm 
     10lib/SWISH/3/Parser/Doc.pm 
     11lib/SWISH/3/Parser/Property.pm 
     12lib/SWISH/3/Parser/MetaName.pm 
     13lib/SWISH/3/Parser/Word.pm 
     14lib/SWISH/3/Parser/WordList.pm 
    1415lib/SWISH/3/Config.pm 
    15 lib/SWISH/3/Data.pm 
     16lib/SWISH/3/Parser/Data.pm 
  • libswish3/trunk/bindings/perl/Makefile.PL

    r1914 r1920  
    99      (ABSTRACT_FROM  => 'lib/SWISH/3.pm', 
    1010       AUTHOR         => 'Peter Karman <perl@peknet.com>') : ()), 
    11     LIBS              => ['-L/usr/local/lib -lswish3 -lxml2'], 
     11    LIBS              => ['-L/opt/local/lib -L/usr/local/lib -lswish3 -lxml2'], 
    1212    DEFINE            => '', # e.g., '-DHAVE_SOMETHING' 
    13     INC               => '-I/usr/include/libxml2 -I/usr/local/include/libxml2 -I.', 
     13    INC               => '-I/opt/local/include/libxml2 -I/usr/local/include/libxml2 -I.', 
    1414        # Un-comment this if you add C files to link with later: 
    1515    # OBJECT            => '$(O_FILES)', # link all the C files too 
  • libswish3/trunk/bindings/perl/lib/SWISH/3.pm

    r1914 r1920  
    11package SWISH::3; 
    22 
     3use 5.8.3; 
    34use strict; 
    45use warnings; 
     
    910use Data::Dump qw(pp); 
    1011 
    11 use base qw(Class::Accessor::Fast); 
    12  
    1312require XSLoader; 
    1413XSLoader::load('SWISH::3', $VERSION); 
     
    1615# defer till runtime so any constants can load 
    1716require SWISH::3::Config; 
    18 require SWISH::3::Data; 
    19 require SWISH::3::Doc; 
    20 require SWISH::3::MetaName; 
    21 require SWISH::3::Property; 
    22 require SWISH::3::Word; 
    23 require SWISH::3::WordList; 
    24 require SWISH::Doc; 
    25  
    26 use Devel::Peek; 
     17require SWISH::3::Parser; 
    2718 
    2819 
    29 __PACKAGE__->mk_accessors(qw/ config handler /); 
    30  
    31 sub new 
    32 
    33     my $proto = shift; 
    34     my $class = ref($proto) || $proto; 
    35     my $self  = {}; 
    36  
    37     bless($self, $class); 
    38     $self->_make_subclasses; 
    39     $self->_init(@_); 
    40     $self->_init_parser; 
    41     return $self; 
    42 
    43  
    44 sub DESTROY 
    45 
    46     my $self = shift; 
    47  
    48     #carp "about to DESTROY 3 object"; 
    49     #Dump $self; 
    50  
    51     $self->_free; 
    52     $self->_cleanup; 
    53 
    54  
    55 sub _init 
    56 
    57     my $self = shift; 
    58     if (@_) 
    59     { 
    60         my %extra = @_; 
    61         @$self{keys %extra} = values %extra; 
    62     } 
    63  
    64     my $conf = SWISH::3::Config->new; 
    65  
    66     if ($self->config) 
    67     { 
    68         $conf->add($self->config); 
    69     } 
    70  
    71     $self->config($conf); 
    72  
    73     unless (exists($self->{handler}) && ref($self->{handler}) eq 'CODE') 
    74     { 
    75         carp 
    76           "WARNING: using default 3 handler -- that's likely not what you want"; 
    77         $self->handler(\&def_handler); 
    78     } 
    79 
    80  
    81 sub debug 
    82 
    83     my $self = shift; 
    84      
    85     $self->config->debug; 
    86  
    87 
    88  
    89 sub def_handler 
    90 
    91     my $data = shift; 
    92  
    93     select(STDERR); 
    94  
    95     #print '~' x 80, "\n"; 
    96  
    97     my $props = $data->config->properties; 
    98  
    99     #print "Properties\n"; 
    100     for my $p (keys %$props) 
    101     { 
    102         my $v    = $data->property($p); 
    103         my $type = $props->{$p}; 
    104  
    105         #print "    <$p type='$type'>$v</$p>\n"; 
    106     } 
    107  
    108     #print "Doc\n"; 
    109     for my $d (@SWISH::Doc::Fields) 
    110     { 
    111  
    112         #printf("%15s: %s\n", $d, $data->doc->$d); 
    113     } 
    114  
    115     #print "WordList\n"; 
    116     while (my $swishword = $data->wordlist->next) 
    117     { 
    118         for my $w (@SWISH::3::Word::Fields) 
    119         { 
    120  
    121             #printf("%15s: %s\n", $w, $swishword->$w); 
    122         } 
    123     } 
    124  
    125 
     20# variables used by various classes 
     21our @DocFields  = qw( mtime size encoding mime uri nwords ext parser ); 
     22our @WordFields = qw( word position metaname start_offset end_offset ); 
    12623 
    127241; 
     
    13633 use SWISH::3; 
    13734  
    138  my $parser = SWISH::3->new(  
    139                 config  => 'path/to/my_file.conf', 
    140                 handler => \&handler 
    141                 ); 
    142                  
    143  my $indexer = MyIndexer->new(); 
     35 my $xml2_version = SWISH::3->xml2_version; 
     36 my $swish3_version = $SWISH::3::VERSION; 
    14437  
    145  $indexer->open_index; 
    146   
    147  for my $file (@list_of_files_from_somewhere) 
    148  { 
    149     $parser->parse_file($file); 
    150  } 
    151   
    152  $indexer->close_index; 
    153   
    154  sub handler 
    155  { 
    156     my $data = shift; 
    157      
    158     my $doc_id = $indexer->add_doc( $data ); 
    159     $indexer->add_properties( $data, $doc_id ); 
    160     $indexer->add_words( $data, $doc_id ); 
    161  } 
    162  
    16338  
    16439=head1 DESCRIPTION 
     
    16641 
    16742 
    168 =head1 METHODS 
     43=head1 CLASS METHODS 
    16944 
    170 =head2 new 
    171  
    172 =head2 parse_file 
    173  
    174 =head2 parse_buf 
     45=head2 make_subclasses 
    17546 
    17647 
     
    17849=head1 UTILITY METHODS 
    17950 
    180 =head2 libxml2_version 
    181  
    182 =head2 slurp_file 
     51=head2 xml2_version 
    18352 
    18453 
     
    18756L<http://swish-e.org/> 
    18857 
    189 SWISH::Prog, SWISH::Index, SWISH::Doc, SWISH::Search 
     58SWISH::Prog 
    19059 
    19160=cut 
  • libswish3/trunk/bindings/perl/lib/SWISH/3/Config.pm

    r1914 r1920  
    6060=head1 NAME 
    6161 
    62 SWISH::3::Config - Swish-e XML-style configuration 
     62SWISH::3::Config - Swish3 configuration 
    6363 
    6464=head1 SYNOPSIS 
  • libswish3/trunk/bindings/perl/lib/SWISH/3/Parser/Data.pm

    r1914 r1920  
    1 package SWISH::3::Data; 
     1package SWISH::3::Parser::Data; 
    22 
    33use strict; 
     
    88our $VERSION = '0.01'; 
    99 
     10sub handler 
     11{ 
     12    my $data = shift; 
     13 
     14    select(STDERR); 
     15 
     16    #print '~' x 80, "\n"; 
     17 
     18    my $props = $data->config->properties; 
     19 
     20    #print "Properties\n"; 
     21    for my $p (keys %$props) 
     22    { 
     23        my $v    = $data->property($p); 
     24        my $type = $props->{$p}; 
     25 
     26        #print "    <$p type='$type'>$v</$p>\n"; 
     27    } 
     28 
     29    #print "Doc\n"; 
     30    for my $d (@SWISH::3::DocFields) 
     31    { 
     32 
     33        #printf("%15s: %s\n", $d, $data->doc->$d); 
     34    } 
     35 
     36    #print "WordList\n"; 
     37    while (my $swishword = $data->wordlist->next) 
     38    { 
     39        for my $w (@SWISH::3::WordFields) 
     40        { 
     41 
     42            #printf("%15s: %s\n", $w, $swishword->$w); 
     43        } 
     44    } 
     45 
     46} 
    1047 
    11481; 
     
    1451=head1 NAME 
    1552 
    16 SWISH::3::Data - handle the data returned from the SWISH3::3 
     53SWISH::3::Parser::Data - handle the data returned from the SWISH3::3::Parser 
    1754 
    1855 
  • libswish3/trunk/bindings/perl/lib/SWISH/3/Parser/Doc.pm

    r1914 r1920  
    1 package SWISH::3::Doc; 
     1package SWISH::3::Parser::Doc; 
    22 
    33use strict; 
  • libswish3/trunk/bindings/perl/lib/SWISH/3/Parser/MetaName.pm

    r1914 r1920  
    1 package SWISH::3::MetaName; 
     1package SWISH::3::Parser::MetaName; 
    22 
    33use strict; 
    44use warnings; 
    5 use Carp
    6 use Data::Dump qw/ pp /
     5use base qw( SWISH::3::Object )
     6__PACKAGE__->mk_accessors(qw( name bias ))
    77 
    8 use base qw( Class::Accessor::Fast ); 
    9 __PACKAGE__->mk_accessors(qw/ name bias /); 
    10  
    11 sub new 
    12 { 
    13     my $proto = shift; 
    14     my $class = ref($proto) || $proto; 
    15     my $self  = {}; 
    16     bless($self, $class); 
    17     $self->_init(@_); 
    18     return $self; 
    19 } 
    20  
    21  
    22 sub _init 
    23 { 
    24     my $self = shift; 
    25     if (@_) 
    26     { 
    27         my %extra = @_; 
    28         @$self{keys %extra} = values %extra; 
    29     } 
    30 } 
    318 
    3291; 
  • libswish3/trunk/bindings/perl/lib/SWISH/3/Parser/Property.pm

    r1914 r1920  
    1 package SWISH::3::Property; 
     1package SWISH::3::Parser::Property; 
    22 
    33use strict; 
  • libswish3/trunk/bindings/perl/lib/SWISH/3/Parser/Word.pm

    r1914 r1920  
    1 package SWISH::3::Word; 
     1package SWISH::3::Parser::Word; 
    22 
    33use strict; 
     
    77our $VERSION = '0.01'; 
    88 
    9 our @Fields = qw( word position metaname start_offset end_offset ); 
    10  
    1191; 
  • libswish3/trunk/bindings/perl/lib/SWISH/3/Parser/WordList.pm

    r1914 r1920  
    1 package SWISH::3::WordList; 
     1package SWISH::3::Parser::WordList; 
    22 
    33use strict; 
  • libswish3/trunk/bindings/perl/t/01slurp.t

    r1914 r1920  
    55BEGIN { use_ok('SWISH::3') }; 
    66 
    7 ok( my $parser = SWISH::3->new,   "new object"); 
     7ok( my $parser = SWISH::3::Parser->new,   "new object"); 
    88 
    99ok( my $buf = $parser->slurp_file("t/test.html"),   "slurp file"); 
  • libswish3/trunk/bindings/perl/t/02xml2_version.t

    r1914 r1920  
    55BEGIN { use_ok('SWISH::3') }; 
    66 
    7 ok( my $parser = SWISH::3->new,   "new object"); 
     7ok( my $x = SWISH::3->xml2_version,   "libxml2 version"); 
     8diag($x); 
    89 
    9 ok( my $v = $parser->libxml2_version,   "libxml2 version"); 
    10 diag($v); 
     10ok( my $s = SWISH::3->swish_version,   "swish version"); 
     11diag($s); 
    1112 
    1213#Dump $v; 
  • libswish3/trunk/bindings/perl/t/03parse_file.t

    r1914 r1920  
    1010} 
    1111 
    12 ok(my $parser = SWISH::3->new(handler => sub {  }), 
     12ok(my $parser = SWISH::3::Parser->new(handler => sub {  }), 
    1313    "new parser"); 
    1414 
  • libswish3/trunk/bindings/perl/t/04subclass.t

    r1914 r1920  
    33use Test::More tests => 201; 
    44 
    5 use base qw/ SWISH::3 /; 
    6  
     5use base qw( SWISH::3::Parser ); 
    76 
    87ok( 
     
    28271; 
    2928 
     29 
    3030package MyApp::Data; 
    31 use base qw( SWISH::3::Data ); 
     31use base qw( SWISH::3::Parser::Data ); 
    32321; 
    3333 
    3434 
    3535package MyApp::Doc; 
    36 use base qw( SWISH::3::Doc ); 
     36use base qw( SWISH::3::Parser::Doc ); 
    37371; 
    3838 
    3939package MyApp::Property; 
    40 use base qw( SWISH::3::Property ); 
     40use base qw( SWISH::3::Parser::Property ); 
    41411; 
    4242 
    4343package MyApp::Word; 
    44 use base qw( SWISH::3::Word ); 
     44use base qw( SWISH::3::Parser::Word ); 
    45451; 
    4646 
    4747package MyApp::WordList; 
    48 use base qw( SWISH::3::WordList ); 
     48use base qw( SWISH::3::Parser::WordList ); 
    49491; 
  • libswish3/trunk/bindings/perl/t/05latin1.t

    r1914 r1920  
    99} 
    1010 
    11 ok(my $parser = SWISH::3->new, "new parser"); 
     11ok(my $parser = SWISH::3::Parser->new, "new parser"); 
    1212 
    1313#monitor('parser' => \$parser);