Esempio n. 1
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);
        }
Esempio n. 2
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);
                }
            }
        }
Esempio n. 3
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);
        }
Esempio n. 4
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);
            }
        }