ó Ž ËPc@s dZdefd„ƒYZdS(s sphinx.util.stemmer ~~~~~~~~~~~~~~~~~~~ Porter Stemming Algorithm This is the Porter stemming algorithm, ported to Python from the version coded up in ANSI C by the author. It may be be regarded as canonical, in that it follows the algorithm presented in Porter, 1980, An algorithm for suffix stripping, Program, Vol. 14, no. 3, pp 130-137, only differing from it at the points maked --DEPARTURE-- below. See also http://www.tartarus.org/~martin/PorterStemmer The algorithm as described in the paper could be exactly replicated by adjusting the points of DEPARTURE, but this is barely necessary, because (a) the points of DEPARTURE are definitely improvements, and (b) no encoding of the Porter stemmer I have seen is anything like as exact as this version, even with the points of DEPARTURE! Release 1: January 2001 :copyright: Copyright 2001 by Vivake Gupta . :license: Public Domain ("can be used free of charge for any purpose"). t PorterStemmercBs˜eZd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„Z d„Z d „Z d „Z d „Z d „Zd „Zd„Zd„ZRS(cCs(d|_d|_d|_d|_dS(sÔThe main part of the stemming algorithm starts here. b is a buffer holding a word to be stemmed. The letters are in b[k0], b[k0+1] ... ending at b[k]. In fact k0 = 0 in this demo program. k is readjusted downwards as the stemming progresses. Zero termination is not in fact used in the algorithm. Note that only lower case sequences are stemmed. Forcing to lower case should be done before stem(...) is called. tiN(tbtktk0tj(tself((s=/usr/local/lib/python2.7/site-packages/sphinx/util/stemmer.pyt__init__!s   cCs¢|j|dks_|j|dks_|j|dks_|j|dks_|j|dkrcdS|j|dkrž||jkr‰dS|j|dƒ SndS( s(cons(i) is TRUE <=> b[i] is a consonant.tatetitotuityi(RRtcons(RR ((s=/usr/local/lib/python2.7/site-packages/sphinx/util/stemmer.pyR1s9&cCsãd}|j}x3||jkr%|S|j|ƒs8Pn|d}q|d}xx3||jkrh|S|j|ƒr{Pn|d}qU|d}|d}x3||jkr²|S|j|ƒsÅPn|d}qŸ|d}qRdS(sFm() measures the number of consonant sequences between k0 and j. if c is a consonant sequence and v a vowel sequence, and <..> indicates arbitrary presence, gives 0 vc gives 1 vcvc gives 2 vcvcvc gives 3 .... iiN(RRR(RtnR ((s=/usr/local/lib/python2.7/site-packages/sphinx/util/stemmer.pytm=s2        cCs;x4t|j|jdƒD]}|j|ƒsdSqWdS(s2vowelinstem() is TRUE <=> k0,...j contains a vowelii(trangeRRR(RR ((s=/usr/local/lib/python2.7/site-packages/sphinx/util/stemmer.pyt vowelinstembs cCsF||jdkrdS|j||j|dkr9dS|j|ƒS(s:doublec(j) is TRUE <=> j,(j-1) contain a double consonant.ii(RRR(RR((s=/usr/local/lib/python2.7/site-packages/sphinx/util/stemmer.pytdoublecis cCs‡||jdksJ|j|ƒ sJ|j|dƒsJ|j|dƒ rNdS|j|}|dks|dks|dkrƒdSdS(s)cvc(i) is TRUE <=> i-2,i-1,i has the form consonant - vowel - consonant and also if the second c is not w,x or y. this is used when trying to restore an e at the end of a short e.g. cav(e), lov(e), hop(e), crim(e), but snow, box, tray. iiitwtxR (RRR(RR tch((s=/usr/local/lib/python2.7/site-packages/sphinx/util/stemmer.pytcvcqs 6 $cCsŒt|ƒ}||d|j|jkr.dS||j|jdkrLdS|j|j|d|jd!|krxdS|j||_dS(s3ends(s) is TRUE <=> k0,...k ends with the string s.ii(tlenRRRR(Rtstlength((s=/usr/local/lib/python2.7/site-packages/sphinx/util/stemmer.pytends‚s (cCsQt|ƒ}|j|jd ||j|j|d|_|j||_dS(sRsetto(s) sets (j+1),...k to the characters in the string s, readjusting k.iN(RRRR(RRR((s=/usr/local/lib/python2.7/site-packages/sphinx/util/stemmer.pytsettoŽs 1cCs&|jƒdkr"|j|ƒndS(sr(s) is used further down.iN(RR(RR((s=/usr/local/lib/python2.7/site-packages/sphinx/util/stemmer.pytr•scCsø|j|jdkr‡|jdƒr8|jd|_q‡|jdƒrW|jdƒq‡|j|jddkr‡|jd|_q‡n|jdƒr¾|jƒdkrô|jd|_qôn6|jd ƒsÜ|jd ƒrô|jƒrô|j|_|jd ƒr|jd ƒqô|jd ƒr2|jdƒqô|jdƒrQ|jdƒqô|j|jƒr½|jd|_|j|j}|dks§|dks§|dkrñ|jd|_qñqô|jƒdkrô|j|jƒrô|jdƒqôndS(sèstep1ab() gets rid of plurals and -ed or -ing. e.g. caresses -> caress ponies -> poni ties -> ti caress -> caress cats -> cat feed -> feed agreed -> agree disabled -> disable matting -> mat mating -> mate meeting -> meet milling -> mill messing -> mess meetings -> meet RtssesitiesR iteeditedtingtattatetbltbletiztizetltzR N( RRRRRRRRR(RR((s=/usr/local/lib/python2.7/site-packages/sphinx/util/stemmer.pytstep1abšs2* $$cCsK|jdƒrG|jƒrG|j|j d|j|jd|_ndS(sOstep1c() turns terminal y to i when there is another vowel in the stem.R R iN(RRRR(R((s=/usr/local/lib/python2.7/site-packages/sphinx/util/stemmer.pytstep1cÆscCsw|j|jddkr[|jdƒr9|jdƒqs|jdƒrs|jdƒqsn|j|jddkr¶|jdƒr”|jd ƒqs|jd ƒrs|jd ƒqsn½|j|jdd krò|jd ƒrs|jdƒqsn|j|jddkrª|jdƒr+|jdƒqs|jdƒrJ|jdƒqs|jdƒri|jdƒqs|jdƒrˆ|jd ƒqs|jdƒrs|jdƒqsnÉ|j|jddkr$|jdƒrã|jdƒqs|jdƒr|jdƒqs|jdƒrs|jdƒqsnO|j|jddkr½|jdƒr]|jdƒqs|jdƒr||jd ƒqs|jd!ƒr›|jd"ƒqs|jd#ƒrs|jdƒqsn¶|j|jdd$kr7|jd%ƒrö|jdƒqs|jd&ƒr|jd ƒqs|jd'ƒrs|jdƒqsn<|j|jdd(krs|jd)ƒrs|jd*ƒqsnd+S(,s³step2() maps double suffices to single ones. so -ization ( = -ize plus -ation) maps to -ize etc. note that the string before the suffix must give m() > 0. iRtationalR$ttionalttiontctencitencetancitanceR tizerR(R)tbliR&tallitaltentlitenttelitouslitousR tizationtationtatorRtalismtivenesstivetfulnesstfultousnesstttalititivititbilititgtlogitlogN(RRRR(R((s=/usr/local/lib/python2.7/site-packages/sphinx/util/stemmer.pytstep2ÌsdcCsA|j|jdkrv|jdƒr5|jdƒq=|jdƒrT|jdƒq=|jdƒr=|jdƒq=nÇ|j|jdkr®|jd ƒr=|jdƒq=n|j|jd kr|jd ƒrã|jdƒq=|jd ƒr=|jdƒq=n8|j|jd kr=|jdƒr=|jdƒq=ndS(sLstep3() dels with -ic-, -full, -ness etc. similar strategy to step2.R ticatetictativeRtalizeR8R ticitiR)ticalRERtnessN(RRRR(R((s=/usr/local/lib/python2.7/site-packages/sphinx/util/stemmer.pytstep3òs$cCs7|j|jddkr3|jdƒr,qdSnß|j|jddkrx|jdƒr_q|jdƒrqqdSnš|j|jddkr«|jd ƒr¤qdSng|j|jdd krÞ|jd ƒr×qdSn4|j|jdd kr#|jd ƒr q|jdƒrqdSnï|j|jddkrŒ|jdƒrOq|jdƒraq|jdƒrsq|jdƒr…qdSn†|j|jddkrý|jdƒrä|j|jdksú|j|jdkräq|jdƒröqdSn|j|jddkr0|jdƒr)qdSnâ|j|jddkru|jdƒr\q|jdƒrnqdSn|j|jddkr¨|jdƒr¡qdSnj|j|jddkrÛ|jdƒrÔqdSn7|j|jdd kr|jd!ƒrqdSndS|jƒdkr3|j|_ndS("s:step4() takes off -ant, -ence etc., in context vcvc.iRR8NR0R4R2R terR RPR)tabletibleRtanttementtmentR:R tionRRGtoutismR$titiR R=tvRCR*R((RRRRR(R((s=/usr/local/lib/python2.7/site-packages/sphinx/util/stemmer.pytstep4s„%cCsÄ|j|_|j|jdkrs|jƒ}|dks]|dkrs|j|jdƒ rs|jd|_qsn|j|jdkrÀ|j|jƒrÀ|jƒdkrÀ|jd|_ndS(sYstep5() removes a final -e if m() > 1, and changes -ll to -l if m() > 1. R iR)N(RRRRRR(RR((s=/usr/local/lib/python2.7/site-packages/sphinx/util/stemmer.pytstep55s  /:cCsŒ||_||_||_|j|jdkr8|jS|jƒ|jƒ|jƒ|jƒ|jƒ|jƒ|j|j|jd!S(sñIn stem(p,i,j), p is a char pointer, and the string to be stemmed is from p[i] to p[j] inclusive. Typically i is zero and j is the offset to the last character of a string, (p[j+1] == ''). The stemmer adjusts the characters p[i] ... p[j] and returns the new end-point of the string, k. Stemming never increases word length, so i <= k <= j. To turn the stemmer into a module, declare 'stem' as extern, and delete the remainder of this file. i( RRRR+R,RNRVRbRc(RtpR R((s=/usr/local/lib/python2.7/site-packages/sphinx/util/stemmer.pytstemAs         (t__name__t __module__RRRRRRRRRR+R,RNRVRbRcRe(((s=/usr/local/lib/python2.7/site-packages/sphinx/util/stemmer.pyRs   %      ,  &  4 N(t__doc__tobjectR(((s=/usr/local/lib/python2.7/site-packages/sphinx/util/stemmer.pyts