1 # ====================================================================
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at
6 # http://www.apache.org/licenses/LICENSE-2.0
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
13 # ====================================================================
15 from unittest import TestCase, main
19 # Test reusableTokenStream, using ReusableAnalyzerBase:
20 class MyAnalyzer(PythonReusableAnalyzerBase):
22 def initReader(self, reader):
25 def createComponents(self, field, reader):
27 first = LowerCaseTokenizer(Version.LUCENE_CURRENT, reader)
28 last = StopFilter(Version.LUCENE_CURRENT, first,
29 StopAnalyzer.ENGLISH_STOP_WORDS_SET)
31 return ReusableAnalyzerBase.TokenStreamComponents(first, last)
34 class ReusableAnalyzerBaseTestCase(TestCase):
36 def testReusable(self):
38 analyzer = MyAnalyzer()
40 for method in (analyzer.reusableTokenStream, analyzer.tokenStream):
42 reader = StringReader("This is a test of the english stop analyzer")
43 stream = method("test", reader)
45 termAtt = stream.getAttribute(TermAttribute.class_)
47 while stream.incrementToken():
48 self.assert_(termAtt.term() not in StopAnalyzer.ENGLISH_STOP_WORDS_SET)
50 self.assertEquals(4, count)
53 if __name__ == "__main__":
56 if '-loop' in sys.argv:
57 sys.argv.remove('-loop')