[Zope-Checkins] CVS: Zope/lib/python/Products/PluginIndexes/TextIndexNG - interactiveDemo.py:1.1.2.4
Andreas Jung
andreas@digicool.com
Fri, 15 Feb 2002 18:26:28 -0500
Update of /cvs-repository/Zope/lib/python/Products/PluginIndexes/TextIndexNG
In directory cvs.zope.org:/tmp/cvs-serv1703
Modified Files:
Tag: ajung-textindexng-branch
interactiveDemo.py
Log Message:
migrated options handling from getopt to optik module
=== Zope/lib/python/Products/PluginIndexes/TextIndexNG/interactiveDemo.py 1.1.2.3 => 1.1.2.4 ===
import time
import readline
+from optik import OptionParser
histfile = os.path.expanduser('~/.pyhist')
try:
@@ -15,8 +16,6 @@
except IOError: pass
atexit.register(readline.write_history_file,histfile)
-class extra: pass
-
class TO(ExtensionClass.Base):
@@ -25,29 +24,17 @@
self.path = path
-def index_directory(dirname, verbose, timed, old):
+def index_directory(dirname, extra, verbose, timed, old):
if not dirname: raise RuntimeError,'no directory name'
- ex = extra()
- ex.useSplitter = 'ZopeSplitter'
- ex.splitterCasefolding = 1
- ex.useStemmer = None
- ex.useOperator = 'and'
- ex.lexicon = None
- ex.useGlobbing = 1
- ex.nearDistance = 5
- ex.useSimilarity = 0
- ex.stopWords = 'default_en.txt'
-# ex.characterMapping = [('a','b')]
-
CAT = Catalog.Catalog("cat")
CAT.aq_parent = TO('aq_parent')
if old:
- TI = TextIndex.TextIndex('text',ex, caller = CAT)
+ TI = TextIndex.TextIndex('text',caller = CAT)
else:
- TI = TextIndexNG.TextIndexNG('text',ex, caller = CAT, verbose=verbose)
+ TI = TextIndexNG.TextIndexNG('text', extra, caller = CAT, verbose=verbose)
if verbose: TI.debugOn()
else: TI.debugOff()
@@ -80,8 +67,8 @@
print "%d files, total size: %d" % (len(files), bytes)
print "Indexing time: %5.3lf" % diff
print 'Indexingspeed: %5.3lf KB/sec' % (1.0*bytes/diff/1024.0)
- for x in dir(ex):
- print "%25s = %s" % (x,getattr(ex,x))
+ for x in dir(extra):
+ print "%25s = %s" % (x,getattr(extra,x))
return CAT
@@ -108,22 +95,58 @@
if __name__== '__main__':
- opts,args = getopt.getopt(sys.argv[1:],'hd:',['help','directory=',\
- 'verbose','timed','old'])
+ usage = "Usage: %prog [options] "
+
+ parser = OptionParser(usage=usage)
+ parser.add_option('-d','--directory', action='store',type='string',
+ dest='directory',help='directory to be search for input files')
+
+ parser.add_option('-v','--verbose', action='store_true',
+ dest='verbose',help='be verbose')
+
+ parser.add_option('-t','--timed', action='store_true',
+ dest='timed',help='enable timed statistics')
+
+ parser.add_option('-o','--old', action='store_true',dest='old',
+ help='use old TextIndex instead TextIndexNG')
+
+ parser.add_option('-g','--globbing', action='store_true',
+ dest='extra_useGlobbing', help='enable globbing',default=0)
+
+ parser.add_option('-s','--stemmer', action='store',type='string',
+ dest='extra_useStemmer', help='use stemmer',default=None)
- directory = None
- verbose = 0
- timed = 0
- old = 0
-
- for k,v in opts:
- if k in ['-h','--help']: usage(); sys.exit(1)
- if k in ['-d','--directory']: directory = v
- if k in ['--verbose']: verbose = 1
- if k in ['--timed']: timed = 1
- if k in ['--old']: old = 1
+ parser.add_option('-n','--neardistance', action='store',type='int',
+ dest='extra_nearDistance',
+ help='max. distance between words for near search',default=5)
+
+ parser.add_option('-c','--casefolding', action='store_true',
+ dest='extra_splitterCasefolding', help='enable casefolding',
+ default=1)
+
+ parser.add_option('-w','--stopwords', action='store',type='string',
+ dest='extra_stopWords', help='name of stopword file')
+
+ parser.add_option('-z','--splitter', action='store',type='string',
+ dest='extra_useSplitter',default='ZopeSplitter',
+ help='name of splitter')
+
+ options,args = parser.parse_args()
+
+ class extra: pass
+ E = extra()
+
+ for k in dir(options):
+ if k.startswith('extra_'):
+ setattr(E,k[6:],getattr(options,k))
- cat = index_directory(directory, verbose, timed, old)
+ cat = index_directory( options.directory,
+ E,
+ options.verbose,
+ options.timed,
+ options.old
+ )
+
interactive_mode(cat)