Package org.maltparserx.core.options.option

Examples of org.maltparserx.core.options.option.Option


   */
  public Option getOption(String optiongroup, String optionname) throws MaltChainedException {   
    if (optionname == null || optionname.length() <= 0) {
      throw new OptionException("The option name '"+optionname+"' cannot be found" );
    }
    Option option;
    if (ambiguous.contains(optionname.toLowerCase())) {
      if (optiongroup == null || optiongroup.length() <= 0) {
        throw new OptionException("The option name '"+optionname+"' is ambiguous use option group name to distinguish the option. ");
      }
      else {
View Full Code Here


   * @param optionflag the option flag
   * @return an option based on the option flag
   * @throws MaltChainedException
   */
  public Option getOption(String optionflag) throws MaltChainedException {
    Option option = flagOptionMap.get(optionflag);
    if (option == null) {
      throw new OptionException("The option flag -"+optionflag+" could not be found. ");
    }
    return option;
  }
View Full Code Here

          shortdesc = (Element)shortdescs.item(0);
          shortdesctext = shortdesc.getTextContent();
        }
       
        if (optiontype.equals("string") || optiontype.equals("bool") || optiontype.equals("integer") || optiontype.equals("unary")) {
          Option op = og.getOption(optionname);
          if (op != null) {
            throw new OptionException("The option name '"+optionname+"' for option group '"+og.getName()+"' already exists. It is only allowed to override the class and enum option type to add legal value. ");
          }
        } else if (optiontype.equals("class") || optiontype.equals("enum") || optiontype.equals("stringenum")) {
          Option op = og.getOption(optionname);
          if (op != null) {
            if (op instanceof EnumOption && !optiontype.equals("enum")) {
              throw new OptionException("The option name '"+optionname+"' for option group '"+og.getName()+"' already exists. The existing option is of enum type, but the new option is of '"+optiontype+"' type. ");
            }
            if (op instanceof ClassOption && !optiontype.equals("class")) {
              throw new OptionException("The option name '"+optionname+"' for option group '"+og.getName()+"' already exists. The existing option is of class type, but the new option is of '"+optiontype+"' type. ");
            }
            if (op instanceof StringEnumOption && !optiontype.equals("stringenum")) {
              throw new OptionException("The option name '"+optionname+"' for option group '"+og.getName()+"' already exists. The existing option is of urlenum type, but the new option is of '"+optiontype+"' type. ");
            }
          }
        }
          if (optiontype.equals("string")) {
            og.addOption(new StringOption(og, optionname, shortdesctext, flag, usage, defaultValue));
          } else if (optiontype.equals("bool")) {
            og.addOption(new BoolOption(og, optionname, shortdesctext, flag, usage, defaultValue));
          } else if (optiontype.equals("integer")) {
            og.addOption(new IntegerOption(og, optionname, shortdesctext, flag, usage, defaultValue));
          } else if (optiontype.equals("unary")) {
            og.addOption(new UnaryOption(og, optionname, shortdesctext, flag, usage));
          } else if (optiontype.equals("enum")) {
            Option op = og.getOption(optionname);
            EnumOption eop = null;
          if (op == null) {
            eop = new EnumOption(og, optionname, shortdesctext, flag, usage);
          } else {
            if (op instanceof EnumOption) {
              eop = (EnumOption)op;
            }
          }
         
            NodeList legalvalues = option.getElementsByTagName("legalvalue");
            Element legalvalue;
            for (int j = 0; j < legalvalues.getLength(); j++) {
              legalvalue = (Element)legalvalues.item(j);
              String legalvaluename = legalvalue.getAttribute("name");
              String legalvaluetext = legalvalue.getTextContent();
              eop.addLegalValue(legalvaluename, legalvaluetext);
            }
            if (op == null) {
              eop.setDefaultValue(defaultValue);
              og.addOption(eop);
            }
           
          } else if (optiontype.equals("class") ) {
            Option op = og.getOption(optionname);
            ClassOption cop = null;
          if (op == null) {
            cop = new ClassOption(og, optionname, shortdesctext, flag, usage);
          } else {
            if (op instanceof ClassOption) {
              cop = (ClassOption)op;
            }
          }
         
            NodeList legalvalues = option.getElementsByTagName("legalvalue");
            Element legalvalue;
            for (int j = 0; j < legalvalues.getLength(); j++) {
              legalvalue = (Element)legalvalues.item(j);
              String legalvaluename = legalvalue.getAttribute("name").toLowerCase();
              String classname = legalvalue.getAttribute("class");
              String legalvaluetext = legalvalue.getTextContent();
              cop.addLegalValue(legalvaluename, legalvaluetext, classname);
            }
            if (op == null) {
              cop.setDefaultValue(defaultValue);
              og.addOption(cop);
            }
          } else if (optiontype.equals("stringenum") ) {
            Option op = og.getOption(optionname);
            StringEnumOption ueop = null;
          if (op == null) {
            ueop = new StringEnumOption(og, optionname, shortdesctext, flag, usage);
          } else {
            if (op instanceof StringEnumOption) {
View Full Code Here

              ambiguousOptionMap.put(option.getGroup().getName()+"-"+option.getName(), option);
            } else {
              if (!unambiguousOptionMap.containsKey(option.getName())) {
                unambiguousOptionMap.put(option.getName(), option);
              } else {
                Option ambig = unambiguousOptionMap.get(option.getName());
                unambiguousOptionMap.remove(ambig);
                ambig.setAmbiguous(true);
                option.setAmbiguous(true);
                ambiguous.add(option.getName());
                ambiguousOptionMap.put(ambig.getGroup().getName()+"-"+ambig.getName(), ambig);
                ambiguousOptionMap.put(option.getGroup().getName()+"-"+option.getName(), option);
              }
            }
          if (option.getFlag() != null) {
            Option co = flagOptionMap.get(option.getFlag());
            if (co != null) {
              flagOptionMap.remove(co);
              co.setFlag(null);
              option.setFlag(null);
              if (SystemLogger.logger().isDebugEnabled()) {
                SystemLogger.logger().debug("Ambiguous use of an option flag -> the option flag is removed for all ambiguous options\n");
              }
            } else {
View Full Code Here

   * @param optionname  The name of the option.
   * @return an object that contains the value of the option, <i>null</i> if the option value could not be found.
   * @throws OptionException
   */
  public Object getOptionValue(int containerIndex, String optiongroup, String optionname) throws MaltChainedException {
    Option option = optionDescriptions.getOption(optiongroup, optionname);

    if (containerIndex == OptionManager.DEFAULTVALUE) {
      return option.getDefaultValueObject();
    }
    Object value = optionValues.getOptionValue(containerIndex, option);
    if (value == null) {
      value = option.getDefaultValueObject();
    }
    return value;
  }
View Full Code Here

    }
    return value;
  }
 
  public Object getOptionDefaultValue(String optiongroup, String optionname) throws MaltChainedException {
    Option option = optionDescriptions.getOption(optiongroup, optionname);
    return option.getDefaultValueObject();
  }
View Full Code Here

    Option option = optionDescriptions.getOption(optiongroup, optionname);
    return option.getDefaultValueObject();
  }
 
  public Object getOptionValueNoDefault(int containerIndex, String optiongroup, String optionname) throws MaltChainedException {
    Option option = optionDescriptions.getOption(optiongroup, optionname);

    if (containerIndex == OptionManager.DEFAULTVALUE) {
      return option.getDefaultValueObject();
    }
    return optionValues.getOptionValue(containerIndex, option);
  }
View Full Code Here

   * @param optionname  The name of the option.
   * @return a string representation of the option value
   * @throws MaltChainedException
   */
  public String getOptionValueString(int containerIndex, String optiongroup, String optionname) throws MaltChainedException {
    Option option = optionDescriptions.getOption(optiongroup, optionname);
    String value = optionValues.getOptionValueString(containerIndex, option);
    if (value == null) {
      value = option.getDefaultValueString();
    }
    return value;
  }
View Full Code Here

   * @param optionname  the name of the option.
   * @param value the option value that should replace the current option value.
   * @throws MaltChainedException
   */
  public void overloadOptionValue(int containerIndex, String optiongroup, String optionname, String value) throws MaltChainedException {
    Option option = optionDescriptions.getOption(optiongroup, optionname);
    if (value == null) {
        throw new OptionException("The option value is missing. ");
      }
      Object ovalue = option.getValueObject(value);
      optionValues.addOptionValue(OptionContainer.DEPENDENCIES_RESOLVED, containerIndex, option, ovalue);
  }
View Full Code Here

   */
  public void loadOptions(int containerIndex, InputStreamReader isr) throws MaltChainedException {
    try {
      BufferedReader br = new BufferedReader(isr);
      String line = null;
      Option option = null;
      Pattern tabPattern = Pattern.compile("\t");
      while ((line = br.readLine()) != null) {
        String[] items = tabPattern.split(line);
        if (items.length < 3 || items.length > 4) {
          throw new OptionException("Could not load the saved option. ");
        }
        option = optionDescriptions.getOption(items[1], items[2]);
        Object ovalue;
        if (items.length == 3) {
          ovalue = new String("");
        } else {
          if (option instanceof ClassOption) {
            if (items[3].startsWith("class ")) {
              Class<?> clazz = null;
              if (PluginLoader.instance() != null) {
                clazz = PluginLoader.instance().getClass(items[3].substring(6));
              }
              if (clazz == null) {
                clazz = Class.forName(items[3].substring(6));
              }
              ovalue = option.getValueObject(((ClassOption)option).getLegalValueString(clazz));
            } else {
              ovalue = option.getValueObject(items[3]);
            }
          } else {
            ovalue = option.getValueObject(items[3]);
          }
        }
        optionValues.addOptionValue(OptionContainer.SAVEDOPTION, containerIndex, option, ovalue);
      }

View Full Code Here

TOP

Related Classes of org.maltparserx.core.options.option.Option

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.