示例#1
0
        public void ProjectSourceLargeAutomaton()
        {
            using (var unlimited = new StringAutomaton.UnlimitedStatesComputation())
            {
                const int StateCount = 100_000;

                var builder = new StringAutomaton.Builder();
                var state   = builder.Start;

                for (var i = 1; i < StateCount; ++i)
                {
                    state = state.AddTransition('a', Weight.One);
                }

                state.SetEndWeight(Weight.One);

                var automaton      = builder.GetAutomaton();
                var point          = new string('a', StateCount - 1);
                var copyTransducer = StringTransducer.Copy();

                var projectedAutomaton = copyTransducer.ProjectSource(automaton);
                var projectedPoint     = copyTransducer.ProjectSource(point);

                StringInferenceTestUtilities.TestValue(projectedAutomaton, 1.0, point);
                StringInferenceTestUtilities.TestValue(projectedPoint, 1.0, point);
            }
        }
示例#2
0
        public void LargeTransducer()
        {
            var largeStatesCount = 1200000; // bigger than default MaxStatesCount in automata

            using (var unlimitedAutomatonStates = new StringAutomaton.UnlimitedStatesComputation())
            {
                var bigAutomatonBuilder = new StringAutomaton.Builder();
                bigAutomatonBuilder.AddStates(largeStatesCount - bigAutomatonBuilder.StatesCount);
                Func <Option <ImmutableDiscreteChar>, Weight, ValueTuple <Option <ImmutablePairDistribution <char, ImmutableDiscreteChar> >, Weight> >
                transitionConverter =
                    (dist, weight) =>
                    ValueTuple.Create(
                        Option.Some(ImmutablePairDistribution <char, ImmutableDiscreteChar> .FromFirstSecond(dist, dist)), weight);

                var bigAutomaton = bigAutomatonBuilder.GetAutomaton();

                Assert.Throws <AutomatonTooLargeException>(() =>
                                                           StringTransducer.FromAutomaton(bigAutomaton, transitionConverter));

                // Shouldn't throw if the maximum number of states is increased
                using (var unlimitedTransducerStates = new StringTransducer.UnlimitedStatesComputation())
                {
                    StringTransducer.FromAutomaton(bigAutomaton, transitionConverter);
                }
            }
        }