A TokenFilter which applies a Pattern to each token in the stream, replacing match occurances with the specified replacement string.

Note: Depending on the input and the pattern used and the input TokenStream, this TokenFilter may produce Tokens whose text is the empty string.

상속: TokenFilter
예제 #1
0
        public virtual void TestStripAll()
        {
            string      input = "aabfooaabfooabfoob ab caaaaaaaaab";
            TokenStream ts    = new PatternReplaceFilter(new MockTokenizer(new StringReader(input), MockTokenizer.WHITESPACE, false), new Regex("a*b", RegexOptions.Compiled), null, true);

            AssertTokenStreamContents(ts, new string[] { "foofoofoo", "", "c" });
        }
예제 #2
0
            protected internal override TokenStreamComponents CreateComponents(string fieldName, TextReader reader)
            {
                Tokenizer   tokenizer = new MockTokenizer(reader, MockTokenizer.WHITESPACE, false);
                TokenStream filter    = new PatternReplaceFilter(tokenizer, new Regex("a", RegexOptions.Compiled), "b", false);

                return(new TokenStreamComponents(tokenizer, filter));
            }
 public virtual void TestReplaceAllWithBackRef()
 {
     string input = "aabfooaabfooabfoob ab caaaaaaaaab";
     // LUCENENET NOTE: In .NET we don't need to escape $ like \\$$ (Java), it is like $$
     TokenStream ts = new PatternReplaceFilter(new MockTokenizer(new StringReader(input), MockTokenizer.WHITESPACE, false), new Regex("(a*)b", RegexOptions.Compiled), /*"$1\\$$"*/ "$1$$", true);
     AssertTokenStreamContents(ts, new string[] { "aa$fooaa$fooa$foo$", "a$", "caaaaaaaaa$" });
 }
예제 #4
0
        public virtual void TestReplaceAllWithBackRef()
        {
            string input = "aabfooaabfooabfoob ab caaaaaaaaab";
            // LUCENENET NOTE: In .NET we don't need to escape $ like \\$$ (Java), it is like $$
            TokenStream ts = new PatternReplaceFilter(new MockTokenizer(new StringReader(input), MockTokenizer.WHITESPACE, false), new Regex("(a*)b", RegexOptions.Compiled), /*"$1\\$$"*/ "$1$$", true);

            AssertTokenStreamContents(ts, new string[] { "aa$fooaa$fooa$foo$", "a$", "caaaaaaaaa$" });
        }
        public virtual void TestRandomStrings()
        {
            Analyzer a = Analyzer.NewAnonymous(createComponents: (fieldName, reader) =>
            {
                Tokenizer tokenizer = new MockTokenizer(reader, MockTokenizer.WHITESPACE, false);
                TokenStream filter  = new PatternReplaceFilter(tokenizer, new Regex("a", RegexOptions.Compiled), "b", false);
                return(new TokenStreamComponents(tokenizer, filter));
            });

            CheckRandomData(Random, a, 1000 * RandomMultiplier);

            Analyzer b = Analyzer.NewAnonymous(createComponents: (fieldName, reader) =>
            {
                Tokenizer tokenizer = new MockTokenizer(reader, MockTokenizer.WHITESPACE, false);
                TokenStream filter  = new PatternReplaceFilter(tokenizer, new Regex("a", RegexOptions.Compiled), "b", true);
                return(new TokenStreamComponents(tokenizer, filter));
            });

            CheckRandomData(Random, b, 1000 * RandomMultiplier);
        }
 public override TokenStreamComponents CreateComponents(string fieldName, TextReader reader)
 {
     Tokenizer tokenizer = new MockTokenizer(reader, MockTokenizer.WHITESPACE, false);
     TokenStream filter = new PatternReplaceFilter(tokenizer, new Regex("a", RegexOptions.Compiled), "b", false);
     return new TokenStreamComponents(tokenizer, filter);
 }
 public virtual void TestStripAll()
 {
     string input = "aabfooaabfooabfoob ab caaaaaaaaab";
     TokenStream ts = new PatternReplaceFilter(new MockTokenizer(new StringReader(input), MockTokenizer.WHITESPACE, false), new Regex("a*b", RegexOptions.Compiled), null, true);
     AssertTokenStreamContents(ts, new string[] { "foofoofoo", "", "c" });
 }