Changeset 1923

Show
Ignore:
Timestamp:
03/19/07 11:58:02 (1 year ago)
Author:
karpet
Message:

expose the tokenizer into Perl space for benchmarking

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • libswish3/trunk/README

    r1913 r1923  
    2929# ReplaceRules 
    3030# SpiderDirectory 
     31 
     32 
     33 
     34Getting Started  
     35----------------- 
     36 
     37See the INSTALL doc. 
     38 
     39But basically: 
     40 
     41 ./bootstrap (only necessary if you are doing development) 
     42 ./configure 
     43 make && make test 
     44 sudo make install 
     45 
     46 
  • libswish3/trunk/bindings/perl/3.xs

    r1921 r1923  
    217217MODULE = SWISH::3       PACKAGE = SWISH::3 
    218218 
    219 PROTOTYPES: disable 
     219PROTOTYPES: enable 
    220220 
    221221SV* 
     
    240240        RETVAL     
    241241       
    242        
     242SV* 
     243libswish3_version(self) 
     244    SV* self; 
     245     
     246    CODE: 
     247        RETVAL = newSVpvn( SWISH_LIB_VERSION, strlen(SWISH_LIB_VERSION) ); 
     248         
     249    OUTPUT: 
     250        RETVAL    
     251    
     252 
    243253# ********************************************************************************* 
    244254MODULE = SWISH::3       PACKAGE = SWISH::3::Constants 
     
    391401        RETVAL 
    392402         
    393   
    394          
     403 
     404         
     405swish_WordList * 
     406tokenize(self, str, ...) 
     407    SV* self; 
     408    SV* str; 
     409     
     410    PREINIT: 
     411        char * CLASS; 
     412        char * metaname = SWISH_DEFAULT_METANAME;    
     413        char * context  = SWISH_DEFAULT_METANAME; 
     414        int maxwordlen  = SWISH_MAX_WORD_LEN; 
     415        int minwordlen  = SWISH_MIN_WORD_LEN; 
     416        int word_pos    = 0; 
     417        int offset      = 0; 
     418         
     419    CODE: 
     420        CLASS = _which_class("WordList"); 
     421 
     422        if ( items > 2 ) 
     423        { 
     424            metaname = SvPV(ST(2), PL_na); 
     425             
     426            if ( items > 3 ) 
     427                context = SvPV(ST(3), PL_na); 
     428                 
     429            if ( items > 4 ) 
     430                maxwordlen = (int)SvIV(ST(4)); 
     431                 
     432            if ( items > 5 ) 
     433                minwordlen = (int)SvIV(ST(5)); 
     434                 
     435            if ( items > 6 ) 
     436                word_pos = (int)SvIV(ST(6)); 
     437                 
     438            if ( items > 7 ) 
     439                offset = (int)SvIV(ST(7)); 
     440                 
     441        } 
     442                 
     443        RETVAL = swish_tokenize( 
     444                        (xmlChar*)SvPV(str, PL_na), 
     445                        (xmlChar*)metaname, 
     446                        (xmlChar*)context, 
     447                        maxwordlen, 
     448                        minwordlen, 
     449                        word_pos, 
     450                        offset); 
     451         
     452        RETVAL->ref_cnt++; 
     453                         
     454    OUTPUT: 
     455        RETVAL 
     456         
     457 
    395458 
    396459# ******************************************************************************* 
     
    581644 
    582645 
     646void 
     647DESTROY(self) 
     648    swish_WordList * self 
     649     
     650    CODE: 
     651        self->ref_cnt--; 
     652        if (!self->ref_cnt) 
     653        { 
     654            swish_free_WordList(self); 
     655        } 
     656         
     657 
    583658 
    584659# ******************************************************************************* 
     
    657732    CODE: 
    658733        CLASS = _which_class("WordList"); 
     734         
     735# MUST increment refcnt 2x so that SWISH::3::Parser::WordList::DESTROY 
     736# does not free it. 
     737        self->wordlist->ref_cnt += 2; 
    659738        RETVAL = self->wordlist; 
    660739         
     
    774853        { 
    775854            swish_free_config(self); 
    776             swish_mem_debug(); 
    777855        } 
    778856         
  • libswish3/trunk/bindings/perl/t/02xml2_version.t

    r1920 r1923  
    1 use Test::More tests => 3
     1use Test::More tests => 4
    22 
    33use Devel::Peek; 
     
    1111diag($s); 
    1212 
     13ok( my $l = SWISH::3->libswish3_version, "libswish3 version"); 
     14diag($l); 
     15 
    1316#Dump $v; 
  • libswish3/trunk/bindings/perl/typemap

    r1914 r1923  
    11TYPEMAP 
    2 const char *                T_PV 
    3 xmlChar *                  T_PV 
     2const char *               T_PV 
     3xmlChar *                  T_PV 
    44swish_Config *             O_OBJECT 
    5 xmlHashTablePtr            O_OBJECT 
     5xmlHashTablePtr            O_OBJECT 
    66swish_ParseData *          O_OBJECT 
    7 xmlBufferPtr                T_IV 
     7xmlBufferPtr               T_IV 
    88swish_WordList *           O_OBJECT 
    99swish_DocInfo *            O_OBJECT 
  • libswish3/trunk/libswish3-config.in

    r1913 r1923  
    7676 
    7777    --libs) 
    78         echo -L${libdir} -lswishp @Z_LIBS@ @LIBS@ 
     78        echo -L${libdir} -lswish3 @Z_LIBS@ @LIBS@ 
    7979        ;; 
    8080 
  • libswish3/trunk/libswish3.build

    r1913 r1923  
    77use File::Path; 
    88 
    9 my $tmp      = '/tmp/swishparser.build'; 
    10 my $htdocs   = '/opt/trac/swishparser/htdocs'; 
     9my $tmp      = '/tmp/swish3.build'; 
     10my $htdocs   = '/opt/trac/swish3/htdocs'; 
    1111my $doc      = $htdocs . '/doc'; 
    1212my $dl       = $htdocs . '/download'; 
     
    3838print P "<ul>"; 
    3939for my $pod ( 
    40       qw/ swishparser.7 swishp_lint.1 swishp_words.1 swishp_isw.1 libswishp.3 /) 
     40      qw/ swish_lint.1 swish_words.1 swish_isw.1 libswish3.3 /) 
    4141{ 
    4242    shell( 
  • libswish3/trunk/src/libswish3/config.c

    r1921 r1923  
    160160 
    161161    swish_xfree(config); 
     162     
     163    swish_mem_debug(); 
    162164} 
    163165 
  • libswish3/trunk/src/libswish3/libswish3.h

    r1921 r1923  
    2929 
    3030 
     31#define SWISH_LIB_VERSION         "0.1.0" 
    3132#define SWISH_VERSION             "3.0.0" 
    3233#define SWISH_BUFFER_CHUNK_SIZE   10000 
     
    4142 
    4243#define SWISH_CONTRACTIONS         1 
    43 #define SWISH_NO_LOWER_UTF         1 
    44 /* chars > 127 will NOT be lowercased by default */ 
    4544 
    4645#define SWISH_SPECIAL_ARG         1 
     
    279278    swish_Word    *current;        // for iterating 
    280279    unsigned int   nwords; 
     280    unsigned int   ref_cnt;         // for scripting languages 
    281281}; 
    282282 
  • libswish3/trunk/src/libswish3/mem.c

    r1913 r1923  
    3737{ 
    3838    memcount = 0; 
     39     
     40    if (SWISH_DEBUG) 
     41        return; 
     42         
    3943    /* init the global env vars, but don't override if already set */ 
    4044    setenv("SWISH_DEBUG", "0", 0); 
  • libswish3/trunk/src/libswish3/words.c

    r1922 r1923  
    3030#include "libswish3.h" 
    3131 
    32 static int      WORD_DEBUG; 
     32extern int      SWISH_DEBUG; 
    3333static int      strip_ascii_chars(xmlChar * word, int len); 
    3434static int      strip_wide_chars(wchar_t * word, int len); 
     
    4444/**********************************************************************************************/ 
    4545 
     46/* we have our own set_debug here because we might be calling these tokenizing 
     47   functions without ever calling swish_init_config() 
     48 */ 
     49  
    4650static void set_debug() 
    4751{ 
     52    if (SWISH_DEBUG) 
     53        return; 
     54         
    4855    setenv("SWISH_DEBUG", "0", 0); 
    4956    /* init the global env var, but don't override if already set */ 
    50     WORD_DEBUG = strtol(getenv("SWISH_DEBUG"), (char**)NULL, 10); 
     57    SWISH_DEBUG = strtol(getenv("SWISH_DEBUG"), (char**)NULL, 10); 
    5158} 
    5259 
     
    5865{ 
    5966    swish_WordList *wl = (swish_WordList *) swish_xmalloc(sizeof(swish_WordList)); 
    60     wl->head = NULL; 
    61     wl->tail = NULL; 
     67    wl->head    = NULL; 
     68    wl->tail    = NULL; 
    6269    wl->current = NULL; 
    63     wl->nwords = 0; 
    64      
    65     set_debug(); 
    66  
     70    wl->nwords  = 0; 
     71    wl->ref_cnt = 0; 
    6772    return wl; 
    6873} 
     
    7378    swish_Word    *t; 
    7479 
    75     if (WORD_DEBUG > 9) 
     80    if (SWISH_DEBUG > 9) 
    7681        swish_debug_msg("freeing swish_WordList"); 
    7782 
     
    8085    while (list->current != NULL) 
    8186    { 
    82         if (WORD_DEBUG > 9) 
     87        if (SWISH_DEBUG > 9) 
    8388            swish_debug_msg("free metaname: %s", list->current->metaname); 
    8489             
    8590        swish_xfree(list->current->metaname); 
    8691         
    87         if (WORD_DEBUG > 9) 
     92        if (SWISH_DEBUG > 9) 
    8893            swish_debug_msg("free context: %s", list->current->context); 
    8994             
    9095        swish_xfree(list->current->context); 
    9196         
    92         if (WORD_DEBUG > 9) 
     97        if (SWISH_DEBUG > 9) 
    9398            swish_debug_msg("free word: %s", list->current->word); 
    9499             
    95100        swish_xfree(list->current->word); 
    96101                 
    97         if (WORD_DEBUG > 9) 
     102        if (SWISH_DEBUG > 9) 
    98103            swish_debug_msg("free Word struct"); 
    99104             
     
    103108    } 
    104109     
    105     if (WORD_DEBUG > 9) 
     110    if (SWISH_DEBUG > 9) 
    106111        swish_debug_msg("reset nwords"); 
    107112         
    108113    list->nwords = 0; 
    109114     
    110     if (WORD_DEBUG > 9) 
     115    if (SWISH_DEBUG > 9) 
    111116        swish_debug_msg("free list"); 
    112117         
     
    220225    } 
    221226     
    222     if( WORD_DEBUG > 5 ) 
     227    if( SWISH_DEBUG > 5 ) 
    223228        swish_debug_msg(" %lc is %d bytes long", ch, len); 
    224229         
     
    239244) 
    240245{ 
     246 
    241247    int byte_count = 0; 
    242248    swish_WordList *list = swish_init_WordList(); 
     
    261267    in_word = 0; 
    262268 
    263     if (WORD_DEBUG > 10) 
     269    if (SWISH_DEBUG > 10) 
    264270        swish_debug_msg("parsing string: '%ls' into words", wide); 
    265271 
     
    270276        byte_count += bytes_in_char((wint_t)c); 
    271277 
    272         if (WORD_DEBUG > 10) 
     278        if (SWISH_DEBUG > 10) 
    273279            swish_debug_msg(" wchar: %lc lower: %lc  int: %d %#x\n    orig: %lc %ld %#lx (next is %lc)", 
    274280                   (wint_t) wide[i], 
     
    294300            if (in_word) 
    295301            { 
    296                 if (WORD_DEBUG > 10) 
     302                if (SWISH_DEBUG > 10) 
    297303                    swish_debug_msg("found end of word: >%lc<", (wint_t)c); 
    298304 
     
    316322                else 
    317323                { 
    318                     if (WORD_DEBUG > 10) 
     324                    if (SWISH_DEBUG > 10) 
    319325                        swish_debug_msg("skipping word >%s< -- too short: %d", utf8_str, wl); 
    320326                } 
     
    327333            else 
    328334            { 
    329                 if (WORD_DEBUG > 10) 
     335                if (SWISH_DEBUG > 10) 
    330336                    swish_debug_msg("ignoring char >%lc<", (wint_t)c); 
    331337                     
     
    340346            { 
    341347             
    342                 if (WORD_DEBUG > 10) 
     348                if (SWISH_DEBUG > 10) 
    343349                    swish_debug_msg("adding to word: >%lc<", (wint_t)c); 
    344350 
     
    349355                { 
    350356 
    351                     if (WORD_DEBUG > 10) 
     357                    if (SWISH_DEBUG > 10) 
    352358                        swish_debug_msg("forcing end of word: >%lc<", (wint_t)c); 
    353359 
     
    371377                    else 
    372378                    { 
    373                         if (WORD_DEBUG > 10) 
     379                        if (SWISH_DEBUG > 10) 
    374380                            swish_debug_msg("skipping word >%ls< -- too short: %d", word, wl); 
    375381                    } 
     
    385391            { 
    386392 
    387                 if (WORD_DEBUG > 10) 
     393                if (SWISH_DEBUG > 10) 
    388394                    swish_debug_msg("start a word with >%lc<", (wint_t)c); 
    389395 
     
    473479    in_word = 0; 
    474480 
    475     if (WORD_DEBUG > 10) 
     481    if (SWISH_DEBUG > 10) 
    476482        swish_debug_msg("parsing string: '%s' into words", str); 
    477483 
     
    488494        byte_count++; 
    489495 
    490         if (WORD_DEBUG > 10) 
     496        if (SWISH_DEBUG > 10) 
    491497            swish_debug_msg(" char: %c lower: %c  int: %d %#x (next is %c)", 
    492498                   str[i], 
     
    509515            if (in_word) 
    510516            { 
    511                 if (WORD_DEBUG > 10) 
     517                if (SWISH_DEBUG > 10) 
    512518                    swish_debug_msg("found end of word: >%c<", c); 
    513519 
     
    530536                else 
    531537                { 
    532                     if (WORD_DEBUG > 10) 
     538                    if (SWISH_DEBUG > 10) 
    533539                        swish_debug_msg("skipping word >%s< -- too short: %d", word, wl); 
    534540                } 
     
    539545            else 
    540546            { 
    541                 if (WORD_DEBUG > 10) 
     547                if (SWISH_DEBUG > 10) 
    542548                    swish_debug_msg("ignoring char >%c<", c); 
    543549                     
     
    552558            { 
    553559             
    554                 if (WORD_DEBUG > 10) 
     560                if (SWISH_DEBUG > 10) 
    555561                    swish_debug_msg("adding to word: >%c<", c); 
    556562 
     
    561567                { 
    562568 
    563                     if (WORD_DEBUG > 10) 
     569                    if (SWISH_DEBUG > 10) 
    564570                        swish_debug_msg("forcing end of word: >%c<", c); 
    565571 
     
    582588                    else 
    583589                    { 
    584                         if (WORD_DEBUG > 10) 
     590                        if (SWISH_DEBUG > 10) 
    585591                            swish_debug_msg("skipping word >%s< -- too short: %d", word, wl); 
    586592                    } 
     
    594600            { 
    595601 
    596                 if (WORD_DEBUG > 10) 
     602                if (SWISH_DEBUG > 10) 
    597603                    swish_debug_msg("start a word with >%c<", c); 
    598604 
     
    631637) 
    632638{ 
    633      
     639 
     640    set_debug();    /* in case this is called without ever swish_init_config() */ 
     641 
    634642    if (swish_is_ascii( str )) 
    635643    { 
     
    670678    end = 0; 
    671679 
    672     if (WORD_DEBUG > 8) 
     680    if (SWISH_DEBUG > 8) 
    673681        swish_debug_msg("Before: %ls", word); 
    674682 
     
    721729    } 
    722730 
    723     if (WORD_DEBUG > 8) 
     731    if (SWISH_DEBUG > 8) 
    724732        swish_debug_msg("After: %ls (stripped %d start chars, %d end chars)", word, start, end); 
    725733 
     
    735743    end = 0; 
    736744 
    737     if (WORD_DEBUG > 8) 
     745    if (SWISH_DEBUG > 8) 
    738746        swish_debug_msg("Before: %s", word); 
    739747 
     
    786794    } 
    787795 
    788     if (WORD_DEBUG > 8) 
     796    if (SWISH_DEBUG > 8) 
    789797        swish_debug_msg("After: %s (stripped %d start chars, %d end chars)", word, start, end); 
    790798 
     
    811819    size_t          len = xmlStrlen(word); 
    812820 
    813     if (WORD_DEBUG > 4) 
     821    if (SWISH_DEBUG > 4) 
    814822    { 
    815823        swish_debug_msg(" >>>>>>>>swish_Word<<<<<<<<:  %s", word); 
     
    823831    thisword->word     = swish_xstrdup(word); 
    824832    thisword->position = word_pos; 
    825     thisword->metaname = swish_xstrdup(metaname); 
    826     thisword->context  = swish_xstrdup(context); 
     833     
     834    if (metaname != NULL) 
     835        thisword->metaname = swish_xstrdup(metaname); 
     836    else 
     837        thisword->metaname = swish_xstrdup((xmlChar*)SWISH_DEFAULT_METANAME); 
     838         
     839    if (context != NULL) 
     840        thisword->context  = swish_xstrdup(context); 
     841    else 
     842        thisword->context  = swish_xstrdup((xmlChar*)SWISH_DEFAULT_METANAME); 
     843         
    827844    thisword->end_offset   = offset - 1; 
    828845    thisword->start_offset = offset - len; 
  • libswish3/trunk/src/swish_lint.c

    r1913 r1923  
    5959void swish_version() 
    6060{ 
    61     printf("libswishp version %s\n", SWISH_VERSION); 
     61    printf("libswish3 version %s\n", SWISH_VERSION); 
    6262} 
    6363