Пример #1
0
        public void TestListOfOutputs()
        {
            PositiveInt32Outputs  _outputs = PositiveInt32Outputs.Singleton;
            ListOfOutputs <long?> outputs  = new ListOfOutputs <long?>(_outputs);
            Builder <object>      builder  = new Builder <object>(Lucene.Net.Util.Fst.FST.INPUT_TYPE.BYTE1, outputs);

            Int32sRef scratch = new Int32sRef();

            // Add the same input more than once and the outputs
            // are merged:
            builder.Add(Util.ToInt32sRef(new BytesRef("a"), scratch), 1L);
            builder.Add(Util.ToInt32sRef(new BytesRef("a"), scratch), 3L);
            builder.Add(Util.ToInt32sRef(new BytesRef("a"), scratch), 0L);
            builder.Add(Util.ToInt32sRef(new BytesRef("b"), scratch), 17L);
            FST <object> fst = builder.Finish();

            object output = Util.Get(fst, new BytesRef("a"));

            assertNotNull(output);
            IList <long?> outputList = outputs.AsList(output);

            assertEquals(3, outputList.size());
            assertEquals(1L, outputList[0]);
            assertEquals(3L, outputList[1]);
            assertEquals(0L, outputList[2]);

            output = Util.Get(fst, new BytesRef("b"));
            assertNotNull(output);
            outputList = outputs.AsList(output);
            assertEquals(1, outputList.size());
            assertEquals(17L, outputList[0]);
        }
Пример #2
0
        public void TestListOfOutputsEmptyString()
        {
            PositiveInt32Outputs  _outputs = PositiveInt32Outputs.Singleton;
            ListOfOutputs <long?> outputs  = new ListOfOutputs <long?>(_outputs);
            Builder <object>      builder  = new Builder <object>(FST.INPUT_TYPE.BYTE1, outputs);

            Int32sRef scratch = new Int32sRef();

            builder.Add(scratch, 0L);
            builder.Add(scratch, 1L);
            builder.Add(scratch, 17L);
            builder.Add(scratch, 1L);

            builder.Add(Util.ToInt32sRef(new BytesRef("a"), scratch), 1L);
            builder.Add(Util.ToInt32sRef(new BytesRef("a"), scratch), 3L);
            builder.Add(Util.ToInt32sRef(new BytesRef("a"), scratch), 0L);
            builder.Add(Util.ToInt32sRef(new BytesRef("b"), scratch), 0L);

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

            object output = Util.Get(fst, new BytesRef(""));

            assertNotNull(output);
            IList <long?> outputList = outputs.AsList(output);

            assertEquals(4, outputList.size());
            assertEquals(0L, outputList[0]);
            assertEquals(1L, outputList[1]);
            assertEquals(17L, outputList[2]);
            assertEquals(1L, outputList[3]);

            output = Util.Get(fst, new BytesRef("a"));
            assertNotNull(output);
            outputList = outputs.AsList(output);
            assertEquals(3, outputList.size());
            assertEquals(1L, outputList[0]);
            assertEquals(3L, outputList[1]);
            assertEquals(0L, outputList[2]);

            output = Util.Get(fst, new BytesRef("b"));
            assertNotNull(output);
            outputList = outputs.AsList(output);
            assertEquals(1, outputList.size());
            assertEquals(0L, outputList[0]);
        }