new-words

diff new-words.py @ 55:2a1a25e61872

new-words.py can be used without wrapper; several features are not still implemented
author Igor Chubin <igor@chub.in>
date Thu Nov 03 15:53:59 2011 +0100 (2011-11-03)
parents e25de9ea9184
children 3682038403ad
line diff
     1.1 --- a/new-words.py	Tue Nov 01 20:19:18 2011 +0100
     1.2 +++ b/new-words.py	Thu Nov 03 15:53:59 2011 +0100
     1.3 @@ -119,7 +119,7 @@
     1.4  
     1.5  parser.add_option(
     1.6      "-a", "--no-marks",
     1.7 -    help="don't add marks (and don't save marks added by user)",
     1.8 +    help="don't add marks (and don't save marks added by user) [NOT IMPLEMENTED YET]",
     1.9      action="store_true",
    1.10      dest="no_marks")
    1.11  
    1.12 @@ -148,6 +148,12 @@
    1.13      dest="allowed_words")
    1.14  
    1.15  parser.add_option(
    1.16 +    "-G", "--words-grouping",
    1.17 +    help="turn off word grouping",
    1.18 +    action="store_true",
    1.19 +    dest="no_words_grouping")
    1.20 +
    1.21 +parser.add_option(
    1.22      "-X", "--function",
    1.23      help="filter through subsystem [INTERNAL]",
    1.24      action="store",
    1.25 @@ -155,13 +161,13 @@
    1.26  
    1.27  parser.add_option(
    1.28      "-m", "--merge-tag",
    1.29 -    help="merge words tagged with specified tag into the main vocabulary",
    1.30 +    help="merge words tagged with specified tag into the main vocabulary [NOT IMPLEMENTED YET]",
    1.31      action="store",
    1.32      dest="merge_tag")
    1.33  
    1.34  parser.add_option(
    1.35      "-M", "--merge-tagged",
    1.36 -    help="merge words tagged with ANY tag into the main vocabulary",
    1.37 +    help="merge words tagged with ANY tag into the main vocabulary [NOT IMPLEMENTED YET]",
    1.38      action="store_true",
    1.39      dest="merge_tagged")
    1.40  
    1.41 @@ -190,6 +196,12 @@
    1.42      dest="delete_tag")
    1.43  
    1.44  parser.add_option(
    1.45 +    "-r", "--show-range",
    1.46 +    help="show only words specified number of words",
    1.47 +    action="store",
    1.48 +    dest="show_range")
    1.49 +
    1.50 +parser.add_option(
    1.51      "-R", "--show-range-percentage",
    1.52      help="show only words that cover specified percentage of the text, skip the rest",
    1.53      action="store",
    1.54 @@ -203,7 +215,7 @@
    1.55  
    1.56  parser.add_option(
    1.57      "-S", "--voc-stats",
    1.58 -    help="show your vocabulary statistics (number of words and word groups)",
    1.59 +    help="show your vocabulary statistics (number of words and word groups) [NOT IMPLEMENTED YET]",
    1.60      action="store_true",
    1.61      dest="voc_stats")
    1.62  
    1.63 @@ -539,7 +551,7 @@
    1.64  
    1.65  
    1.66  def take_part(lines, part_description = None):
    1.67 -    if part_description == None:
    1.68 +    if part_description == None or part_description == '':
    1.69          return lines
    1.70      (start, stop, step) = parse_parts_description(part_description)
    1.71      n = len(lines)
    1.72 @@ -587,9 +599,8 @@
    1.73      if 'compressed' in config:
    1.74          compressed_wordlist = True
    1.75  
    1.76 -    show_range = os.environ.get('SHOW_RANGE', '')
    1.77 -    if show_range != '':
    1.78 -        show_range = int(show_range)
    1.79 +    if 'show_range' in config:
    1.80 +        show_range = int(config['show_range'])
    1.81      else:
    1.82          show_range = 0
    1.83  
    1.84 @@ -637,7 +648,7 @@
    1.85          words_with_freq.append((words[k], k))
    1.86  
    1.87      wgw = find_wordgroups_weights(words_with_freq, normalizator)
    1.88 -    if 'WORDS_GROUPING' in os.environ and os.environ['WORDS_GROUPING'] == 'YES':
    1.89 +    if not 'no_words_grouping' in config or not config['no_words_grouping']:
    1.90          words_with_freq = sorted(
    1.91                  words_with_freq,
    1.92                  cmp=lambda x,y:compare_word_pairs(x,y, wgw, normalizator, linked_words),
    1.93 @@ -711,6 +722,9 @@
    1.94  if options.allowed_words:
    1.95      config['allowed_words'] = options.allowed_words
    1.96  
    1.97 +if options.show_range:
    1.98 +    config['show_range'] = options.show_range
    1.99 +
   1.100  if options.show_range_percentage:
   1.101      config['show_range_percentage'] = options.show_range_percentage
   1.102  
   1.103 @@ -732,17 +746,22 @@
   1.104  if options.three_words:
   1.105      config['three_words'] = True
   1.106  
   1.107 -if options.function:
   1.108 -    function_names = {
   1.109 -        'get_words_group_words_add_stat': filter_get_words_group_words_add_stat,
   1.110 -    }
   1.111 -    if options.function in function_names:
   1.112 -        function_names[options.function](args)
   1.113 -    else:
   1.114 -        error_message("Unkown function %s.\nAvailable functions:\n%s" % (
   1.115 -            options.function, "".join(["   "+x for x in sorted(function_names.keys())])))
   1.116 -        sys.exit(1)
   1.117 +if options.no_words_grouping:
   1.118 +    config['no_words_grouping'] = True
   1.119  
   1.120 +filter_get_words_group_words_add_stat(args)
   1.121 +
   1.122 +#if options.function:
   1.123 +#    function_names = {
   1.124 +#        'get_words_group_words_add_stat': ,
   1.125 +#    }
   1.126 +#    if options.function in function_names:
   1.127 +#        function_names[options.function](args)
   1.128 +#    else:
   1.129 +#        error_message("Unkown function %s.\nAvailable functions:\n%s" % (
   1.130 +#            options.function, "".join(["   "+x for x in sorted(function_names.keys())])))
   1.131 +#        sys.exit(1)
   1.132 +#
   1.133  
   1.134  
   1.135