Example #1
0
 public string Stemming(string str)
 {
     return(Stemmer.go(str));
 }
        /** Test program for demonstrating the Stemmer.  It reads text from a
         * a list of files, stems each word, and writes the result to standard
         * output. Note that the word stemmed is expected to be in lower case:
         * forcing lower case must be done outside the Stemmer class.
         * Usage: Stemmer file-name file-name ...
         */
        public static string go(String str)
        {
            string result = "";

            char[]  w = new char[501];
            Stemmer s = new Stemmer();

            for (int i = 0; i < 1; i++)
            {
                try
                {
                    //FileStream _in = new FileStream(args[i], FileMode.Open, FileAccess.Read);
                    StringReader _in = new StringReader(str);
                    try
                    {
                        while (true)
                        {
                            int ch = _in.Read();
                            if (Char.IsLetter((char)ch))
                            {
                                int j = 0;
                                while (true)
                                {
                                    ch   = Char.ToLower((char)ch);
                                    w[j] = (char)ch;
                                    if (j < 500)
                                    {
                                        j++;
                                    }
                                    ch = _in.Read();
                                    if (!Char.IsLetter((char)ch))
                                    {
                                        /* to test add(char ch) */
                                        for (int c = 0; c < j; c++)
                                        {
                                            s.add(w[c]);
                                        }
                                        /* or, to test add(char[] w, int j) */
                                        /* s.add(w, j); */
                                        s.stem();

                                        String u;

                                        /* and now, to test toString() : */
                                        u = s.ToString();

                                        /* to test getResultBuffer(), getResultLength() : */
                                        /* u = new String(s.getResultBuffer(), 0, s.getResultLength()); */
                                        //Console.Write(u);

                                        result += u;
                                        break;
                                    }
                                }
                            }
                            if (ch < 0)
                            {
                                break;
                            }
                            result += (char)ch;
                            //Console.Write((char)ch);
                        }
                    }
                    catch (IOException)
                    {
                        //Console.WriteLine("error reading " + args[i]);
                        break;
                    }
                }
                catch (FileNotFoundException)
                {
                    //Console.WriteLine("file " + args[i] + " not found");
                    break;
                }
            }

            return(result);
        }