Beispiel #1
0
 /// <summary>
 /// Adds a MaltFeatureNode object to the feature list. The object will be added in the sorted feature list based on
 /// the compareTo() in MaltFeatureNode.
 /// </summary>
 /// <param name="x"> a MaltFeatureNode object </param>
 public virtual void add(MaltFeatureNode x)
 {
     if (list.Count == 0 || list[list.Count - 1].CompareTo(x) <= 0)
     {
         list.Add(x);
     }
     else
     {
         int             low  = 0;
         int             high = list.Count - 1;
         int             mid;
         MaltFeatureNode y;
         while (low <= high)
         {
             mid = (low + high) / 2;
             y   = list[mid];
             if (y.CompareTo(x) < 0)
             {
                 low = mid + 1;
             }
             else if (y.CompareTo(x) > 0)
             {
                 high = mid - 1;
             }
             else
             {
                 break;
             }
         }
         list.Insert(low, x);
     }
 }
Beispiel #2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: protected void binariesInstances2SVMFileFormat(java.io.InputStreamReader isr, java.io.OutputStreamWriter osw) throws org.maltparser.core.exception.MaltChainedException
        protected internal virtual void binariesInstances2SVMFileFormat(StreamReader isr, StreamWriter osw)
        {
            try
            {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.io.BufferedReader in = new java.io.BufferedReader(isr);
                StreamReader @in = new StreamReader(isr);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.io.BufferedWriter out = new java.io.BufferedWriter(osw);
                StreamWriter @out = new StreamWriter(osw);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.maltparser.ml.lib.FeatureList featureSet = new org.maltparser.ml.lib.FeatureList();
                FeatureList featureSet = new FeatureList();
                while (true)
                {
                    string line = @in.ReadLine();
                    if (ReferenceEquals(line, null))
                    {
                        break;
                    }
                    int y = binariesInstance(line, featureSet);
                    if (y == -1)
                    {
                        continue;
                    }
                    @out.Write(Convert.ToString(y));

                    for (int k = 0; k < featureSet.size(); k++)
                    {
                        MaltFeatureNode x = featureSet.get(k);
                        @out.BaseStream.WriteByte(' ');
                        @out.Write(Convert.ToString(x.Index));
                        @out.BaseStream.WriteByte(':');
                        @out.Write(Convert.ToString(x.Value));
                    }
                    @out.BaseStream.WriteByte('\n');
                }
                @in.Close();
                @out.Close();
            }
            catch (FormatException e)
            {
                throw new LibException("The instance file contain a non-numeric value", e);
            }
            catch (IOException e)
            {
                throw new LibException("Couldn't read from the instance file, when converting the Malt instances into LIBSVM/LIBLINEAR format. ", e);
            }
        }
Beispiel #3
0
        public virtual MaltFeatureNode[] toArray()
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final MaltFeatureNode[] nodes = new MaltFeatureNode[list.size()];
            MaltFeatureNode[] nodes = new MaltFeatureNode[list.Count];
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int len = nodes.length;
            int len = nodes.Length;

            for (int i = 0; i < len; i++)
            {
                nodes[i] = list[i];
            }
            return(nodes);
        }
Beispiel #4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private libsvm.svm_problem readProblem(java.io.InputStreamReader isr, java.util.LinkedHashMap<String, String> libOptions) throws org.maltparser.core.exception.MaltChainedException
        private svm_problem readProblem(StreamReader isr, LinkedHashMap <string, string> libOptions)
        {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final libsvm.svm_problem problem = new libsvm.svm_problem();
            svm_problem problem = new svm_problem();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final libsvm.svm_parameter param = getLibSvmParameters(libOptions);
            svm_parameter param = getLibSvmParameters(libOptions);
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.maltparser.ml.lib.FeatureList featureList = new org.maltparser.ml.lib.FeatureList();
            FeatureList featureList = new FeatureList();

            try
            {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.io.BufferedReader fp = new java.io.BufferedReader(isr);
                StreamReader fp = new StreamReader(isr);

                problem.l = NumberOfInstances;
                problem.x = new svm_node[problem.l][];
                problem.y = new double[problem.l];
                int i = 0;

                while (true)
                {
                    string line = fp.ReadLine();
                    if (ReferenceEquals(line, null))
                    {
                        break;
                    }
                    int y = binariesInstance(line, featureList);
                    if (y == -1)
                    {
                        continue;
                    }
                    try
                    {
                        problem.y[i] = y;
                        problem.x[i] = new svm_node[featureList.size()];
                        int p = 0;
                        for (int k = 0; k < featureList.size(); k++)
                        {
                            MaltFeatureNode x = featureList.get(k);
                            problem.x[i][p]       = new svm_node();
                            problem.x[i][p].value = x.Value;
                            problem.x[i][p].index = x.Index;
                            p++;
                        }
                        i++;
                    }
                    catch (IndexOutOfRangeException e)
                    {
                        throw new LibException("Couldn't read libsvm problem from the instance file. ", e);
                    }
                }
                fp.Close();
                if (param.gamma == 0)
                {
                    param.gamma = 1.0 / featureMap.FeatureCounter;
                }
            }
            catch (IOException e)
            {
                throw new LibException("Couldn't read libsvm problem from the instance file. ", e);
            }
            return(problem);
        }
Beispiel #5
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private de.bwaldvogel.liblinear.Problem readProblem(java.io.InputStreamReader isr) throws org.maltparser.core.exception.MaltChainedException
        private Problem readProblem(StreamReader isr)
        {
            Problem problem = new Problem();
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final org.maltparser.ml.lib.FeatureList featureList = new org.maltparser.ml.lib.FeatureList();
            FeatureList featureList = new FeatureList();

            if (Configuration.LoggerInfoEnabled)
            {
                Configuration.logInfoMessage("- Read all training instances.\n");
            }
            try
            {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final java.io.BufferedReader fp = new java.io.BufferedReader(isr);
                StreamReader fp = new StreamReader(isr);

                problem.bias = -1;
                problem.l    = NumberOfInstances;
                problem.x    = new FeatureNode[problem.l][];
                problem.y    = new int[problem.l];
                int i = 0;

                while (true)
                {
                    string line = fp.ReadLine();
                    if (ReferenceEquals(line, null))
                    {
                        break;
                    }
                    int y = binariesInstance(line, featureList);
                    if (y == -1)
                    {
                        continue;
                    }
                    try
                    {
                        problem.y[i] = y;
                        problem.x[i] = new FeatureNode[featureList.size()];
                        int p = 0;
                        for (int k = 0; k < featureList.size(); k++)
                        {
                            MaltFeatureNode x = featureList.get(k);
                            problem.x[i][p++] = new FeatureNode(x.Index, x.Value);
                        }
                        i++;
                    }
                    catch (IndexOutOfRangeException e)
                    {
                        throw new LibException("Couldn't read liblinear problem from the instance file. ", e);
                    }
                }
                fp.Close();
                problem.n = featureMap.size();
            }
            catch (IOException e)
            {
                throw new LibException("Cannot read from the instance file. ", e);
            }

            return(problem);
        }