mò )á¸Ec@sdZdkZdkZdkZdklZdklZlZdk l Z l Z l Z dk lZlZlZdklZdklZdklZd klZlZd klZd klZd klZd fd„ƒYZdfd„ƒYZ dei!fd„ƒYZ"d„Z#edƒd„Z$ddddgZ%dfd„ƒYZ&de&e i'fd„ƒYZ(de&e i)fd„ƒYZ*d e i+e i,fd!„ƒYZ-d"e-fd#„ƒYZ.d$e-fd%„ƒYZ/d&ei0fd'„ƒYZ1d(„Z2e3d)joei4d*d+ƒndS(,sZZCTextIndex unit tests. $Id: testZCTextIndex.py 40218 2005-11-18 14:39:19Z andreasjung $ N(sNotFound(s ZCTextIndexsPLexicon(s testIndexstestQueryEnginestestQueryParser(s scaled_ints SCALE_FACTORsinverse_doc_frequency(s CosineIndex(s OkapiIndex(sSplitter(sCaseNormalizersStopWordRemover(s QueryParser(s get_stopdict(s ParseErrort IndexablecBstZd„ZRS(NcCs ||_dS(N(ttexttself(RR((tI/data/zmath/zope/lib/python/Products/ZCTextIndex/tests/testZCTextIndex.pyt__init__)s(t__name__t __module__R(((RR(st Indexable2cBstZd„ZRS(NcCs||_||_dS(N(ttext1Rttext2(RRR ((RR-s (RRR(((RR,st LexiconHoldercBstZd„Zd„ZRS(NcCs ||_dS(N(tlexiconR(RR ((RR2scCsdS(Nt(R ((R((RtgetPhysicalPath5s(RRRR (((RR 1s cCs%|djo |iSnt|‚dS(NR R (R slexicon(tpathRR tNotFound(RR((RtdummyUnrestrictedTraverse8s  f0.01cCs2t||ƒ|jotd||f‚ndS(Ns%s != %s(tabstscaled1tscaled2tepsilontAssertionError(RRR((RteqBss„Here's a knocking indeed! If a man were porter of hell-gate, he should have old turning the key. knock (that made sure sure there's at least one word in common).Knock, knock, knock! Who's there, i' the name of Beelzebub? Here's a farmer, that hanged himself on the expectation of plenty: come in time; have napkins enow about you; here you'll sweat for't.sKnock, knock! Who's there, in the other devil's name? Faith, here's an equivocator, that could swear in both the scales against either scale; who committed treason enough for God's sake, yet could not equivocate to heaven: O, come in, equivocator.s±Knock, knock, knock! Who's there? Faith, here's an English tailor come hither, for stealing out of a French hose: come in, tailor; here you may roast your goose.sïKnock, knock; never at quiet! What are you? But this place is too cold for hell. I'll devil-porter it no further: I had thought to have let in some of all professions that go the primrose way to the everlasting bonfire.tZCIndexTestsBasecBsGtZd„Zd„Zd„Zd„Zd„Zd„Zd„ZRS(NcCsgtddtƒtƒtƒƒ|_t|iƒ}tdd||i ddƒ|_ |i i |_ dS(NR R tnameR( tPLexicontSplittertCaseNormalizertStopWordRemoverRR R tcallert ZCTextIndextNonet IndexFactorytzc_indextindex(RR((RtsetUpos  cCs|it|ii|ƒdS(N(Rt assertRaisest ParseErrorR!tquery(RR&((Rt parserFailure~scCsO|ii|ƒ\}}|i||ƒ|o|i|dddƒndS(Nii(RR!R&trtnumt assertEqualtn(RR&R+R(R)((Rt parserSuccessscCsòtddtƒtƒtƒƒ}t|iƒ}tdd||i ddƒ}t ddƒ}|id|ƒ|idƒ\}}|it|ƒdƒ|id ƒ\}}|it|ƒdƒ|id ƒ\}}|it|ƒd ƒdS( NR R Rs text1,text2sfoo bars alpha omegaitfoos foo alphasfoo alpha gammai(RRRRR R RRRRR R!Rtdoct index_objectR&tnbestttotalR*tlen(RR R.R0R!RR1((RttestMultipleAttributes‡s&   cCsøtddtƒtƒtƒƒ}t|iƒ}tdd||i ddƒ}t dddgƒ}|id|ƒ|id ƒ\}}|it|ƒdƒ|id ƒ\}}|it|ƒdƒ|id ƒ\}}|it|ƒd ƒdS( NR R Rs text1,text2s Hello Tims#Now is the winter of our discontents(Made glorious summer by this sun of YorkitglorioussYork TimsTuesday Tim Yorki(RRRRR R RRRRR R!RR.R/R&R0R1R*R2(RR R.R0R!RR1((RttestListAttributesœs(   cCsƒd}t|ƒ}|iid|ƒxG|iƒD]9}|djo&|ii |ƒ}|i |gƒq2q2W|i t |i idƒƒdƒ|iddƒ|iddƒ|iddƒ|iddƒ|iddƒ|id dƒ|id dƒ|id dƒ|id dƒ|id dƒ|idƒ|idƒ|idƒ|idƒ|idƒ|idƒdS(Ns'to be or not to be that is the questionitquestionsquestion AND to AND besto AND question AND besquestion AND NOT gardeniasquestion AND gardeniaitgardeniasquestion OR gardeniasquestion AND NOT to AND NOT besquestion OR to OR besquestion to besto bes to AND besto OR bes to AND NOT besto AND NOT questionsto AND NOT gardenia(RRR.RR!R/tsplittwordR t termToWordIdstwidsR*R2R"t get_wordsR,R'(RR9RR.R;((Rt testStopWords³s2   "     cCsd}ttƒ}tƒ}h} xÌttt|ƒƒD]µ\}} g}t i d|iƒƒD]5}t|ƒdjo|i|ƒ o ||q`q`~}h}xE|D]=}|i|ƒp'| i|gƒi| ƒd||RERSRAR?RLRPR0RBRFR.RURGRQRJRVRM((Rt testDocUpdateÑsN   [ !    ( RRR#R'R,R3R5R=RW(((RRms      tCosineIndexTestscBsGtZd„Zd„Zd„Zd„Zd„Zd„Zd„ZRS(NcCs+dkl}dkl}||tƒdS(N(s verifyClass(sPluggableIndexInterface(tInterface.Verifyt verifyClasst,Products.PluginIndexes.common.PluggableIndextPluggableIndexInterfaceR(RR\RZ((Rttest_z2interfacesÿs  cCsEdkl}dkl}dkl}||tƒ||tƒdS(N(sIPluggableIndex(s IZCTextIndex(s verifyClass(t!Products.PluginIndexes.interfacestIPluggableIndextProducts.ZCTextIndex.interfacest IZCTextIndextzope.interface.verifyRZR(RRaRZR_((Rttest_z3interfacess     c Cs‡ddddddddd d g |_d d d dddg|_|iƒ|iƒ|iƒ|iƒ|i}xÌdD]Ä}|ii t |ƒt |ƒƒy|iƒWnt t fj onX|idƒy|iƒWnt t fj onX|idƒy|iƒWnt j oqzX|idƒqzW|ii t |ƒt |dƒƒ|iƒ|iƒ|iƒdS(Ntcoldtdaysteatthottlottninetoldtpeasetporridgetpots(Pease porridge hot, pease porridge cold,sPease porridge in the pot,sNine days old.s In the pot cold, in the pot hot,sPease porridge, pease porridge,s Eat the lot.shot cold porridge pythonspease hot pithys)expected _ranking_tf() to fail -- reindexs*expected _ranking_idf() to fail -- reindexs.expected _ranking_queries() to fail -- reindexiÿÿÿÿ(shot cold porridge pythonspease hot pithy(RRLtdocst_ranking_indext _ranking_tft _ranking_idft_ranking_queriestvariantR!R/R2RRtKeyErrortfail(RRnRs((Rt testRankings:'       #  cCsK|i}x;tt|ƒƒD]'}|ii|dt||ƒƒqWdS(Ni(RRnRDR2RFR!R/R(RRFRn((RRo;s c Csùd d d d ddg}ddddddg}xÂtt|ƒƒD]®}|d }t||ƒ}t||i i |ƒƒg}||D]} |t| ƒq‹~} xGtt| ƒƒD]3}|i i||i|ƒ}t| ||ƒqºWqCWdS(Nf1.0f0.0f1.7f2.7799999999999998f1.73f2.21f2.3900000000000001f1.4099999999999999i( f1.0f0.0f0.0f1.0f0.0f0.0f0.0f1.7f1.7f0.0( f0.0f0.0f0.0f0.0f0.0f0.0f0.0f1.0f1.0f1.0( f0.0f1.0f0.0f0.0f0.0f1.0f1.0f0.0f0.0f0.0( f1.0f0.0f0.0f1.0f0.0f0.0f0.0f0.0f0.0f1.7( f0.0f0.0f0.0f0.0f0.0f0.0f0.0f1.7f1.7f0.0( f0.0f0.0f1.0f0.0f1.0f0.0f0.0f0.0f0.0f0.0(tl_wdttl_WdRDR2RFR>t scaled_intt scaled_WdRRR"t_get_WdRGtttwdtstjt_get_wdtRLtwdt( RR>RFR~RxRzRGRwR€R|R}((RRp@s +c Cs¹ddddddddddg }ddddddddddg }xjtt|iƒƒD]S}|i|}t|||i i |ƒƒtt ||ƒ|i i |ƒƒq^WdS(Niiif1.3899999999999999f1.95f1.1000000000000001( t word_freqstidfsRDR2RRLRFR9RR"t_get_ftRyt_get_wt(RR9RR‚RF((RRqTs$$ c Csžddddg} ddddg}dgdddgdd d!d"gd#d$d%d&d'gg}x:tt| ƒƒD]&}| |}t|i ƒi |ƒ}|i i |iƒƒ} t| t||ƒƒ|ii|ƒ\} }|it| ƒt||ƒƒh}x(||D]\}} t| ƒ||scCsFtiƒ}x3tttttfD]}|i ti |ƒƒq"W|S(N( tunittestt TestSuitetsRXR’R±R³R´tklasstaddTestt makeSuite(R¹Rº((Rt test_suiteIs  t__main__t defaultTestR½(5t__doc__R·RHt Acquisitiont zExceptionsRt Products.ZCTextIndex.ZCTextIndexRRtProducts.ZCTextIndex.testst testIndexttestQueryEnginettestQueryParsertProducts.ZCTextIndex.BaseIndexRyR‘R™t Products.ZCTextIndex.CosineIndexR²tProducts.ZCTextIndex.OkapiIndexRœtProducts.ZCTextIndex.LexiconRRRt Products.ZCTextIndex.QueryParserR‰tProducts.ZCTextIndex.StopDictR@tProducts.ZCTextIndex.ParseTreeR%RRtImplicitR RRRRtCosineIndexTestRXtOkapiIndexTestR’tTestQueryEnginetTestQueryParserR¤R±R³tTestCaseR´R½Rtmain("RRÅR·RyR´RXR²RR±RR‘RR’RHRRR™R½RÆRRRÇR@R%RœRÁR¤RR³RR RR‰R((Rt?s<           &‹|•-