public void GetOutgoingTransitionsForDeterminization2()
        {
            var wrapper = new StringAutomatonWrapper();

            wrapper.Start.AddTransition(DiscreteChar.UniformInRange('a', 'z'), Weight.FromValue(2));
            wrapper.Start.AddTransition(DiscreteChar.UniformInRanges('a', 'z', 'A', 'Z'), Weight.FromValue(3));

            var outgoingTransitions =
                wrapper.GetOutgoingTransitionsForDeterminization(new Dictionary <int, Weight> {
                { 0, Weight.FromValue(5) }
            });
            var expectedOutgoingTransitions = new[]
            {
                new Tuple <DiscreteChar, Weight, IEnumerable <KeyValuePair <int, Weight> > >(
                    DiscreteChar.UniformInRange('A', 'Z'), Weight.FromValue(7.5), new Dictionary <int, Weight> {
                    { 2, Weight.FromValue(1) }
                }),
                new Tuple <DiscreteChar, Weight, IEnumerable <KeyValuePair <int, Weight> > >(
                    DiscreteChar.UniformInRange('a', 'z'), Weight.FromValue(17.5), new Dictionary <int, Weight> {
                    { 1, Weight.FromValue(10 / 17.5) }, { 2, Weight.FromValue(7.5 / 17.5) }
                }),
            };

            AssertCollectionsEqual(expectedOutgoingTransitions, outgoingTransitions, TransitionInfoEqualityComparer.Instance);
        }
Beispiel #2
0
        public void GetOutgoingTransitionsForDeterminization1()
        {
            var builder = new StringAutomaton.Builder();

            builder.Start.AddTransition(DiscreteChar.Uniform(), Weight.FromValue(2));

            var wrapper = new StringAutomatonWrapper(builder);

            var outgoingTransitions =
                wrapper.GetOutgoingTransitionsForDeterminization(0, Weight.FromValue(3));
            var expectedOutgoingTransitions = new[]
Beispiel #3
0
        public void GetOutgoingTransitionsForDeterminization3()
        {
            var builder = new StringAutomaton.Builder();

            builder.Start.AddTransition(DiscreteChar.UniformInRange('a', 'b'), Weight.FromValue(2));
            builder.Start.AddTransition(DiscreteChar.UniformInRanges('b', 'd'), Weight.FromValue(3));
            builder.Start.AddTransition(DiscreteChar.UniformInRanges('e', 'g'), Weight.FromValue(4));
            builder.Start.AddTransition(DiscreteChar.UniformInRanges(char.MinValue, 'a'), Weight.FromValue(5));

            var wrapper = new StringAutomatonWrapper(builder);

            var outgoingTransitions =
                wrapper.GetOutgoingTransitionsForDeterminization(new Dictionary <int, Weight> {
                { 0, Weight.FromValue(6) }
            });
            var expectedOutgoingTransitions = new[]
            {
                new ValueTuple <DiscreteChar, Weight, IEnumerable <KeyValuePair <int, Weight> > >(
                    DiscreteChar.UniformInRange(char.MinValue, (char)('a' - 1)),
                    Weight.FromValue(30.0 * 97.0 / 98.0),
                    new Dictionary <int, Weight> {
                    { 4, Weight.FromValue(1) }
                }),
                new ValueTuple <DiscreteChar, Weight, IEnumerable <KeyValuePair <int, Weight> > >(
                    DiscreteChar.PointMass('a'),
                    Weight.FromValue((30.0 / 98.0) + 6.0),
                    new Dictionary <int, Weight> {
                    { 1, Weight.FromValue(6.0 / ((30.0 / 98.0) + 6.0)) }, { 4, Weight.FromValue((30.0 / 98.0) / ((30.0 / 98.0) + 6.0)) }
                }),
                new ValueTuple <DiscreteChar, Weight, IEnumerable <KeyValuePair <int, Weight> > >(
                    DiscreteChar.PointMass('b'),
                    Weight.FromValue(12.0),
                    new Dictionary <int, Weight> {
                    { 1, Weight.FromValue(0.5) }, { 2, Weight.FromValue(0.5) }
                }),
                new ValueTuple <DiscreteChar, Weight, IEnumerable <KeyValuePair <int, Weight> > >(
                    DiscreteChar.UniformInRange('c', 'd'),
                    Weight.FromValue(12.0),
                    new Dictionary <int, Weight> {
                    { 2, Weight.FromValue(1.0) }
                }),
                new ValueTuple <DiscreteChar, Weight, IEnumerable <KeyValuePair <int, Weight> > >(
                    DiscreteChar.UniformInRange('e', 'g'),
                    Weight.FromValue(24.0),
                    new Dictionary <int, Weight> {
                    { 3, Weight.FromValue(1.0) }
                }),
            };

            AssertCollectionsEqual(expectedOutgoingTransitions, outgoingTransitions, TransitionInfoEqualityComparer.Instance);
        }
Beispiel #4
0
        public void GetOutgoingTransitionsForDeterminization4()
        {
            var builder = new StringAutomaton.Builder();

            builder.Start.AddTransition(DiscreteChar.UniformInRange(char.MinValue, char.MaxValue), Weight.FromValue(2));
            builder.Start.AddTransition(DiscreteChar.UniformInRange('a', char.MaxValue), Weight.FromValue(3));
            builder.Start.AddTransition(DiscreteChar.UniformInRanges('z', char.MaxValue), Weight.FromValue(4));

            var wrapper = new StringAutomatonWrapper(builder);

            var outgoingTransitions =
                wrapper.GetOutgoingTransitionsForDeterminization(new Dictionary <int, Weight> {
                { 0, Weight.FromValue(5) }
            });

            double transition1Segment1Weight   = 10.0 * 'a' / (char.MaxValue + 1.0);
            double transition1Segment2Weight   = 10.0 * ('z' - 'a') / (char.MaxValue + 1.0);
            double transition1Segment3Weight   = 10.0 * (char.MaxValue - 'z' + 1.0) / (char.MaxValue + 1.0);
            double transition2Segment1Weight   = 15.0 * ('z' - 'a') / (char.MaxValue - 'a' + 1.0);
            double transition2Segment2Weight   = 15.0 * (char.MaxValue - 'z' + 1.0) / (char.MaxValue - 'a' + 1.0);
            double transition3Segment1Weight   = 20.0;
            var    expectedOutgoingTransitions = new[]
            {
                new ValueTuple <DiscreteChar, Weight, IEnumerable <KeyValuePair <int, Weight> > >(
                    DiscreteChar.UniformInRange(char.MinValue, (char)('a' - 1)),
                    Weight.FromValue(transition1Segment1Weight),
                    new Dictionary <int, Weight> {
                    { 1, Weight.FromValue(1) }
                }),
                new ValueTuple <DiscreteChar, Weight, IEnumerable <KeyValuePair <int, Weight> > >(
                    DiscreteChar.UniformInRange('a', (char)('z' - 1)),
                    Weight.FromValue(transition1Segment2Weight + transition2Segment1Weight),
                    new Dictionary <int, Weight>
                {
                    { 1, Weight.FromValue(transition1Segment2Weight / (transition1Segment2Weight + transition2Segment1Weight)) },
                    { 2, Weight.FromValue(transition2Segment1Weight / (transition1Segment2Weight + transition2Segment1Weight)) }
                }),
                new ValueTuple <DiscreteChar, Weight, IEnumerable <KeyValuePair <int, Weight> > >(
                    DiscreteChar.UniformInRange('z', char.MaxValue),
                    Weight.FromValue(transition1Segment3Weight + transition2Segment2Weight + transition3Segment1Weight),
                    new Dictionary <int, Weight>
                {
                    { 1, Weight.FromValue(transition1Segment3Weight / (transition1Segment3Weight + transition2Segment2Weight + transition3Segment1Weight)) },
                    { 2, Weight.FromValue(transition2Segment2Weight / (transition1Segment3Weight + transition2Segment2Weight + transition3Segment1Weight)) },
                    { 3, Weight.FromValue(transition3Segment1Weight / (transition1Segment3Weight + transition2Segment2Weight + transition3Segment1Weight)) }
                }),
            };

            AssertCollectionsEqual(expectedOutgoingTransitions, outgoingTransitions, TransitionInfoEqualityComparer.Instance);
        }
        public void GetOutgoingTrainsitionsForDeterminization5()
        {
            var wrapper = new StringAutomatonWrapper();

            wrapper.Start.AddTransition('A', Weight.FromValue(2.49999999999995));
            wrapper.Start.AddTransition('A', Weight.FromValue(4.49999999999959));
            wrapper.Start.AddTransition('D', Weight.FromValue(2.49999999999996));
            wrapper.Start.AddTransition('D', Weight.FromValue(4.49999999999966));
            wrapper.Start.AddTransition('K', Weight.FromValue(5.00000001783332));
            wrapper.Start.AddTransition('M', Weight.FromValue(2.49999999999996));
            wrapper.Start.AddTransition('M', Weight.FromValue(2.49999999999991));
            wrapper.Start.AddTransition('N', Weight.FromValue(2.49999999999996));
            wrapper.Start.AddTransition('N', Weight.FromValue(2.49999999999994));

            var outgoingTransitions = wrapper.GetOutgoingTransitionsForDeterminization(
                new Dictionary <int, Weight> {
                { 0, Weight.FromValue(1) }
            }).ToArray();

            Assert.Equal(5, outgoingTransitions.Length);
            Assert.True(outgoingTransitions.All(ot => ot.Item1.IsPointMass));
        }
Beispiel #6
0
        public void GetOutgoingTransitionsForDeterminization1()
        {
            var builder = new StringAutomaton.Builder();

            builder.Start.AddTransition(DiscreteChar.Uniform(), Weight.FromValue(2));

            var wrapper = new StringAutomatonWrapper(builder);

            var outgoingTransitions =
                wrapper.GetOutgoingTransitionsForDeterminization(new Dictionary <int, Weight> {
                { 0, Weight.FromValue(3) }
            });
            var expectedOutgoingTransitions = new[]
            {
                new ValueTuple <DiscreteChar, Weight, IEnumerable <KeyValuePair <int, Weight> > >(
                    DiscreteChar.Uniform(), Weight.FromValue(6), new Dictionary <int, Weight> {
                    { 1, Weight.FromValue(1) }
                })
            };

            AssertCollectionsEqual(expectedOutgoingTransitions, outgoingTransitions, TransitionInfoEqualityComparer.Instance);
        }