[Zope-Checkins] CVS: Zope/lib/python/Products/PluginIndexes/TextIndexNG/tests - testSimilarityLexicon.py:1.1.2.1 testProximityLexicon.py:NONE
Andreas Jung
andreas@digicool.com
Tue, 12 Feb 2002 20:40:31 -0500
Update of /cvs-repository/Zope/lib/python/Products/PluginIndexes/TextIndexNG/tests
In directory cvs.zope.org:/tmp/cvs-serv28482
Added Files:
Tag: ajung-textindexng-branch
testSimilarityLexicon.py
Removed Files:
Tag: ajung-textindexng-branch
testProximityLexicon.py
Log Message:
renamed all 'Proximity' stuff to 'Similarity'
=== Added File Zope/lib/python/Products/PluginIndexes/TextIndexNG/tests/testSimilarityLexicon.py ===
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################
import sys, os, unittest
from Products.PluginIndexes.TextIndexNG.ProximityLexicon import ProximityLexicon
from BTrees.IIBTree import IISet, difference
import Proximity
class Tests(unittest.TestCase):
_metaphoneAscii= {
'brown' : ['braun','Brun','braune','browne'],
'quick' : ['qicke','quicke','quicky','kik','kuik'],
}
_metaphoneLatin1= {
'alle' : ['ale','ahle','aale','al'],
'einen' : ['eihnen','einnen','eihnnen'],
'zerstört' : ['zerstoert','zerstörd','zersdörd','zerzdoerd'],
}
_soundexAscii = {
'brown' : ['braun','Brun','braune','browne'],
'quick' : ['qicke','quicke','quicky','qwik'],
}
_soundexLatin1 = {
'alle' : ['ale','ahle','aale','al'],
'einen' : ['eihnen','einnen','eihnnen'],
'zerstört' : ['zerstoert','zerstörd','zersdörd','zerzdoerd'],
}
def doTest(self,s, algorithm):
""" """
self._lexicon = ProximityLexicon(algorithm)
words = s.split()
self.assertEqual(len(self._lexicon),0)
self.WIDS = {}
for word in words:
self.WIDS[word] = self._lexicon.getWordId(word)
self.assertEqual(len(self.WIDS) , len(self._lexicon._lexicon))
for word,wid in self.WIDS.items():
set = self._lexicon.get(word)
diff = difference(IISet([wid]), set)
self.assertEqual( len(diff),0, (word,wid))
def algorithmTest(self,d):
for key,words in d.items():
for word in words:
i1 = self._lexicon.get(key)
i2 = self._lexicon.get(word)
self.assertEqual( len(difference(i1,i2)), 0, ( key,word))
def testSoundexAscii(self):
""" Soundex Ascii test """
s = 'the quick brown fox jumps over the lazy dog'
self.doTest(s,'soundex')
self.algorithmTest(self._soundexAscii)
def testSoundexLatin1(self):
""" Soundex Latin1 test """
s = ( 'auf einen alle Flugplätze der Taliban zerstört worden')
self.doTest(s,'soundex')
self.algorithmTest(self._soundexLatin1)
def testSoundexUnicode(self):
""" Soundex unicode test """
s = unicode('auf einen alle Flugplätze der Taliban zerstört worden',
'latin1')
self.doTest(s,'soundex')
self.algorithmTest(self._soundexLatin1)
def testMetaphoneAscii(self):
""" Soundex Ascii test """
s = 'the quick brown fox jumps over the lazy dog'
self.doTest(s,'metaphone')
self.algorithmTest(self._metaphoneAscii)
def testMetaphoneLatin1(self):
""" Soundex Latin1 test """
s = 'auf einen alle Flugplätze der Taliban zerstört worden'
self.doTest(s,'metaphone')
self.algorithmTest(self._metaphoneLatin1)
def testMetaphoneUnicode(self):
""" Metaphone Unicode test """
s = unicode('auf einen alle Flugplätze der Taliban zerstört worden',
'latin1')
self.doTest(s,'metaphone')
def printLexicon(self):
for k,v in self._lexicon._lexicon.items():
print k.encode('latin1'),v
def test_suite():
return unittest.makeSuite(Tests)
def main():
unittest.TextTestRunner().run(test_suite())
def debug():
test_suite().debug()
def pdebug():
import pdb
pdb.run('debug()')
if __name__=='__main__':
if len(sys.argv) > 1:
globals()[sys.argv[1]]()
else:
main()
=== Removed File Zope/lib/python/Products/PluginIndexes/TextIndexNG/tests/testProximityLexicon.py ===