コード例 #1
0
ファイル: TestFSTsMisc.cs プロジェクト: yohikofox/lucenenet
        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
ファイル: TestFSTsMisc.cs プロジェクト: yohikofox/lucenenet
        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]);
        }
コード例 #3
0
        private void DoTest(int inputMode, Int32sRef[] terms)
        {
            Array.Sort(terms);

            // Up to two positive ints, shared, generally but not
            // monotonically increasing
            {
                if (Verbose)
                {
                    Console.WriteLine("TEST: now test UpToTwoPositiveIntOutputs");
                }
                UpToTwoPositiveInt64Outputs   outputs = UpToTwoPositiveInt64Outputs.GetSingleton(true);
                IList <InputOutput <object> > pairs   = new JCG.List <InputOutput <object> >(terms.Length);
                long lastOutput = 0;
                for (int idx = 0; idx < terms.Length; idx++)
                {
                    // Sometimes go backwards
                    long value = lastOutput + TestUtil.NextInt32(Random, -100, 1000);
                    while (value < 0)
                    {
                        value = lastOutput + TestUtil.NextInt32(Random, -100, 1000);
                    }
                    object output;
                    if (Random.nextInt(5) == 3)
                    {
                        long value2 = lastOutput + TestUtil.NextInt32(Random, -100, 1000);
                        while (value2 < 0)
                        {
                            value2 = lastOutput + TestUtil.NextInt32(Random, -100, 1000);
                        }
                        IList <long> values = new JCG.List <long>();
                        values.Add(value);
                        values.Add(value2);
                        output = values;
                    }
                    else
                    {
                        output = outputs.Get(value);
                    }
                    pairs.Add(new InputOutput <object>(terms[idx], output));
                }
                new FSTTesterHelper <object>(Random, dir, inputMode, pairs, outputs, false).DoTest(false);

                // ListOfOutputs(PositiveIntOutputs), generally but not
                // monotonically increasing
                {
                    if (Verbose)
                    {
                        Console.WriteLine("TEST: now test OneOrMoreOutputs");
                    }
                    PositiveInt32Outputs          _outputs = PositiveInt32Outputs.Singleton;
                    ListOfOutputs <long?>         outputs2 = new ListOfOutputs <long?>(_outputs);
                    IList <InputOutput <object> > pairs2   = new JCG.List <InputOutput <object> >(terms.Length);
                    long lastOutput2 = 0;
                    for (int idx = 0; idx < terms.Length; idx++)
                    {
                        int           outputCount = TestUtil.NextInt32(Random, 1, 7);
                        IList <long?> values      = new JCG.List <long?>();
                        for (int i = 0; i < outputCount; i++)
                        {
                            // Sometimes go backwards
                            long value = lastOutput2 + TestUtil.NextInt32(Random, -100, 1000);
                            while (value < 0)
                            {
                                value = lastOutput2 + TestUtil.NextInt32(Random, -100, 1000);
                            }
                            values.Add(value);
                            lastOutput2 = value;
                        }

                        object output;
                        if (values.size() == 1)
                        {
                            output = values[0];
                        }
                        else
                        {
                            output = values;
                        }

                        pairs2.Add(new InputOutput <object>(terms[idx], output));
                    }
                    new FSTTester <object>(Random, dir, inputMode, pairs2, outputs2, false).DoTest(false);
                }
            }
        }