Esempio n. 1
0
        public void SimpleConstructionWithStringOutputs()
        {
            var inputs = new string[]
            {
                "a banana",
                "a lemon",
                "a mandarine",
                "a mango",
                "an apple",
                "an orange",
            };

            var outputs = new string[]
            {
                "one",
                "two",
                "three",
                "minusone",
                "minustwo",
                "minuseight"
            };

            var fst = new FSTBuilder <string>(FSTStringOutput.Instance).FromList(inputs, outputs);

            Verify(fst, inputs, outputs);

            var fst1 = FST <string> .FromBytes(fst.GetBytes(), FSTStringOutput.Instance);

            Verify(fst1, inputs, outputs);

            var fst2 = FST <string> .FromBytesCompressed(fst.GetBytesCompressed(), FSTStringOutput.Instance);

            Verify(fst2, inputs, outputs);
        }
Esempio n. 2
0
        public void ConstructionWithIntOutputs()
        {
            var inputs = new string[]
            {
                "a",
                "ab",
                "abilities",
                "ability",
            };

            var outputs = new int[]
            {
                4,
                3134,
                7488,
                1580,
            };

            var fst = new FSTBuilder <int>(FSTVarIntOutput.Instance).FromList(inputs, outputs);

            Verify(fst, inputs, outputs);

            var fst1 = FST <int> .FromBytes(fst.GetBytes(), FSTVarIntOutput.Instance);

            Verify(fst1, inputs, outputs);

            var fst2 = FST <int> .FromBytesCompressed(fst.GetBytesCompressed(), FSTVarIntOutput.Instance);

            Verify(fst2, inputs, outputs);
        }
Esempio n. 3
0
        public void SimpleConstructionWithIntOutputs()
        {
            var inputs = new string[]
            {
                "a banana",
                "a lemon",
                "a mandarine",
                "a mango",
                "an apple",
                "an orange",
            };

            var outputs = new int[]
            {
                1,
                2,
                3,
                -2,
                15,
                8
            };

            var fst = new FSTBuilder <int>(FSTVarIntOutput.Instance).FromList(inputs, outputs);

            Verify(fst, inputs, outputs);

            var fst1 = FST <int> .FromBytes(fst.GetBytes(), FSTVarIntOutput.Instance);

            Verify(fst1, inputs, outputs);

            var fst2 = FST <int> .FromBytesCompressed(fst.GetBytesCompressed(), FSTVarIntOutput.Instance);

            Verify(fst2, inputs, outputs);
        }
Esempio n. 4
0
        private static int DoPrint(PrintOptions opts)
        {
            var timer = Stopwatch.StartNew();

            var bytes    = File.ReadAllBytes(opts.InputFile);
            var fstBytes = bytes.Skip(7).ToArray();
            var fst      = default(FST <int>);

            if (bytes[6] == 'D')
            {
                fst = FST <int> .FromBytes(fstBytes, outputType);
            }
            else if (bytes[6] == 'C')
            {
                fst = FST <int> .FromBytesCompressed(fstBytes, outputType);
            }
            else
            {
                throw new NotSupportedException("FST format is not supported or input is not correct");
            }
            PrintConsole(ConsoleColor.White, $"FST read from: {opts.InputFile}, time: {timer.Elapsed}");

            timer.Restart();
            var terms = 0;

            foreach (var term in fst.Match(new WildcardMatcher(opts.Pattern, 255)))
            {
                if (!fst.TryMatch(term, out int value))
                {
                    throw new Exception("This is a bug");
                }

                ++terms;
                Console.WriteLine($"{term}->{value}");
            }
            PrintConsole(ConsoleColor.White, $"FST print terms: {terms}, time: {timer.Elapsed}");

            return(0);
        }
        public void AcceptanceTestWithIntegerOutput()
        {
            var inputs = new string[] {
                "Albert Schweitzer Ziekenhuis. Locatie Amstelwijck Heliport",
                "Amsterdam Airfield",
                "Amsterdam Airport",
                "Amsterdam Airport Schiphol",
                "Amsterdam Heliport",
                "Chafei Amsei Airport",
                "New Amsterdam Airport",
                "Schwarzheide/Schipkau Airport"
            };

            var outputs = new int[] {
                43711,
                23465,
                41198,
                2513,
                43207,
                5873,
                41521,
                29065
            };

            var fst = new FSTBuilder <int>(FSTVarIntOutput.Instance).FromList(inputs, outputs);

            Verify(fst, inputs, outputs);

            var fst1 = FST <int> .FromBytes(fst.GetBytes(), FSTVarIntOutput.Instance);

            Verify(fst1, inputs, outputs);

            var fst2 = FST <int> .FromBytesCompressed(fst.GetBytesCompressed(), FSTVarIntOutput.Instance);

            Verify(fst2, inputs, outputs);
        }