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 # ====================================================================
16 from lia.analysis.AnalyzerUtils import AnalyzerUtils
17 from lucene import Version, \
18 StopAnalyzer, SimpleAnalyzer, WhitespaceAnalyzer, StandardAnalyzer
21 class AnalyzerDemo(object):
23 examples = ["The quick brown fox jumped over the lazy dogs",
24 "XY&Z Corporation - xyz@example.com"]
26 analyzers = [WhitespaceAnalyzer(),
28 StopAnalyzer(Version.LUCENE_CURRENT),
29 StandardAnalyzer(Version.LUCENE_CURRENT)]
33 # Use the embedded example strings, unless
34 # command line arguments are specified, then use those.
35 strings = cls.examples
40 for string in strings:
43 def analyze(cls, text):
45 print 'Analyzing "%s"' %(text)
47 for analyzer in cls.analyzers:
48 name = type(analyzer).__name__
50 AnalyzerUtils.displayTokens(analyzer, text)
54 main = classmethod(main)
55 analyze = classmethod(analyze)
58 if __name__ == "__main__":
60 AnalyzerDemo.main(sys.argv)