new-words

changeset 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 6d6655d4cab6
files new-words-py.sh new-words.py
line diff
     1.1 --- a/new-words-py.sh	Tue Nov 01 20:19:18 2011 +0100
     1.2 +++ b/new-words-py.sh	Thu Nov 03 15:53:59 2011 +0100
     1.3 @@ -1,5 +1,11 @@
     1.4  #!/bin/bash
     1.5  
     1.6 +cat <<EOF
     1.7 +Please, use the script no more.
     1.8 +You can execute new-words.py directly.
     1.9 +EOF
    1.10 +exit 1
    1.11 +
    1.12  show_usage()
    1.13  {
    1.14  cat <<HELP > /dev/stderr
    1.15 @@ -134,6 +140,7 @@
    1.16  {
    1.17      [ "$PART_TO_PROCESS" == "" ] || PART_TO_PROCESS="-p $PART_TO_PROCESS"
    1.18      [ "$ALLOWED_WORDS_FILENAME" = "" ] || ALLOWED_WORDS_FILENAME="-f $ALLOWED_WORDS_FILENAME"
    1.19 +    [ "$SHOW_RANGE" = "" ] || SHOW_RANGE="-r $SHOW_RANGE"
    1.20      [ "$SHOW_RANGE_PERCENTAGE" = "" ] || SHOW_RANGE_PERCENTAGE="-R $SHOW_RANGE_PERCENTAGE"
    1.21      [ "$NON_INTERACTIVE_MODE" = YES ] && non_interactive="-n"
    1.22      [ "$STAT_ONLY" = YES ] && stat_only="-s"
    1.23 @@ -141,10 +148,10 @@
    1.24      [ "$FILTER_WORDS" = NO ] && filter_words="-N"
    1.25      [ "$GROUP_WORDS_BY_TWO" = YES ] && group_words_by_two="-2"
    1.26      [ "$GROUP_WORDS_BY_THREE" = YES ] && group_words_by_three="-3"
    1.27 +    [ "$WORDS_GROUPING" = NO ] && words_grouping="-G"
    1.28  
    1.29 -    SHOW_RANGE="$SHOW_RANGE" \
    1.30 -    WORDS_GROUPING="$WORDS_GROUPING" \
    1.31      $NEW_WORDS_PY -l "$LANGUAGE" \
    1.32 +    $SHOW_RANGE \
    1.33      $SHOW_RANGE_PERCENTAGE \
    1.34      $PART_TO_PROCESS \
    1.35      $ALLOWED_WORDS_FILENAME \
    1.36 @@ -154,6 +161,7 @@
    1.37      $filter_words \
    1.38      $group_words_by_two \
    1.39      $group_words_by_three \
    1.40 +    $words_grouping \
    1.41      -X get_words_group_words_add_stat "$1"
    1.42  }
    1.43  
     2.1 --- a/new-words.py	Tue Nov 01 20:19:18 2011 +0100
     2.2 +++ b/new-words.py	Thu Nov 03 15:53:59 2011 +0100
     2.3 @@ -119,7 +119,7 @@
     2.4  
     2.5  parser.add_option(
     2.6      "-a", "--no-marks",
     2.7 -    help="don't add marks (and don't save marks added by user)",
     2.8 +    help="don't add marks (and don't save marks added by user) [NOT IMPLEMENTED YET]",
     2.9      action="store_true",
    2.10      dest="no_marks")
    2.11  
    2.12 @@ -148,6 +148,12 @@
    2.13      dest="allowed_words")
    2.14  
    2.15  parser.add_option(
    2.16 +    "-G", "--words-grouping",
    2.17 +    help="turn off word grouping",
    2.18 +    action="store_true",
    2.19 +    dest="no_words_grouping")
    2.20 +
    2.21 +parser.add_option(
    2.22      "-X", "--function",
    2.23      help="filter through subsystem [INTERNAL]",
    2.24      action="store",
    2.25 @@ -155,13 +161,13 @@
    2.26  
    2.27  parser.add_option(
    2.28      "-m", "--merge-tag",
    2.29 -    help="merge words tagged with specified tag into the main vocabulary",
    2.30 +    help="merge words tagged with specified tag into the main vocabulary [NOT IMPLEMENTED YET]",
    2.31      action="store",
    2.32      dest="merge_tag")
    2.33  
    2.34  parser.add_option(
    2.35      "-M", "--merge-tagged",
    2.36 -    help="merge words tagged with ANY tag into the main vocabulary",
    2.37 +    help="merge words tagged with ANY tag into the main vocabulary [NOT IMPLEMENTED YET]",
    2.38      action="store_true",
    2.39      dest="merge_tagged")
    2.40  
    2.41 @@ -190,6 +196,12 @@
    2.42      dest="delete_tag")
    2.43  
    2.44  parser.add_option(
    2.45 +    "-r", "--show-range",
    2.46 +    help="show only words specified number of words",
    2.47 +    action="store",
    2.48 +    dest="show_range")
    2.49 +
    2.50 +parser.add_option(
    2.51      "-R", "--show-range-percentage",
    2.52      help="show only words that cover specified percentage of the text, skip the rest",
    2.53      action="store",
    2.54 @@ -203,7 +215,7 @@
    2.55  
    2.56  parser.add_option(
    2.57      "-S", "--voc-stats",
    2.58 -    help="show your vocabulary statistics (number of words and word groups)",
    2.59 +    help="show your vocabulary statistics (number of words and word groups) [NOT IMPLEMENTED YET]",
    2.60      action="store_true",
    2.61      dest="voc_stats")
    2.62  
    2.63 @@ -539,7 +551,7 @@
    2.64  
    2.65  
    2.66  def take_part(lines, part_description = None):
    2.67 -    if part_description == None:
    2.68 +    if part_description == None or part_description == '':
    2.69          return lines
    2.70      (start, stop, step) = parse_parts_description(part_description)
    2.71      n = len(lines)
    2.72 @@ -587,9 +599,8 @@
    2.73      if 'compressed' in config:
    2.74          compressed_wordlist = True
    2.75  
    2.76 -    show_range = os.environ.get('SHOW_RANGE', '')
    2.77 -    if show_range != '':
    2.78 -        show_range = int(show_range)
    2.79 +    if 'show_range' in config:
    2.80 +        show_range = int(config['show_range'])
    2.81      else:
    2.82          show_range = 0
    2.83  
    2.84 @@ -637,7 +648,7 @@
    2.85          words_with_freq.append((words[k], k))
    2.86  
    2.87      wgw = find_wordgroups_weights(words_with_freq, normalizator)
    2.88 -    if 'WORDS_GROUPING' in os.environ and os.environ['WORDS_GROUPING'] == 'YES':
    2.89 +    if not 'no_words_grouping' in config or not config['no_words_grouping']:
    2.90          words_with_freq = sorted(
    2.91                  words_with_freq,
    2.92                  cmp=lambda x,y:compare_word_pairs(x,y, wgw, normalizator, linked_words),
    2.93 @@ -711,6 +722,9 @@
    2.94  if options.allowed_words:
    2.95      config['allowed_words'] = options.allowed_words
    2.96  
    2.97 +if options.show_range:
    2.98 +    config['show_range'] = options.show_range
    2.99 +
   2.100  if options.show_range_percentage:
   2.101      config['show_range_percentage'] = options.show_range_percentage
   2.102  
   2.103 @@ -732,17 +746,22 @@
   2.104  if options.three_words:
   2.105      config['three_words'] = True
   2.106  
   2.107 -if options.function:
   2.108 -    function_names = {
   2.109 -        'get_words_group_words_add_stat': filter_get_words_group_words_add_stat,
   2.110 -    }
   2.111 -    if options.function in function_names:
   2.112 -        function_names[options.function](args)
   2.113 -    else:
   2.114 -        error_message("Unkown function %s.\nAvailable functions:\n%s" % (
   2.115 -            options.function, "".join(["   "+x for x in sorted(function_names.keys())])))
   2.116 -        sys.exit(1)
   2.117 +if options.no_words_grouping:
   2.118 +    config['no_words_grouping'] = True
   2.119  
   2.120 +filter_get_words_group_words_add_stat(args)
   2.121 +
   2.122 +#if options.function:
   2.123 +#    function_names = {
   2.124 +#        'get_words_group_words_add_stat': ,
   2.125 +#    }
   2.126 +#    if options.function in function_names:
   2.127 +#        function_names[options.function](args)
   2.128 +#    else:
   2.129 +#        error_message("Unkown function %s.\nAvailable functions:\n%s" % (
   2.130 +#            options.function, "".join(["   "+x for x in sorted(function_names.keys())])))
   2.131 +#        sys.exit(1)
   2.132 +#
   2.133  
   2.134  
   2.135