public IEnumerable <Word> Apply(Word input)
        {
            if (!_morpher.RuleSelector(_rule))
            {
                return(Enumerable.Empty <Word>());
            }

            Word origInput = null;

            if (_morpher.TraceManager.IsTracing)
            {
                origInput = input.DeepClone();
            }

            if (_patternRule.Apply(input).Any())
            {
                if (_morpher.TraceManager.IsTracing)
                {
                    _morpher.TraceManager.PhonologicalRuleUnapplied(_rule, -1, origInput, input);
                }
                return(input.ToEnumerable());
            }

            if (_morpher.TraceManager.IsTracing)
            {
                _morpher.TraceManager.PhonologicalRuleNotUnapplied(_rule, -1, input);
            }
            return(Enumerable.Empty <Word>());
        }
Exemple #2
0
        public IEnumerable <Word> Apply(Word input)
        {
            if (!_morpher.RuleSelector(_rule))
            {
                return(Enumerable.Empty <Word>());
            }

            Word origInput = null;

            if (_morpher.TraceManager.IsTracing)
            {
                origInput = input.DeepClone();
                input.CurrentRuleResults = new Dictionary <int, Tuple <FailureReason, object> >();
            }

            bool applied = _patternRule.Apply(input).Any();

            if (_morpher.TraceManager.IsTracing)
            {
                for (int i = 0; i < _rule.Subrules.Count; i++)
                {
                    Tuple <FailureReason, object> reason;
                    if (input.CurrentRuleResults.TryGetValue(i, out reason))
                    {
                        if (reason.Item1 == FailureReason.None)
                        {
                            _morpher.TraceManager.PhonologicalRuleApplied(_rule, i, origInput, input);
                            break;
                        }
                        _morpher.TraceManager.PhonologicalRuleNotApplied(_rule, i, input, reason.Item1, reason.Item2);
                    }
                    else
                    {
                        _morpher.TraceManager.PhonologicalRuleNotApplied(_rule, i, input, FailureReason.Pattern, null);
                    }
                }
                input.CurrentRuleResults = null;
            }
            if (applied)
            {
                return(input.ToEnumerable());
            }
            return(Enumerable.Empty <Word>());
        }