[Zope-CVS] CVS: Products/ZCTextIndex/tests - testLexicon.py:1.1.2.4
Barry Warsaw
barry@wooz.org
Wed, 1 May 2002 11:40:53 -0400
Update of /cvs-repository/Products/ZCTextIndex/tests
In directory cvs.zope.org:/tmp/cvs-serv4769
Modified Files:
Tag: TextIndexDS9-branch
testLexicon.py
Log Message:
Added a test for 3-element pipeline, and stopwords.
=== Products/ZCTextIndex/tests/testLexicon.py 1.1.2.3 => 1.1.2.4 ===
return res
+class StopWordPipelineElement:
+ def __init__(self, stopdict={}):
+ self.__stopdict = stopdict
+
+ def __call__(self, seq):
+ res = []
+ for term in seq:
+ if self.__stopdict.get(term):
+ continue
+ else:
+ res.append(term)
+ return res
+
class SplitterAdaptor:
- def __init__(self, splitterclass, synstop=None, casefolding=0):
+ def __init__(self, splitterclass, casefolding=0):
self.__class = splitterclass
- self.__synstop = synstop
self.__casefolding = casefolding
def __call__(self, text):
- return self.__class(text,
- synstop=self.__synstop,
- casefolding=self.__casefolding)
+ return self.__class(text, casefolding=self.__casefolding)
class Test(TestCase):
@@ -83,32 +93,41 @@
wids = lexicon.termToWordIds('boxes')
self.assertEqual(wids, [])
- def testStupidPipelineElement(self):
+ def testOnePipelineElement(self):
lexicon = Lexicon(ZopeSplitter,
(StupidPipelineElement('dogs', 'fish'),),)
wids = lexicon.sourceToWordIds('cats and dogs')
wids = lexicon.termToWordIds('fish')
self.assertEqual(wids, [3])
- def testBiggerPipeline(self):
+ def testSplitterAdaptorFold(self):
lexicon = Lexicon(SplitterAdaptor(ZopeSplitter, casefolding=1))
wids = lexicon.sourceToWordIds('CATS and dogs')
wids = lexicon.termToWordIds('cats and dogs')
self.assertEqual(wids, [1, 2, 3])
- def testBiggerPipelineNofold(self):
+ def testSplitterAdaptorNofold(self):
lexicon = Lexicon(SplitterAdaptor(ZopeSplitter))
wids = lexicon.sourceToWordIds('CATS and dogs')
wids = lexicon.termToWordIds('cats and dogs')
self.assertEqual(wids, [2, 3])
- def testLongerPipeline(self):
+ def testTwoElementPipeline(self):
lexicon = Lexicon(ZopeSplitter,
(StupidPipelineElement('cats', 'fish'),
WackyReversePipelineElement('fish')))
wids = lexicon.sourceToWordIds('cats and dogs')
wids = lexicon.termToWordIds('hsif')
self.assertEqual(wids, [1])
+
+ def testThreeElementPipeline(self):
+ lexicon = Lexicon(ZopeSplitter,
+ (StopWordPipelineElement({'and':1}),
+ StupidPipelineElement('dogs', 'fish'),
+ WackyReversePipelineElement('fish')))
+ wids = lexicon.sourceToWordIds('cats and dogs')
+ wids = lexicon.termToWordIds('hsif')
+ self.assertEqual(wids, [2])
def test_suite():