[Zope-CVS] CVS: Products/ZCTextIndex/tests - testLexicon.py:1.1.2.9
Guido van Rossum
guido@python.org
Fri, 3 May 2002 13:10:11 -0400
Update of /cvs-repository/Products/ZCTextIndex/tests
In directory cvs.zope.org:/tmp/cvs-serv9684/tests
Modified Files:
Tag: TextIndexDS9-branch
testLexicon.py
Log Message:
Don't use the cumbersome and broken ZopeSplitter.
re.findall(r"\w+") is fast enough.
=== Products/ZCTextIndex/tests/testLexicon.py 1.1.2.8 => 1.1.2.9 ===
from Products.ZCTextIndex.Lexicon import Lexicon
-from Products.ZCTextIndex.Splitter import Splitter
-from Products.PluginIndexes.TextIndex.Splitter.ZopeSplitter.ZopeSplitter \
- import ZopeSplitter
+from Products.ZCTextIndex.ZCTextIndex import Splitter, CaseNormalizer
class StupidPipelineElement:
def __init__(self, fromword, toword):
@@ -69,43 +67,43 @@
class Test(TestCase):
def testSourceToWordIds(self):
- lexicon = Lexicon(Splitter(ZopeSplitter))
+ lexicon = Lexicon(Splitter())
wids = lexicon.sourceToWordIds('cats and dogs')
self.assertEqual(wids, [1, 2, 3])
def testTermToWordIds(self):
- lexicon = Lexicon(Splitter(ZopeSplitter))
+ lexicon = Lexicon(Splitter())
wids = lexicon.sourceToWordIds('cats and dogs')
wids = lexicon.termToWordIds('dogs')
self.assertEqual(wids, [3])
def testMissingTermToWordIds(self):
- lexicon = Lexicon(Splitter(ZopeSplitter))
+ lexicon = Lexicon(Splitter())
wids = lexicon.sourceToWordIds('cats and dogs')
wids = lexicon.termToWordIds('boxes')
self.assertEqual(wids, [])
def testOnePipelineElement(self):
- lexicon = Lexicon(Splitter(ZopeSplitter),
+ lexicon = Lexicon(Splitter(),
(StupidPipelineElement('dogs', 'fish'),),)
wids = lexicon.sourceToWordIds('cats and dogs')
wids = lexicon.termToWordIds('fish')
self.assertEqual(wids, [3])
def testSplitterAdaptorFold(self):
- lexicon = Lexicon(Splitter(ZopeSplitter, casefolding=1))
+ lexicon = Lexicon(Splitter(), [CaseNormalizer()])
wids = lexicon.sourceToWordIds('CATS and dogs')
wids = lexicon.termToWordIds('cats and dogs')
self.assertEqual(wids, [1, 2, 3])
def testSplitterAdaptorNofold(self):
- lexicon = Lexicon(Splitter(ZopeSplitter, casefolding=0))
+ lexicon = Lexicon(Splitter())
wids = lexicon.sourceToWordIds('CATS and dogs')
wids = lexicon.termToWordIds('cats and dogs')
self.assertEqual(wids, [2, 3])
def testTwoElementPipeline(self):
- lexicon = Lexicon(Splitter(ZopeSplitter),
+ lexicon = Lexicon(Splitter(),
(StupidPipelineElement('cats', 'fish'),
WackyReversePipelineElement('fish')))
wids = lexicon.sourceToWordIds('cats and dogs')
@@ -113,7 +111,7 @@
self.assertEqual(wids, [1])
def testThreeElementPipeline(self):
- lexicon = Lexicon(Splitter(ZopeSplitter),
+ lexicon = Lexicon(Splitter(),
(StopWordPipelineElement({'and':1}),
StupidPipelineElement('dogs', 'fish'),
WackyReversePipelineElement('fish')))