コード例 #1
0
 //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
 //ORIGINAL LINE: public void testNoOverrides() throws java.io.IOException
 public virtual void testNoOverrides()
 {
     StemmerOverrideFilter.Builder builder = new StemmerOverrideFilter.Builder(true);
     Tokenizer tokenizer = new KeywordTokenizer(new StringReader("book"));
     TokenStream stream = new PorterStemFilter(new StemmerOverrideFilter(tokenizer, builder.build()));
     assertTokenStreamContents(stream, new string[] {"book"});
 }
コード例 #2
0
 //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
 //ORIGINAL LINE: public void testOverride() throws java.io.IOException
 public virtual void testOverride()
 {
     // lets make booked stem to books
     // the override filter will convert "booked" to "books",
     // but also mark it with KeywordAttribute so Porter will not change it.
     StemmerOverrideFilter.Builder builder = new StemmerOverrideFilter.Builder();
     builder.add("booked", "books");
     Tokenizer tokenizer = new KeywordTokenizer(new StringReader("booked"));
     TokenStream stream = new PorterStemFilter(new StemmerOverrideFilter(tokenizer, builder.build()));
     assertTokenStreamContents(stream, new string[] {"books"});
 }
コード例 #3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void testRandomRealisticKeyword() throws java.io.IOException
        public virtual void testRandomRealisticKeyword()
        {
            IDictionary <string, string> map = new Dictionary <string, string>();
            int numTerms = atLeast(50);

            for (int i = 0; i < numTerms; i++)
            {
                string randomRealisticUnicodeString = TestUtil.randomRealisticUnicodeString(random());
                if (randomRealisticUnicodeString.Length > 0)
                {
                    string value = TestUtil.randomSimpleString(random());
                    map[randomRealisticUnicodeString] = value.Length == 0 ? "a" : value;
                }
            }
            if (map.Count == 0)
            {
                map["booked"] = "books";
            }
            StemmerOverrideFilter.Builder         builder  = new StemmerOverrideFilter.Builder(random().nextBoolean());
            ISet <KeyValuePair <string, string> > entrySet = map.SetOfKeyValuePairs();

            foreach (KeyValuePair <string, string> entry in entrySet)
            {
                builder.add(entry.Key, entry.Value);
            }
            StemmerOverrideMap build = builder.build();

            foreach (KeyValuePair <string, string> entry in entrySet)
            {
                if (random().nextBoolean())
                {
                    Tokenizer   tokenizer = new KeywordTokenizer(new StringReader(entry.Key));
                    TokenStream stream    = new PorterStemFilter(new StemmerOverrideFilter(tokenizer, build));
                    assertTokenStreamContents(stream, new string[] { entry.Value });
                }
            }
        }
コード例 #4
0
 //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
 //ORIGINAL LINE: public void testRandomRealisticKeyword() throws java.io.IOException
 public virtual void testRandomRealisticKeyword()
 {
     IDictionary<string, string> map = new Dictionary<string, string>();
     int numTerms = atLeast(50);
     for (int i = 0; i < numTerms; i++)
     {
       string randomRealisticUnicodeString = TestUtil.randomRealisticUnicodeString(random());
       if (randomRealisticUnicodeString.Length > 0)
       {
     string value = TestUtil.randomSimpleString(random());
     map[randomRealisticUnicodeString] = value.Length == 0 ? "a" : value;
       }
     }
     if (map.Count == 0)
     {
       map["booked"] = "books";
     }
     StemmerOverrideFilter.Builder builder = new StemmerOverrideFilter.Builder(random().nextBoolean());
     ISet<KeyValuePair<string, string>> entrySet = map.SetOfKeyValuePairs();
     foreach (KeyValuePair<string, string> entry in entrySet)
     {
       builder.add(entry.Key, entry.Value);
     }
     StemmerOverrideMap build = builder.build();
     foreach (KeyValuePair<string, string> entry in entrySet)
     {
       if (random().nextBoolean())
       {
     Tokenizer tokenizer = new KeywordTokenizer(new StringReader(entry.Key));
     TokenStream stream = new PorterStemFilter(new StemmerOverrideFilter(tokenizer, build));
     assertTokenStreamContents(stream, new string[] {entry.Value});
       }
     }
 }
コード例 #5
0
        //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
        //ORIGINAL LINE: public void testRandomRealisticWhiteSpace() throws java.io.IOException
        public virtual void testRandomRealisticWhiteSpace()
        {
            IDictionary<string, string> map = new Dictionary<string, string>();
            int numTerms = atLeast(50);
            for (int i = 0; i < numTerms; i++)
            {
              string randomRealisticUnicodeString = TestUtil.randomRealisticUnicodeString(random());
              char[] charArray = randomRealisticUnicodeString.ToCharArray();
              StringBuilder builder = new StringBuilder();
              for (int j = 0; j < charArray.Length;)
              {
            int cp = char.codePointAt(charArray, j, charArray.Length);
            if (!char.IsWhiteSpace(cp))
            {
              builder.appendCodePoint(cp);
            }
            j += char.charCount(cp);
              }
              if (builder.Length > 0)
              {
            string value = TestUtil.randomSimpleString(random());
            map[builder.ToString()] = value.Length == 0 ? "a" : value;

              }
            }
            if (map.Count == 0)
            {
              map["booked"] = "books";
            }
            StemmerOverrideFilter.Builder builder = new StemmerOverrideFilter.Builder(random().nextBoolean());
            ISet<KeyValuePair<string, string>> entrySet = map.SetOfKeyValuePairs();
            StringBuilder input = new StringBuilder();
            IList<string> output = new List<string>();
            foreach (KeyValuePair<string, string> entry in entrySet)
            {
              builder.add(entry.Key, entry.Value);
              if (random().nextBoolean() || output.Count == 0)
              {
            input.Append(entry.Key).Append(" ");
            output.Add(entry.Value);
              }
            }
            Tokenizer tokenizer = new WhitespaceTokenizer(TEST_VERSION_CURRENT, new StringReader(input.ToString()));
            TokenStream stream = new PorterStemFilter(new StemmerOverrideFilter(tokenizer, builder.build()));
            assertTokenStreamContents(stream, output.ToArray());
        }
コード例 #6
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void testRandomRealisticWhiteSpace() throws java.io.IOException
        public virtual void testRandomRealisticWhiteSpace()
        {
            IDictionary <string, string> map = new Dictionary <string, string>();
            int numTerms = atLeast(50);

            for (int i = 0; i < numTerms; i++)
            {
                string        randomRealisticUnicodeString = TestUtil.randomRealisticUnicodeString(random());
                char[]        charArray = randomRealisticUnicodeString.ToCharArray();
                StringBuilder builder   = new StringBuilder();
                for (int j = 0; j < charArray.Length;)
                {
                    int cp = char.codePointAt(charArray, j, charArray.Length);
                    if (!char.IsWhiteSpace(cp))
                    {
                        builder.appendCodePoint(cp);
                    }
                    j += char.charCount(cp);
                }
                if (builder.Length > 0)
                {
                    string value = TestUtil.randomSimpleString(random());
                    map[builder.ToString()] = value.Length == 0 ? "a" : value;
                }
            }
            if (map.Count == 0)
            {
                map["booked"] = "books";
            }
            StemmerOverrideFilter.Builder         builder  = new StemmerOverrideFilter.Builder(random().nextBoolean());
            ISet <KeyValuePair <string, string> > entrySet = map.SetOfKeyValuePairs();
            StringBuilder  input  = new StringBuilder();
            IList <string> output = new List <string>();

            foreach (KeyValuePair <string, string> entry in entrySet)
            {
                builder.add(entry.Key, entry.Value);
                if (random().nextBoolean() || output.Count == 0)
                {
                    input.Append(entry.Key).Append(" ");
                    output.Add(entry.Value);
                }
            }
            Tokenizer   tokenizer = new WhitespaceTokenizer(TEST_VERSION_CURRENT, new StringReader(input.ToString()));
            TokenStream stream    = new PorterStemFilter(new StemmerOverrideFilter(tokenizer, builder.build()));

            assertTokenStreamContents(stream, output.ToArray());
        }
コード例 #7
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void testNoOverrides() throws java.io.IOException
        public virtual void testNoOverrides()
        {
            StemmerOverrideFilter.Builder builder = new StemmerOverrideFilter.Builder(true);
            Tokenizer   tokenizer = new KeywordTokenizer(new StringReader("book"));
            TokenStream stream    = new PorterStemFilter(new StemmerOverrideFilter(tokenizer, builder.build()));

            assertTokenStreamContents(stream, new string[] { "book" });
        }
コード例 #8
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void testIgnoreCase() throws java.io.IOException
        public virtual void testIgnoreCase()
        {
            // lets make booked stem to books
            // the override filter will convert "booked" to "books",
            // but also mark it with KeywordAttribute so Porter will not change it.
            StemmerOverrideFilter.Builder builder = new StemmerOverrideFilter.Builder(true);
            builder.add("boOkEd", "books");
            Tokenizer   tokenizer = new KeywordTokenizer(new StringReader("BooKeD"));
            TokenStream stream    = new PorterStemFilter(new StemmerOverrideFilter(tokenizer, builder.build()));

            assertTokenStreamContents(stream, new string[] { "books" });
        }