def main(argv): parser = OptionParser( conflict_handler='resolve') # Intelligently resolve switch collisions parser.set_defaults(verbose=False, filters_to_run=[], packages=BuiltInPackages) # If any library loading switches (-l) are given, collect their names and remove them from argv argv, user_defined_libraries = filter_library_switches(argv) argv, autoloaded_libraries = filter_autoload_paths(argv) # Load built-in filters (those under BuiltInPackages) # Load user-requested filters (passed by -l on the command line) all_libraries = BuiltInPackages + user_defined_libraries + autoloaded_libraries tracer = TraceCore(libraries=all_libraries) # For each available filter, allow it to be invoked with switches on the command line for filter in tracer.available_filters_dict.values(): add_filter_to_optparser(parser, filter) # Load built-in optparse switches register_builtin_switches(parser) if len(argv) <= 1: parser.print_help() sys.exit(1) # Perform option parse, check for user-requested filter classes opts, remaining_args = parser.parse_args(argv) # Done with parser parser.destroy() if opts.debug: config.set(debug=True) # Set verbose switch if given on command line tracer.verbose = opts.verbose tracer.break_on_exception = opts.break_on_exception # Set override Reader if given on command line tracer.reader_class_name = opts.reader_class_name # Take remaining arguments as input file names files = remaining_args[1:] # remaining_args[0] seems to be sys.argv[0] # If switch -L was passed, dump out all available filter names and quit if opts.do_list_filters: tracer.list_filters() sys.exit(0) # Run requested filters try: tracer.run(opts.filters_to_run, files) except RuntimeError, e: err('RuntimeError: %s', e) sys.exit(1)
def main(argv): parser = OptionParser(conflict_handler='resolve') # Intelligently resolve switch collisions parser.set_defaults(verbose=False, filters_to_run=[], packages=BuiltInPackages) # If any library loading switches (-l) are given, collect their names and remove them from argv argv, user_defined_libraries = filter_library_switches(argv) argv, autoloaded_libraries = filter_autoload_paths(argv) # Load built-in filters (those under BuiltInPackages) # Load user-requested filters (passed by -l on the command line) all_libraries = BuiltInPackages + user_defined_libraries + autoloaded_libraries tracer = TraceCore(libraries=all_libraries) # For each available filter, allow it to be invoked with switches on the command line for filter in tracer.available_filters_dict.values(): add_filter_to_optparser(parser, filter) # Load built-in optparse switches register_builtin_switches(parser) if len(argv) <= 1: parser.print_help() sys.exit(1) # Perform option parse, check for user-requested filter classes opts, remaining_args = parser.parse_args(argv) # Done with parser parser.destroy() if opts.debug: config.set(debug=True) # Set verbose switch if given on command line tracer.verbose = opts.verbose tracer.break_on_exception = opts.break_on_exception # Set override Reader if given on command line tracer.reader_class_name = opts.reader_class_name # Take remaining arguments as input file names files = remaining_args[1:] # remaining_args[0] seems to be sys.argv[0] # If switch -L was passed, dump out all available filter names and quit if opts.do_list_filters: tracer.list_filters() sys.exit(0) # Run requested filters try: tracer.run(opts.filters_to_run, files) except RuntimeError, e: err('RuntimeError: %s', e) sys.exit(1)
# Chinese CCGbank conversion # ========================== # (c) 2008-2012 Daniel Tse <*****@*****.**> # University of Sydney # Use of this software is governed by the attached "Chinese CCGbank converter Licence Agreement" # supplied in the Chinese CCGbank conversion distribution. If the LICENCE file is missing, please # notify the maintainer Daniel Tse <*****@*****.**>. import sys, copy from munge.util.config import config config.set(show_vars=True, curly_vars=True) from munge.cats.headed.nodes import AtomicCategory from munge.cats.headed.parse import * from munge.cats.cat_defs import NP, N from munge.util.err_utils import * from munge.trees.traverse import leaves from apps.util.echo import echo def variables(): '''Returns an iterator over variable names. The first variable name returned is _, for the outermost variable.''' # C&C only supports up to variable F # We add variables G, H to prevent two failures # (5:27(12) and 27:97(12)) which run out of variables return iter('_YZWVUTRQABCDEFGH') def is_modifier(cat):