Ejemplo n.º 1
0
        /// <summary>
        /// Creates a transducer <c>T(a, b) = g(b) I[a = ""]</c>, where <c>g(b)</c> is a given automaton.
        /// </summary>
        /// <param name="destAutomaton">The automaton defining weights for the second transducer argument.</param>
        /// <returns>The created transducer.</returns>
        public static TThis Produce(TDestAutomaton destAutomaton)
        {
            Argument.CheckIfNotNull(destAutomaton, "destAutomaton");

            var result = new TThis();

            result.sequencePairToWeight.SetToFunction(
                destAutomaton,
                (dist, weight, group) => Tuple.Create(
                    dist == null ? null : PairDistributionBase <TSrcElement, TSrcElementDistribution, TDestElement, TDestElementDistribution, TPairDistribution> .FromSecond(dist),
                    weight));
            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a transducer <c>T(a, b) = f(a) I[b = ""]</c>, where <c>f(a)</c> is a given automaton.
        /// </summary>
        /// <param name="srcAutomaton">The automaton defining weights for the first transducer argument.</param>
        /// <returns>The created transducer.</returns>
        public static TThis Consume(TSrcAutomaton srcAutomaton)
        {
            Argument.CheckIfNotNull(srcAutomaton, "srcAutomaton");

            var result = new TThis();

            result.sequencePairToWeight.SetToFunction(
                srcAutomaton,
                (dist, weight, group) => ValueTuple.Create(
                    dist.HasValue
                        ? Option.Some(PairDistributionBase <TSrcElement, TSrcElementDistribution, TDestElement, TDestElementDistribution, TPairDistribution> .FromFirst(dist))
                        : Option.None,
                    weight));

            return(result);
        }