Beispiel #1
0
        /// <summary>
        /// Returns a string representation of the option value for the specified option. It uses the priority
        /// amongst the internal option containers.
        /// </summary>
        /// <param name="option"> the option object </param>
        /// <returns> a string representation of the option value </returns>
        public virtual string getOptionValueString(Option.Option option)
        {
            string value = null;

            for (int i = SAVEDOPTION; i <= OPTIONFILE; i++)
            {
                if (i == SAVEDOPTION)
                {
                    value = option.getStringRepresentation(savedOptionMap[option]);
                }
                else if (i == DEPENDENCIES_RESOLVED)
                {
                    value = option.getStringRepresentation(dependenciesResolvedOptionMap[option]);
                }
                else if (i == COMMANDLINE)
                {
                    value = option.getStringRepresentation(commandLineOptionMap[option]);
                }
                else if (i == OPTIONFILE)
                {
                    value = option.getStringRepresentation(optionFileOptionMap[option]);
                }
                if (!ReferenceEquals(value, null))
                {
                    return(value);
                }
            }
            return(null);
        }
Beispiel #2
0
        /// <summary>
        /// Returns the option value object for the option. It uses the priority amongst the internal
        /// option containers.
        /// </summary>
        /// <param name="option"> the option object </param>
        /// <returns> the option value object </returns>
        public virtual object getOptionValue(Option.Option option)
        {
            object value = null;

            for (int i = SAVEDOPTION; i <= OPTIONFILE; i++)
            {
                if (i == SAVEDOPTION)
                {
                    value = savedOptionMap[option];
                }
                else if (i == DEPENDENCIES_RESOLVED)
                {
                    value = dependenciesResolvedOptionMap[option];
                }
                else if (i == COMMANDLINE)
                {
                    value = commandLineOptionMap[option];
                }
                else if (i == OPTIONFILE)
                {
                    value = optionFileOptionMap[option];
                }
                if (value != null)
                {
                    return(value);
                }
            }
            return(null);
        }
        /// <summary>
        /// Returns an option based on the option flag
        /// </summary>
        /// <param name="optionflag"> the option flag </param>
        /// <returns> an option based on the option flag </returns>
        /// <exception cref="MaltChainedException"> </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public org.maltparser.core.options.option.Option getOption(String optionflag) throws org.maltparser.core.exception.MaltChainedException
        public virtual Option.Option getOption(string optionflag)
        {
            Option.Option option = flagOptionMap[optionflag];
            if (option == null)
            {
                throw new OptionException("The option flag -" + optionflag + " could not be found. ");
            }
            return(option);
        }
Beispiel #4
0
        /// <summary>
        /// Returns a string representation of the option value for an option that is in a specific option container.
        /// </summary>
        /// <param name="containerIndex">	the index of the option container. </param>
        /// <param name="option">	an option object </param>
        /// <returns> a string representation of the option value for an option that is in a specific option container. </returns>
        /// <exception cref="OptionException"> </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public String getOptionValueString(int containerIndex, org.maltparser.core.options.option.Option option) throws OptionException
        public virtual string getOptionValueString(int containerIndex, Option.Option option)
        {
            OptionContainer oc = optionContainers[containerIndex];

            if (oc == null)
            {
                throw new OptionException("The option container '" + containerIndex + "' cannot be found. ");
            }
            return(oc.getOptionValueString(option));
        }
Beispiel #5
0
        /// <summary>
        /// Returns the option value for an option.
        /// </summary>
        /// <param name="option">	an option object
        /// @return	 the option value for an option, <i>null</i> if the option value could not be found. </param>
        /// <exception cref="OptionException"> </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public Object getOptionValue(org.maltparser.core.options.option.Option option) throws OptionException
        public virtual object getOptionValue(Option.Option option)
        {
            if (optionContainers.Count == 0)
            {
                return(null);
            }
            OptionContainer oc = optionContainers[optionContainers.firstKey()];

            return(oc.getOptionValue(option));
        }
Beispiel #6
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public Object getOptionValueNoDefault(int containerIndex, String optiongroup, String optionname) throws org.maltparser.core.exception.MaltChainedException
        public virtual object getOptionValueNoDefault(int containerIndex, string optiongroup, string optionname)
        {
            Option.Option option = optionDescriptions.getOption(optiongroup, optionname);

            if (containerIndex == DEFAULTVALUE)
            {
                return(option.DefaultValueObject);
            }
            return(optionValues.getOptionValue(containerIndex, option));
        }
Beispiel #7
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void overloadOptionValue(int containerIndex, int containerType, String optiongroup, String optionname, String value) throws org.maltparser.core.exception.MaltChainedException
        public virtual void overloadOptionValue(int containerIndex, int containerType, string optiongroup, string optionname, string value)
        {
            Option.Option option = optionDescriptions.getOption(optiongroup, optionname);
            if (ReferenceEquals(value, null))
            {
                throw new OptionException("The option value is missing. ");
            }
            object ovalue = option.getValueObject(value);

            optionValues.addOptionValue(containerType, containerIndex, option, ovalue);
        }
Beispiel #8
0
        /// <summary>
        /// Returns a string representation of the option value for an option that is specified by the option group name and the option name. The
        /// container name points out the specific option container.
        /// </summary>
        /// <param name="containerIndex">	The index of the option container (0..n and -1 is default values). </param>
        /// <param name="optiongroup">	The name of the option group. </param>
        /// <param name="optionname">	The name of the option. </param>
        /// <returns> a string representation of the option value </returns>
        /// <exception cref="MaltChainedException"> </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public String getOptionValueString(int containerIndex, String optiongroup, String optionname) throws org.maltparser.core.exception.MaltChainedException
        public virtual string getOptionValueString(int containerIndex, string optiongroup, string optionname)
        {
            Option.Option option = optionDescriptions.getOption(optiongroup, optionname);
            string        value  = optionValues.getOptionValueString(containerIndex, option);

            if (ReferenceEquals(value, null))
            {
                value = option.DefaultValueString;
            }
            return(value);
        }
        /// <summary>
        /// Creates several option maps for fast access to individual options.
        /// </summary>
        /// <exception cref="OptionException"> </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void generateMaps() throws org.maltparser.core.exception.MaltChainedException
        public virtual void generateMaps()
        {
            foreach (string groupname in optionGroups.Keys)
            {
                OptionGroup og = optionGroups[groupname];
                ICollection <Option.Option> options = og.OptionList;

                foreach (Option.Option option in options)
                {
                    if (ambiguous.Contains(option.Name))
                    {
                        option.Ambiguous = true;
                        ambiguousOptionMap[option.Group.Name + "-" + option.Name] = option;
                    }
                    else
                    {
                        if (!unambiguousOptionMap.ContainsKey(option.Name))
                        {
                            unambiguousOptionMap[option.Name] = option;
                        }
                        else
                        {
                            Option.Option ambig = unambiguousOptionMap[option.Name];
                            unambiguousOptionMap.Remove(ambig);
                            ambig.Ambiguous  = true;
                            option.Ambiguous = true;
                            ambiguous.Add(option.Name);
                            ambiguousOptionMap[ambig.Group.Name + "-" + ambig.Name]   = ambig;
                            ambiguousOptionMap[option.Group.Name + "-" + option.Name] = option;
                        }
                    }
                    if (!ReferenceEquals(option.Flag, null))
                    {
                        Option.Option co = flagOptionMap[option.Flag];
                        if (co != null)
                        {
                            flagOptionMap.Remove(co);
                            co.Flag     = null;
                            option.Flag = null;
                            if (SystemLogger.logger().DebugEnabled)
                            {
                                SystemLogger.logger().debug("Ambiguous use of an option flag -> the option flag is removed for all ambiguous options\n");
                            }
                        }
                        else
                        {
                            flagOptionMap[option.Flag] = option;
                        }
                    }
                }
            }
        }
Beispiel #10
0
        /// <summary>
        /// Sets the name of the option group
        /// </summary>
        /// <param name="name">	the name of the option group </param>
        //	public void setName(String name) {
        //		this.name = name.toLowerCase();
        //	}

        /// <summary>
        /// Adds an option to the option group.
        /// </summary>
        /// <param name="option">	an option </param>
        /// <exception cref="OptionException"> </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void addOption(org.maltparser.core.options.option.Option option) throws OptionException
        public virtual void addOption(Option.Option option)
        {
            if (ReferenceEquals(option.Name, null) || option.Name.Equals(""))
            {
                throw new OptionException("The option name is null or contains the empty string. ");
            }
            else if (options.ContainsKey(option.Name.ToLower()))
            {
                throw new OptionException("The option name already exists for that option group. ");
            }
            else
            {
                options[option.Name.ToLower()] = option;
            }
        }
Beispiel #11
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void addLegalValue(String optiongroup, String optionname, String value, String desc, String target) throws org.maltparser.core.exception.MaltChainedException
        public virtual void addLegalValue(string optiongroup, string optionname, string value, string desc, string target)
        {
            Option.Option option = optionDescriptions.getOption(optiongroup, optionname);
            if (option != null)
            {
                if (option is EnumOption)
                {
                    ((EnumOption)option).addLegalValue(value, desc);
                }
                else if (option is ClassOption)
                {
                    ((ClassOption)option).addLegalValue(value, desc, target);
                }
                else if (option is StringEnumOption)
                {
                    ((StringEnumOption)option).addLegalValue(value, desc, target);
                }
            }
        }
Beispiel #12
0
        /// <summary>
        /// Parses an option container for option values.
        /// </summary>
        /// <param name="container">	a reference to an individual option container in the DOM tree. </param>
        /// <param name="containerName">	the name of this container. </param>
        /// <exception cref="OptionException"> </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void parseOptionValues(org.w3c.dom.Element container, int containerIndex) throws org.maltparser.core.exception.MaltChainedException
        private void parseOptionValues(Element container, int containerIndex)
        {
            NodeList optiongroups = container.getElementsByTagName("optiongroup");
            Element  optiongroup;

            for (int i = 0; i < optiongroups.Length; i++)
            {
                optiongroup = (Element)optiongroups.item(i);
                string groupname = optiongroup.getAttribute("groupname").ToLower();
                if (ReferenceEquals(groupname, null))
                {
                    throw new OptionException("The option group name is missing. ");
                }
                NodeList optionvalues = optiongroup.getElementsByTagName("option");
                Element  optionvalue;

                for (int j = 0; j < optionvalues.Length; j++)
                {
                    optionvalue = (Element)optionvalues.item(j);
                    string optionname = optionvalue.getAttribute("name").ToLower();
                    string value      = optionvalue.getAttribute("value");

                    if (ReferenceEquals(optionname, null))
                    {
                        throw new OptionException("The option name is missing. ");
                    }

                    Option.Option option = optionDescriptions.getOption(groupname, optionname);

                    if (option is UnaryOption)
                    {
                        value = "used";
                    }
                    if (ReferenceEquals(value, null))
                    {
                        throw new OptionException("The option value is missing. ");
                    }
                    object ovalue = option.getValueObject(value);
                    optionValues.addOptionValue(OptionContainer.OPTIONFILE, containerIndex, option, ovalue);
                }
            }
        }
Beispiel #13
0
        /// <summary>
        /// Adds an option value to an option to one of the internal option container specified by the type.
        /// </summary>
        /// <param name="type">	the internal option container </param>
        /// <param name="option">	the option object </param>
        /// <param name="value">		the option value object </param>
        /// <exception cref="OptionException"> </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: protected void addOptionValue(int type, org.maltparser.core.options.option.Option option, Object value) throws OptionException
        protected internal virtual void addOptionValue(int type, Option.Option option, object value)
        {
            if (type == SAVEDOPTION)
            {
                savedOptionMap[option] = value;
            }
            else if (type == DEPENDENCIES_RESOLVED)
            {
                dependenciesResolvedOptionMap[option] = value;
            }
            else if (type == COMMANDLINE)
            {
                commandLineOptionMap[option] = value;
            }
            else if (type == OPTIONFILE)
            {
                optionFileOptionMap[option] = value;
            }
            else
            {
                throw new OptionException("Unknown option container type");
            }
        }
Beispiel #14
0
        /// <summary>
        /// Returns true if the option is present in the specified internal option container, otherwise false.
        /// </summary>
        /// <param name="type">	the internal option container </param>
        /// <param name="option">	the option object </param>
        /// <returns> true if the option is present in the specified internal option container, otherwise false </returns>
        /// <exception cref="OptionException"> </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public boolean contains(int type, org.maltparser.core.options.option.Option option) throws OptionException
        public virtual bool contains(int type, Option.Option option)
        {
            if (type == SAVEDOPTION)
            {
                return(savedOptionMap.ContainsValue(option));
            }
            else if (type == DEPENDENCIES_RESOLVED)
            {
                return(dependenciesResolvedOptionMap.ContainsValue(option));
            }
            else if (type == COMMANDLINE)
            {
                return(commandLineOptionMap.ContainsValue(option));
            }
            else if (type == OPTIONFILE)
            {
                return(optionFileOptionMap.ContainsValue(option));
            }
            else
            {
                throw new OptionException("Unknown option container type");
            }
        }
Beispiel #15
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public Object getOptionDefaultValue(String optiongroup, String optionname) throws org.maltparser.core.exception.MaltChainedException
        public virtual object getOptionDefaultValue(string optiongroup, string optionname)
        {
            Option.Option option = optionDescriptions.getOption(optiongroup, optionname);
            return(option.DefaultValueObject);
        }
Beispiel #16
0
        /// <summary>
        /// Loads the saved options (options that are marked with <code>usage=Option.SAVE</code>).
        /// </summary>
        /// <param name="isr">	the input stream reader of the saved options file. </param>
        /// <exception cref="MaltChainedException"> </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void loadOptions(int containerIndex, java.io.InputStreamReader isr) throws org.maltparser.core.exception.MaltChainedException
        public virtual void loadOptions(int containerIndex, StreamReader isr)
        {
            try
            {
                StreamReader  br         = new StreamReader(isr);
                string        line       = null;
                Option.Option option     = null;
                Pattern       tabPattern = Pattern.compile("\t");
                while (!ReferenceEquals((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 = "";
                    }
                    else
                    {
                        if (option is ClassOption)
                        {
                            if (items[3].StartsWith("class ", StringComparison.Ordinal))
                            {
                                Type clazz = null;
                                if (PluginLoader.instance() != null)
                                {
                                    clazz = PluginLoader.instance().getClass(items[3].Substring(6));
                                }
                                if (clazz == null)
                                {
                                    clazz = Type.GetType(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);
                }

                br.Close();
            }
            catch (ClassNotFoundException e)
            {
                throw new OptionException("The class cannot be found. ", e);
            }
            catch (FormatException e)
            {
                throw new OptionException("Option container index isn't an integer value. ", e);
            }
            catch (IOException e)
            {
                throw new OptionException("Error when reading the saved options. ", e);
            }
        }
Beispiel #17
0
        /// <summary>
        /// Parses the command line arguments.
        /// </summary>
        /// <param name="args"> An array of arguments that are supplied when starting the application. </param>
        /// <exception cref="OptionException"> </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public boolean parseCommandLine(String[] args, int containerIndex) throws org.maltparser.core.exception.MaltChainedException
        public virtual bool parseCommandLine(string[] args, int containerIndex)
        {
            if (args == null || args.Length == 0)
            {
                return(false);
            }
            int i = 0;
            Dictionary <string, string> oldFlags = new Dictionary <string, string>();

            oldFlags["llo"] = "lo";
            oldFlags["lso"] = "lo";
            oldFlags["lli"] = "li";
            oldFlags["lsi"] = "li";
            oldFlags["llx"] = "lx";
            oldFlags["lsx"] = "lx";
            oldFlags["llv"] = "lv";
            oldFlags["lsv"] = "lv";
            while (i < args.Length)
            {
                Option.Option option = null;
                string        value  = null;

                /* Recognizes
                 * --optiongroup-optionname=value
                 * --optionname=value
                 * --optiongroup-optionname (unary option)
                 * --optionname (unary option)
                 */
                if (args[i].StartsWith("--", StringComparison.Ordinal))
                {
                    if (args[i].Length == 2)
                    {
                        throw new OptionException("The argument contains only '--', please check the user guide to see the correct format. ");
                    }
                    string optionstring;
                    string optiongroup;
                    string optionname;
                    int    indexEqualSign = args[i].IndexOf('=');
                    if (indexEqualSign != -1)
                    {
                        value        = args[i].Substring(indexEqualSign + 1);
                        optionstring = args[i].Substring(2, indexEqualSign - 2);
                    }
                    else
                    {
                        value        = null;
                        optionstring = args[i].Substring(2);
                    }
                    int indexMinusSign = optionstring.IndexOf('-');
                    if (indexMinusSign != -1)
                    {
                        optionname  = optionstring.Substring(indexMinusSign + 1);
                        optiongroup = optionstring.Substring(0, indexMinusSign);
                    }
                    else
                    {
                        optiongroup = null;
                        optionname  = optionstring;
                    }

                    option = optionDescriptions.getOption(optiongroup, optionname);
                    if (option is UnaryOption)
                    {
                        value = "used";
                    }
                    i++;
                }

                /* Recognizes
                 * -optionflag value
                 * -optionflag (unary option)
                 */
                else if (args[i].StartsWith("-", StringComparison.Ordinal))
                {
                    if (args[i].Length < 2)
                    {
                        throw new OptionException("Wrong use of option flag '" + args[i] + "', please check the user guide to see the correct format. ");
                    }
                    string flag = "";
                    if (oldFlags.ContainsKey(args[i].Substring(1)))
                    {
                        flag = oldFlags[args[i].Substring(1)];
                    }
                    else
                    {
                        flag = args[i].Substring(1);
                    }

                    // Error message if the old flag '-r' (root handling) is used
                    if (args[i].Substring(1).Equals("r"))
                    {
                        throw new OptionException("The flag -r (root_handling) is replaced with two flags -nr (allow_root) and -ne (allow_reduce) since MaltParser 1.7. Read more about these changes in the user guide.");
                    }

                    option = optionDescriptions.getOption(flag);

                    if (option is UnaryOption)
                    {
                        value = "used";
                    }
                    else
                    {
                        i++;
                        if (args.Length > i)
                        {
                            value = args[i];
                        }
                        else
                        {
                            throw new OptionException("Could not find the corresponding value for -" + option.Flag + ". ");
                        }
                    }
                    i++;
                }
                else
                {
                    throw new OptionException("The option should starts with a minus sign (-), error at argument '" + args[i] + "'");
                }
                object optionvalue = option.getValueObject(value);
                optionValues.addOptionValue(OptionContainer.COMMANDLINE, containerIndex, option, optionvalue);
            }
            return(true);
        }
Beispiel #18
0
        /// <summary>
        /// Adds an option value to an option to one of the internal option container specified by the type.
        /// </summary>
        /// <param name="containerType">		the type of the option container. </param>
        /// <param name="containerIndex">	the index of the option container. </param>
        /// <param name="option">	an option to add </param>
        /// <param name="value">	an option value to add
        /// @return	true if the value is added, false if the value already is in use. </param>
        /// <exception cref="OptionException"> </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: protected boolean addOptionValue(int containerType, int containerIndex, org.maltparser.core.options.option.Option option, Object value) throws OptionException
        protected internal virtual bool addOptionValue(int containerType, int containerIndex, Option.Option option, object value)
        {
            if (option == null)
            {
                throw new OptionException("The option cannot be found. ");
            }
            if (value == null)
            {
                throw new OptionException("The option value cannot be found. ");
            }

            if (!optionContainers.ContainsKey(containerIndex))
            {
                optionContainers[containerIndex] = new OptionContainer(containerIndex);
            }
            OptionContainer oc = optionContainers[containerIndex];

            if (oc == null)
            {
                throw new OptionException("The option container index " + containerIndex + " is unknown");
            }
            if (!oc.contains(containerType, option))
            {
                oc.addOptionValue(containerType, option, value);
                return(true);
            }
            return(false);
        }
        /// <summary>
        /// Parse a set of options within an option group to collect all information of individual options.
        /// </summary>
        /// <param name="group"> a reference to an individual option group in the DOM tree. </param>
        /// <param name="og"> a reference to the corresponding option group in the HashMap. </param>
        /// <exception cref="OptionException"> </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void parseOptionsDescription(org.w3c.dom.Element group, OptionGroup og) throws org.maltparser.core.exception.MaltChainedException
        private void parseOptionsDescription(Element group, OptionGroup og)
        {
            NodeList options = group.getElementsByTagName("option");
            Element  option;

            for (int i = 0; i < options.Length; i++)
            {
                option = (Element)options.item(i);
                string optionname   = option.getAttribute("name").ToLower();
                string optiontype   = option.getAttribute("type").ToLower();
                string defaultValue = option.getAttribute("default");
                string usage        = option.getAttribute("usage").ToLower();
                string flag         = option.getAttribute("flag");

                NodeList shortdescs = option.getElementsByTagName("shortdesc");
                Element  shortdesc;
                string   shortdesctext = "";
                if (shortdescs.Length == 1)
                {
                    shortdesc     = (Element)shortdescs.item(0);
                    shortdesctext = shortdesc.TextContent;
                }

                if (optiontype.Equals("string") || optiontype.Equals("bool") || optiontype.Equals("integer") || optiontype.Equals("unary"))
                {
                    Option.Option op = og.getOption(optionname);
                    if (op != null)
                    {
                        throw new OptionException("The option name '" + optionname + "' for option group '" + og.Name + "' 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.Option op = og.getOption(optionname);
                    if (op != null)
                    {
                        if (op is EnumOption && !optiontype.Equals("enum"))
                        {
                            throw new OptionException("The option name '" + optionname + "' for option group '" + og.Name + "' already exists. The existing option is of enum type, but the new option is of '" + optiontype + "' type. ");
                        }
                        if (op is ClassOption && !optiontype.Equals("class"))
                        {
                            throw new OptionException("The option name '" + optionname + "' for option group '" + og.Name + "' already exists. The existing option is of class type, but the new option is of '" + optiontype + "' type. ");
                        }
                        if (op is StringEnumOption && !optiontype.Equals("stringenum"))
                        {
                            throw new OptionException("The option name '" + optionname + "' for option group '" + og.Name + "' 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.Option op  = og.getOption(optionname);
                    EnumOption    eop = null;
                    if (op == null)
                    {
                        eop = new EnumOption(og, optionname, shortdesctext, flag, usage);
                    }
                    else
                    {
                        if (op is EnumOption)
                        {
                            eop = (EnumOption)op;
                        }
                    }

                    NodeList legalvalues = option.getElementsByTagName("legalvalue");
                    Element  legalvalue;
                    for (int j = 0; j < legalvalues.Length; j++)
                    {
                        legalvalue = (Element)legalvalues.item(j);
                        string legalvaluename = legalvalue.getAttribute("name");
                        string legalvaluetext = legalvalue.TextContent;
                        eop.addLegalValue(legalvaluename, legalvaluetext);
                    }
                    if (op == null)
                    {
                        eop.DefaultValue = defaultValue;
                        og.addOption(eop);
                    }
                }
                else if (optiontype.Equals("class"))
                {
                    Option.Option op  = og.getOption(optionname);
                    ClassOption   cop = null;
                    if (op == null)
                    {
                        cop = new ClassOption(og, optionname, shortdesctext, flag, usage);
                    }
                    else
                    {
                        if (op is ClassOption)
                        {
                            cop = (ClassOption)op;
                        }
                    }

                    NodeList legalvalues = option.getElementsByTagName("legalvalue");
                    Element  legalvalue;
                    for (int j = 0; j < legalvalues.Length; j++)
                    {
                        legalvalue = (Element)legalvalues.item(j);
                        string legalvaluename = legalvalue.getAttribute("name").ToLower();
                        string classname      = legalvalue.getAttribute("class");
                        string legalvaluetext = legalvalue.TextContent;
                        cop.addLegalValue(legalvaluename, legalvaluetext, classname);
                    }
                    if (op == null)
                    {
                        cop.DefaultValue = defaultValue;
                        og.addOption(cop);
                    }
                }
                else if (optiontype.Equals("stringenum"))
                {
                    Option.Option    op   = og.getOption(optionname);
                    StringEnumOption ueop = null;
                    if (op == null)
                    {
                        ueop = new StringEnumOption(og, optionname, shortdesctext, flag, usage);
                    }
                    else
                    {
                        if (op is StringEnumOption)
                        {
                            ueop = (StringEnumOption)op;
                        }
                    }

                    NodeList legalvalues = option.getElementsByTagName("legalvalue");
                    Element  legalvalue;
                    for (int j = 0; j < legalvalues.Length; j++)
                    {
                        legalvalue = (Element)legalvalues.item(j);
                        string legalvaluename = legalvalue.getAttribute("name").ToLower();
                        string url            = legalvalue.getAttribute("mapto");
                        string legalvaluetext = legalvalue.TextContent;
                        ueop.addLegalValue(legalvaluename, legalvaluetext, url);
                    }
                    if (op == null)
                    {
                        ueop.DefaultValue = defaultValue;
                        og.addOption(ueop);
                    }
                }
                else
                {
                    throw new OptionException("Illegal option type found in the setting file. ");
                }
            }
        }