Example #1
0
        private CharsRef NewStem(char[] buffer, int length, Int32sRef forms, int formID)
        {
            string exception;

            if (dictionary.hasStemExceptions)
            {
                int exceptionID = forms.Int32s[forms.Offset + formID + 1];
                if (exceptionID > 0)
                {
                    exception = dictionary.GetStemException(exceptionID);
                }
                else
                {
                    exception = null;
                }
            }
            else
            {
                exception = null;
            }

            if (dictionary.needsOutputCleaning)
            {
                scratchSegment.Length = 0;
                if (exception != null)
                {
                    scratchSegment.Append(exception);
                }
                else
                {
                    scratchSegment.Append(buffer, 0, length);
                }
                try
                {
                    Dictionary.ApplyMappings(dictionary.oconv, scratchSegment);
                }
                catch (Exception bogus) when(bogus.IsIOException())
                {
                    throw RuntimeException.Create(bogus);
                }
                char[] cleaned = new char[scratchSegment.Length];
                scratchSegment.CopyTo(0, cleaned, 0, cleaned.Length);
                return(new CharsRef(cleaned, 0, cleaned.Length));
            }
            else
            {
                if (exception != null)
                {
                    return(new CharsRef(exception));
                }
                else
                {
                    return(new CharsRef(buffer, 0, length));
                }
            }
        }
Example #2
0
        public virtual void TestReplacements()
        {
            Outputs <CharsRef> outputs     = CharSequenceOutputs.Singleton;
            Builder <CharsRef> builder     = new Builder <CharsRef>(FST.INPUT_TYPE.BYTE2, outputs);
            Int32sRef          scratchInts = new Int32sRef();

            // a -> b
            Lucene.Net.Util.Fst.Util.ToUTF16("a", scratchInts);
            builder.Add(scratchInts, new CharsRef("b"));

            // ab -> c
            Lucene.Net.Util.Fst.Util.ToUTF16("ab", scratchInts);
            builder.Add(scratchInts, new CharsRef("c"));

            // c -> de
            Lucene.Net.Util.Fst.Util.ToUTF16("c", scratchInts);
            builder.Add(scratchInts, new CharsRef("de"));

            // def -> gh
            Lucene.Net.Util.Fst.Util.ToUTF16("def", scratchInts);
            builder.Add(scratchInts, new CharsRef("gh"));

            FST <CharsRef> fst = builder.Finish();

            StringBuilder sb = new StringBuilder("atestanother");

            Dictionary.ApplyMappings(fst, sb);
            assertEquals("btestbnother", sb.ToString());

            sb = new StringBuilder("abtestanother");
            Dictionary.ApplyMappings(fst, sb);
            assertEquals("ctestbnother", sb.ToString());

            sb = new StringBuilder("atestabnother");
            Dictionary.ApplyMappings(fst, sb);
            assertEquals("btestcnother", sb.ToString());

            sb = new StringBuilder("abtestabnother");
            Dictionary.ApplyMappings(fst, sb);
            assertEquals("ctestcnother", sb.ToString());

            sb = new StringBuilder("abtestabcnother");
            Dictionary.ApplyMappings(fst, sb);
            assertEquals("ctestcdenother", sb.ToString());

            sb = new StringBuilder("defdefdefc");
            Dictionary.ApplyMappings(fst, sb);
            assertEquals("ghghghde", sb.ToString());
        }
Example #3
0
 private CharsRef NewStem(char[] buffer, int length)
 {
     if (dictionary.needsOutputCleaning)
     {
         scratchSegment.Length = 0;
         scratchSegment.Append(buffer, 0, length);
         try
         {
             Dictionary.ApplyMappings(dictionary.oconv, scratchSegment);
         }
         catch (IOException bogus)
         {
             throw new Exception(bogus.Message, bogus);
         }
         char[] cleaned = new char[scratchSegment.Length];
         scratchSegment.CopyTo(0, cleaned, 0, cleaned.Length);
         return(new CharsRef(cleaned, 0, cleaned.Length));
     }
     else
     {
         return(new CharsRef(buffer, 0, length));
     }
 }