This is the rev 500 of the snowball SVN trunk, but modified: made abstract and introduced abstract method stem to avoid expensive reflection in filter class
示例#1
0
 protected internal virtual void  copyFrom(SnowballProgram other)
 {
     current       = other.current;
     cursor        = other.cursor;
     limit         = other.limit;
     limitBackward = other.limitBackward;
     bra           = other.bra;
     ket           = other.ket;
 }
 protected internal virtual void  copy_from(SnowballProgram other)
 {
     current = other.current;
     cursor = other.cursor;
     limit = other.limit;
     limit_backward = other.limit_backward;
     bra = other.bra;
     ket = other.ket;
 }
示例#3
0
 public Among(System.String s, int substring_i, int result, System.String methodname, SnowballProgram methodobject)
 {
     this.s_size = s.Length;
     this.s = s;
     this.substring_i = substring_i;
     this.result = result;
     if (methodname.Length == 0)
     {
         this.method = null;
     }
     else
     {
         var m = methodobject.GetType().GetTypeInfo().GetDeclaredMethod(methodname);
         if (m == null) throw new Exception();
         method = Expression.Lambda<Func<bool>>(Expression.Call(Expression.Constant(methodobject), m)).Compile();
     }
 }
示例#4
0
		public Among(System.String s, int substring_i, int result, System.String methodname, SnowballProgram methodobject)
		{
			this.s_size = s.Length;
			this.s = s;
			this.substring_i = substring_i;
			this.result = result;
			this.methodobject = methodobject;
			if (methodname.Length == 0)
			{
				this.method = null;
			}
			else
			{
				try
				{
					this.method = methodobject.GetType().GetMethod(methodname, System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.DeclaredOnly, null, new System.Type[0], null);
				}
				catch (System.MethodAccessException e)
				{
					// FIXME - debug message
					this.method = null;
				}
			}
		}
示例#5
0
文件: Among.cs 项目: stgwilli/ravendb
 public Among(System.String s, int substring_i, int result, System.String methodname, SnowballProgram methodobject)
 {
     this.s_size       = s.Length;
     this.s            = s;
     this.substring_i  = substring_i;
     this.result       = result;
     this.methodobject = methodobject;
     if (methodname.Length == 0)
     {
         this.method = null;
     }
     else
     {
         try
         {
             this.method = methodobject.GetType().GetMethod(methodname, System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.DeclaredOnly, null, new System.Type[0], null);
         }
         catch (System.MethodAccessException e)
         {
             // FIXME - debug message
             this.method = null;
         }
     }
 }
示例#6
0
 public Among(System.String s, int substring_i, int result, System.String methodname, SnowballProgram methodobject)
 {
     this.s_size      = s.Length;
     this.s           = s;
     this.substring_i = substring_i;
     this.result      = result;
     if (methodname.Length == 0)
     {
         this.method = null;
     }
     else
     {
         var m = methodobject.GetType().GetTypeInfo().GetDeclaredMethod(methodname);
         if (m == null)
         {
             throw new Exception();
         }
         method = Expression.Lambda <Func <bool> >(Expression.Call(Expression.Constant(methodobject), m)).Compile();
     }
 }
示例#7
0
        public static void  Main(System.String[] args)
        {
            if (args.Length < 2)
            {
                ExitWithUsage();
            }

            System.Type     stemClass = System.Type.GetType("SF.Snowball.Ext." + args[0] + "Stemmer");
            SnowballProgram stemmer   = (SnowballProgram)System.Activator.CreateInstance(stemClass);

            System.Reflection.MethodInfo stemMethod = stemClass.GetMethod("Stem", new Type[0]);

            System.IO.StreamReader reader;
            reader = new System.IO.StreamReader(new System.IO.FileStream(args[1], System.IO.FileMode.Open, System.IO.FileAccess.Read), System.Text.Encoding.Default);
            reader = new System.IO.StreamReader(reader.BaseStream, reader.CurrentEncoding);

            System.Text.StringBuilder input = new System.Text.StringBuilder();

            System.IO.Stream outstream = System.Console.OpenStandardOutput();

            if (args.Length > 2 && args[2].Equals("-o"))
            {
                outstream = new System.IO.FileStream(args[3], System.IO.FileMode.Create);
            }
            else if (args.Length > 2)
            {
                ExitWithUsage();
            }

            System.IO.StreamWriter output = new System.IO.StreamWriter(outstream, System.Text.Encoding.Default);
            output = new System.IO.StreamWriter(output.BaseStream, output.Encoding);

            int repeat = 1;

            if (args.Length > 4)
            {
                repeat = System.Int32.Parse(args[4]);
            }

            System.Object[] emptyArgs = new System.Object[0];
            int             character;

            while ((character = reader.Read()) != -1)
            {
                char ch = (char)character;
                if (System.Char.IsWhiteSpace(ch))
                {
                    if (input.Length > 0)
                    {
                        stemmer.SetCurrent(input.ToString());
                        for (int i = repeat; i != 0; i--)
                        {
                            stemMethod.Invoke(stemmer, (System.Object[])emptyArgs);
                        }
                        output.Write(stemmer.GetCurrent());
                        output.Write('\n');
                        input.Remove(0, input.Length - 0);
                    }
                }
                else
                {
                    input.Append(System.Char.ToLower(ch));
                }
            }
            output.Flush();
        }