コード例 #1
0
        //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
        //ORIGINAL LINE: public void testMaxPosition3WithSynomyms() throws java.io.IOException
        public virtual void testMaxPosition3WithSynomyms()
        {
            foreach (bool consumeAll in new bool[]{true, false})
            {
              MockTokenizer tokenizer = new MockTokenizer(new StringReader("one two three four five"), MockTokenizer.WHITESPACE, false);
              // if we are consuming all tokens, we can use the checks, otherwise we can't
              tokenizer.EnableChecks = consumeAll;

              SynonymMap.Builder builder = new SynonymMap.Builder(true);
              builder.add(new CharsRef("one"), new CharsRef("first"), true);
              builder.add(new CharsRef("one"), new CharsRef("alpha"), true);
              builder.add(new CharsRef("one"), new CharsRef("beguine"), true);
              CharsRef multiWordCharsRef = new CharsRef();
              SynonymMap.Builder.join(new string[]{"and", "indubitably", "single", "only"}, multiWordCharsRef);
              builder.add(new CharsRef("one"), multiWordCharsRef, true);
              SynonymMap.Builder.join(new string[]{"dopple", "ganger"}, multiWordCharsRef);
              builder.add(new CharsRef("two"), multiWordCharsRef, true);
              SynonymMap synonymMap = builder.build();
              TokenStream stream = new SynonymFilter(tokenizer, synonymMap, true);
              stream = new LimitTokenPositionFilter(stream, 3, consumeAll);

              // "only", the 4th word of multi-word synonym "and indubitably single only" is not emitted, since its position is greater than 3.
              assertTokenStreamContents(stream, new string[]{"one", "first", "alpha", "beguine", "and", "two", "indubitably", "dopple", "three", "single", "ganger"}, new int[]{1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0});
            }
        }
コード例 #2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void testMaxPosition3WithSynomyms() throws java.io.IOException
        public virtual void testMaxPosition3WithSynomyms()
        {
            foreach (bool consumeAll in new bool[] { true, false })
            {
                MockTokenizer tokenizer = new MockTokenizer(new StringReader("one two three four five"), MockTokenizer.WHITESPACE, false);
                // if we are consuming all tokens, we can use the checks, otherwise we can't
                tokenizer.EnableChecks = consumeAll;

                SynonymMap.Builder builder = new SynonymMap.Builder(true);
                builder.add(new CharsRef("one"), new CharsRef("first"), true);
                builder.add(new CharsRef("one"), new CharsRef("alpha"), true);
                builder.add(new CharsRef("one"), new CharsRef("beguine"), true);
                CharsRef multiWordCharsRef = new CharsRef();
                SynonymMap.Builder.join(new string[] { "and", "indubitably", "single", "only" }, multiWordCharsRef);
                builder.add(new CharsRef("one"), multiWordCharsRef, true);
                SynonymMap.Builder.join(new string[] { "dopple", "ganger" }, multiWordCharsRef);
                builder.add(new CharsRef("two"), multiWordCharsRef, true);
                SynonymMap  synonymMap = builder.build();
                TokenStream stream     = new SynonymFilter(tokenizer, synonymMap, true);
                stream = new LimitTokenPositionFilter(stream, 3, consumeAll);

                // "only", the 4th word of multi-word synonym "and indubitably single only" is not emitted, since its position is greater than 3.
                assertTokenStreamContents(stream, new string[] { "one", "first", "alpha", "beguine", "and", "two", "indubitably", "dopple", "three", "single", "ganger" }, new int[] { 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0 });
            }
        }
コード例 #3
0
        private void add(string input, string output, bool keepOrig)
        {
            if (VERBOSE)
            {
              Console.WriteLine("  add input=" + input + " output=" + output + " keepOrig=" + keepOrig);
            }
            CharsRef inputCharsRef = new CharsRef();
            SynonymMap.Builder.join(input.Split(" +", true), inputCharsRef);

            CharsRef outputCharsRef = new CharsRef();
            SynonymMap.Builder.join(output.Split(" +", true), outputCharsRef);

            b.add(inputCharsRef, outputCharsRef, keepOrig);
        }
コード例 #4
0
ファイル: DutchAnalyzer.cs プロジェクト: Cefa68000/lucenenet
 public DutchAnalyzer(Version matchVersion, CharArraySet stopwords, CharArraySet stemExclusionTable, CharArrayMap<string> stemOverrideDict)
 {
     this.matchVersion = matchVersion;
     this.stoptable = CharArraySet.unmodifiableSet(CharArraySet.copy(matchVersion, stopwords));
     this.excltable = CharArraySet.unmodifiableSet(CharArraySet.copy(matchVersion, stemExclusionTable));
     if (stemOverrideDict.Empty || !matchVersion.onOrAfter(Version.LUCENE_31))
     {
       this.stemdict = null;
       this.origStemdict = CharArrayMap.unmodifiableMap(CharArrayMap.copy(matchVersion, stemOverrideDict));
     }
     else
     {
       this.origStemdict = null;
       // we don't need to ignore case here since we lowercase in this analyzer anyway
       StemmerOverrideFilter.Builder builder = new StemmerOverrideFilter.Builder(false);
       CharArrayMap<string>.EntryIterator iter = stemOverrideDict.entrySet().GetEnumerator();
       CharsRef spare = new CharsRef();
       while (iter.hasNext())
       {
     char[] nextKey = iter.nextKey();
     spare.copyChars(nextKey, 0, nextKey.Length);
     builder.add(spare, iter.currentValue());
       }
       try
       {
     this.stemdict = builder.build();
       }
       catch (IOException ex)
       {
     throw new Exception("can not build stem dict", ex);
       }
     }
 }