[Checkins] SVN: Products.ZCTextIndex/trunk/ - added clear method

Yvo Schubbe y.2010 at wcm-solutions.de
Sat Aug 14 06:25:35 EDT 2010


Log message for revision 115677:
  - added clear method

Changed:
  U   Products.ZCTextIndex/trunk/CHANGES.txt
  U   Products.ZCTextIndex/trunk/src/Products/ZCTextIndex/Lexicon.py
  UU  Products.ZCTextIndex/trunk/src/Products/ZCTextIndex/interfaces.py
  U   Products.ZCTextIndex/trunk/src/Products/ZCTextIndex/tests/testLexicon.py

-=-
Modified: Products.ZCTextIndex/trunk/CHANGES.txt
===================================================================
--- Products.ZCTextIndex/trunk/CHANGES.txt	2010-08-14 10:09:18 UTC (rev 115676)
+++ Products.ZCTextIndex/trunk/CHANGES.txt	2010-08-14 10:25:35 UTC (rev 115677)
@@ -4,6 +4,8 @@
 2.13.1 (unreleased)
 -------------------
 
+- Lexicon: Added clear method.
+
 - Lexicon: Removed BBB code for instances created with Zope < 2.6.2.
 
 - Added missing namespace_packages declaration to setup.py.

Modified: Products.ZCTextIndex/trunk/src/Products/ZCTextIndex/Lexicon.py
===================================================================
--- Products.ZCTextIndex/trunk/src/Products/ZCTextIndex/Lexicon.py	2010-08-14 10:09:18 UTC (rev 115676)
+++ Products.ZCTextIndex/trunk/src/Products/ZCTextIndex/Lexicon.py	2010-08-14 10:25:35 UTC (rev 115677)
@@ -33,6 +33,13 @@
     implements(ILexicon)
 
     def __init__(self, *pipeline):
+        self.clear()
+        self._pipeline = pipeline
+
+    def clear(self):
+        """Empty the lexicon.
+        """
+        self.length = Length()
         self._wids = OIBTree()  # word -> wid
         self._words = IOBTree() # wid -> word
         # wid 0 is reserved for words that aren't in the lexicon (OOV -- out
@@ -40,8 +47,6 @@
         # we never saw before, and that isn't a known stopword (or otherwise
         # filtered out).  Returning a special wid value for OOV words is a
         # way to let clients know when an OOV word appears.
-        self.length = Length()
-        self._pipeline = pipeline
 
     def length(self):
         """Return the number of unique terms in the lexicon.

Modified: Products.ZCTextIndex/trunk/src/Products/ZCTextIndex/interfaces.py
===================================================================
--- Products.ZCTextIndex/trunk/src/Products/ZCTextIndex/interfaces.py	2010-08-14 10:09:18 UTC (rev 115676)
+++ Products.ZCTextIndex/trunk/src/Products/ZCTextIndex/interfaces.py	2010-08-14 10:25:35 UTC (rev 115677)
@@ -10,9 +10,7 @@
 # FOR A PARTICULAR PURPOSE.
 #
 ##############################################################################
-"""ZCTextIndex z3 interfaces.
-
-$Id$
+"""ZCTextIndex interfaces.
 """
 
 from zope.interface import Interface
@@ -29,6 +27,10 @@
     """Object responsible for converting text to word identifiers.
     """
 
+    def clear():
+        """Empty the lexicon.
+        """
+
     def termToWordIds(text):
         """Return a sequence of ids of the words parsed from the text.
 
@@ -59,7 +61,7 @@
         """
 
     def length():
-        """Return the number of unique term in the lexicon.
+        """Return the number of unique terms in the lexicon.
         """
 
     def get_word(wid):


Property changes on: Products.ZCTextIndex/trunk/src/Products/ZCTextIndex/interfaces.py
___________________________________________________________________
Deleted: svn:keywords
   - Id

Modified: Products.ZCTextIndex/trunk/src/Products/ZCTextIndex/tests/testLexicon.py
===================================================================
--- Products.ZCTextIndex/trunk/src/Products/ZCTextIndex/tests/testLexicon.py	2010-08-14 10:09:18 UTC (rev 115676)
+++ Products.ZCTextIndex/trunk/src/Products/ZCTextIndex/tests/testLexicon.py	2010-08-14 10:25:35 UTC (rev 115677)
@@ -86,6 +86,20 @@
 
         verifyClass(ILexicon, self._getTargetClass())
 
+    def test_clear(self):
+        from Products.ZCTextIndex.Lexicon import Splitter
+
+        lexicon = self._makeOne()
+        wids = lexicon.sourceToWordIds('foo')
+        self.assertEqual(len(lexicon._wids), 1)
+        self.assertEqual(len(lexicon._words), 1)
+        self.assertEqual(lexicon.length(), 1)
+
+        lexicon.clear()
+        self.assertEqual(len(lexicon._wids), 0)
+        self.assertEqual(len(lexicon._words), 0)
+        self.assertEqual(lexicon.length(), 0)
+
     def testSourceToWordIds(self):
         from Products.ZCTextIndex.Lexicon import Splitter
 



More information about the checkins mailing list