예제 #1
0
  private static String readStringValue(Mutable<Integer> index, String option_string) {
    int eq_index = option_string.indexOf(',', index.get());

    if (eq_index == -1) {
      eq_index = option_string.length();
    }

    String value = option_string.substring(index.get(), eq_index);
    index.set(eq_index + 1);
    return value;
  }
예제 #2
0
  private static KeyType readKey(Mutable<Integer> index, String option_string) {
    int eq_index = option_string.indexOf('=', index.get());
    int co_index = option_string.indexOf(',', index.get());

    if (eq_index == -1 || (co_index < eq_index && co_index != -1)) {
      return KeyType.filename;
    }

    String key_string = option_string.substring(index.get(), eq_index);
    index.set(eq_index + 1);

    KeyType type = KeyType.valueOf(key_string);

    return type;
  }
예제 #3
0
  public static MorphDictionaryOptions parse(String option_string, boolean set_defaults) {
    MorphDictionaryOptions options = new MorphDictionaryOptions();

    if (set_defaults) {
      options.setDefaultOptions();
    }

    Mutable<Integer> index = new Mutable<Integer>(0);

    while (index.get() < option_string.length()) {
      KeyType key = readKey(index, option_string);

      try {

        switch (key) {
          case filename:
            options.filename_ = readStringValue(index, option_string);
            break;
          case type:
            options.type_ = readTypeValue(index, option_string);
            break;
          case indexes:
            options.indexes_ = readArrayValue(index, option_string);
            break;
          case norm:
            options.norm_ = readModeValue(index, option_string);
            break;
          case limit:
            options.limit_ = readIntValue(index, option_string);
            break;
          case reverse:
            options.reverse_ = readBooleanValue(index, option_string);
            break;
          case dense:
            options.dense_ = readBooleanValue(index, option_string);
            break;
        }

      } catch (Exception e) {
        System.err.println("Error: Couldn't parse string: " + option_string + " because of:");
        throw new RuntimeException(e);
      }
    }

    return options;
  }
예제 #4
0
  private static int[] readArrayValue(Mutable<Integer> index, String option_string) {

    String[] array = StringUtils.parseArray(option_string, index);

    int[] indexes = new int[array.length];
    for (int i = 0; i < array.length; i++) {
      indexes[i] = Integer.parseInt(array[i]);

      //			if (indexes[i] < 1) {
      //				throw new InvalidParameterException("Index must be > 0!");
      //			}

    }

    Arrays.sort(indexes);

    if (index.get() < option_string.length()) {
      if (option_string.charAt(index.get()) == ',') {
        index.set(index.get() + 1);
      }
    }

    return indexes;
  }