Ejemplo n.º 1
0
 /// <summary>
 /// Determines whether this subrule is applicable to the specified word analysis.
 /// </summary>
 /// <param name="input">The word analysis.</param>
 /// <returns>
 ///     <c>true</c> if this subrule is applicable, otherwise <c>false</c>.
 /// </returns>
 public bool IsApplicable(WordSynthesis input)
 {
     // check part of speech and MPR features
     return((m_requiredPOSs == null || m_requiredPOSs.Count == 0 || m_requiredPOSs.Contains(input.POS)) &&
            (m_requiredMPRFeatures == null || m_requiredMPRFeatures.Count == 0 || m_requiredMPRFeatures.IsMatch(input.MPRFeatures)) &&
            (m_excludedMPRFeatures == null || m_excludedMPRFeatures.Count == 0 || !m_excludedMPRFeatures.IsMatch(input.MPRFeatures)));
 }
Ejemplo n.º 2
0
            /// <summary>
            /// Applies this subrule to the specified word synthesis.
            /// </summary>
            /// <param name="input">The input word synthesis.</param>
            /// <param name="output">The output word synthesis.</param>
            /// <returns><c>true</c> if the subrule was successfully applied, otherwise <c>false</c></returns>
            public bool Apply(WordSynthesis input, out WordSynthesis output)
            {
                output = null;

                // check MPR features
                if ((m_requiredMPRFeatures != null && m_requiredMPRFeatures.Count > 0 && !m_requiredMPRFeatures.IsMatch(input.MPRFeatures)) ||
                    (m_excludedMPRFeatures != null && m_excludedMPRFeatures.Count > 0 && m_excludedMPRFeatures.IsMatch(input.MPRFeatures)))
                {
                    return(false);
                }

                VariableValues instantiatedVars = new VariableValues(m_alphaVars);
                IList <Match>  headMatches, nonHeadMatches;

                if (m_headLhsTemp.IsMatch(input.Shape.First, Direction.RIGHT, ModeType.SYNTHESIS, instantiatedVars, out headMatches) &&
                    m_nonHeadLhsTemp.IsMatch(input.NonHead.Shape.First, Direction.RIGHT, ModeType.SYNTHESIS, instantiatedVars, out nonHeadMatches))
                {
                    output = input.Clone();
                    ApplyRHS(headMatches[0], nonHeadMatches[0], input, output);

                    if (m_outputMPRFeatures != null)
                    {
                        output.MPRFeatures.AddOutput(m_outputMPRFeatures);
                    }
                    return(true);
                }

                return(false);
            }
            /// <summary>
            /// Determines whether this subrule is applicable to the specified word analysis.
            /// </summary>
            /// <param name="input">The word analysis.</param>
            /// <param name="trace"> </param>
            /// <returns>
            ///     <c>true</c> if this subrule is applicable, otherwise <c>false</c>.
            /// </returns>
            public bool IsApplicable(WordSynthesis input, Trace trace)
            {
                // check part of speech and MPR features
                bool fRequiredPOSMet         = m_requiredPOSs == null || m_requiredPOSs.Count == 0 || m_requiredPOSs.Contains(input.POS);
                bool fRequiredMPRFeaturesMet = m_requiredMPRFeatures == null || m_requiredMPRFeatures.Count == 0 || m_requiredMPRFeatures.IsMatch(input.MPRFeatures);
                bool fExcludedMPRFeaturesMet = m_excludedMPRFeatures == null || m_excludedMPRFeatures.Count == 0 || !m_excludedMPRFeatures.IsMatch(input.MPRFeatures);

                if (trace != null)
                {
                    if (!fRequiredPOSMet)
                    {
                        var badPosTrace = new PhonologicalRuleSynthesisRequiredPOSTrace(input.POS, m_requiredPOSs);
                        trace.AddChild(badPosTrace);
                    }
                    if (!fRequiredMPRFeaturesMet)
                    {
                        var badRequiredMPRFeaturesTrace =
                            new PhonologicalRuleSynthesisMPRFeaturesTrace(
                                PhonologicalRuleSynthesisMPRFeaturesTrace.PhonologicalRuleSynthesisMPRFeaturesTraceType.REQUIRED,
                                input.MPRFeatures, m_requiredMPRFeatures);
                        trace.AddChild(badRequiredMPRFeaturesTrace);
                    }
                    if (!fExcludedMPRFeaturesMet)
                    {
                        var badExcludedMPRFeaturesTrace =
                            new PhonologicalRuleSynthesisMPRFeaturesTrace(
                                PhonologicalRuleSynthesisMPRFeaturesTrace.PhonologicalRuleSynthesisMPRFeaturesTraceType.EXCLUDED,
                                input.MPRFeatures, m_excludedMPRFeatures);
                        trace.AddChild(badExcludedMPRFeaturesTrace);
                    }
                }
                return(fRequiredPOSMet && fRequiredMPRFeaturesMet && fExcludedMPRFeaturesMet);
            }