43 namespace Lucene.Net.Analysis
57 private int i, j, k, k0;
58 private bool dirty =
false;
59 private const int INC = 50;
60 private const int EXTRA = 1;
72 public virtual void Reset()
80 public virtual void Add(
char ch)
82 if (b.Length <= i + EXTRA)
84 var new_b =
new char[b.Length + INC];
85 Array.Copy(b, 0, new_b, 0, b.Length);
95 public override System.String ToString()
97 return new System.String(b, 0, i);
101 public virtual int ResultLength
110 public virtual char[] ResultBuffer
117 private bool Cons(
int i)
130 return (i == k0)?
true:!Cons(i - 1);
188 private bool Vowelinstem()
191 for (i = k0; i <= j; i++)
199 private bool Doublec(
int j)
203 if (b[j] != b[j - 1])
217 private bool Cvc(
int i)
219 if (i < k0 + 2 || !Cons(i) || Cons(i - 1) || !Cons(i - 2))
224 if (ch ==
'w' || ch ==
'x' || ch ==
'y')
230 private bool Ends(System.String s)
236 for (
int i = 0; i < l; i++)
237 if (b[o + i] != s[i])
246 internal virtual void Setto(System.String s)
250 for (
int i = 0; i < l; i++)
258 internal virtual void R(System.String s)
292 else if (Ends(
"ies"))
294 else if (b[k - 1] !=
's')
302 else if ((Ends(
"ed") || Ends(
"ing")) && Vowelinstem())
314 if (ch ==
'l' || ch ==
's' || ch ==
'z')
317 else if (M() == 1 && Cvc(k))
326 if (Ends(
"y") && Vowelinstem())
551 if (Ends(
"ion") && j >= 0 && (b[j] ==
's' || b[j] ==
't'))
602 if (a > 1 || a == 1 && !Cvc(k - 1))
605 if (b[k] ==
'l' && Doublec(k) && M() > 1)
611 public virtual System.String Stem(System.String s)
613 if (Stem(s.ToCharArray(), s.Length))
625 public virtual bool Stem(
char[] word)
627 return Stem(word, word.Length);
635 public virtual bool Stem(
char[] wordBuffer,
int offset,
int wordLen)
638 if (b.Length < wordLen)
640 var new_b =
new char[wordLen + EXTRA];
643 Array.Copy(wordBuffer, offset, b, 0, wordLen);
653 public virtual bool Stem(
char[] word,
int wordLen)
655 return Stem(word, 0, wordLen);
663 public virtual bool Stem()
668 public virtual bool Stem(
int i0)
674 Step1(); Step2(); Step3(); Step4(); Step5(); Step6();
689 public static void Main(System.String[] args)
693 for (
int i = 0; i < args.Length; i++)
697 System.IO.Stream in_Renamed =
new System.IO.FileStream(args[i], System.IO.FileMode.Open, System.IO.FileAccess.Read);
698 var buffer =
new byte[1024];
700 int bufferLen = in_Renamed.Read(buffer, 0, buffer.Length);
707 if (offset < bufferLen)
708 ch = buffer[offset++];
711 bufferLen = in_Renamed.Read(buffer, 0, buffer.Length);
716 ch = buffer[offset++];
719 if (Char.IsLetter((
char) ch))
721 s.Add(Char.ToLower((
char) ch));
726 Console.Out.Write(s.ToString());
732 System.Console.Out.Write((
char) ch);
739 catch (System.IO.IOException)
741 Console.Out.WriteLine(
"error reading " + args[i]);