public override void MorphologicalRuleUnapplied(MorphologicalRule rule, WordAnalysis input, WordAnalysis output, Allomorph allomorph)
		{
			if (IsAnalysisTracingEnabled(rule.ID))
			{
				// create the morphological rule analysis trace record for each output analysis
				var trace = new MorphologicalRuleAnalysisTrace(rule, input.Clone()) {RuleAllomorph = allomorph, Output = output.Clone()};
				((Trace) output.CurrentTraceObject).AddChild(trace);
				// set current trace record to the morphological rule trace record for each
				// output analysis
				output.CurrentTraceObject = trace;
			}
		}
Example #2
0
        /// <summary>
        /// Unapplies the specified subrule to the specified word analysis.
        /// </summary>
        /// <param name="input">The input word analysis.</param>
        /// <param name="srIndex">Index of the subrule.</param>
        /// <param name="output">All resulting word analyses.</param>
        /// <returns>
        ///     <c>true</c> if the subrule was successfully unapplied, otherwise <c>false</c>
        /// </returns>
        public override bool Unapply(WordAnalysis input, int srIndex, out ICollection <WordAnalysis> output)
        {
            if (m_subrules[srIndex].Unapply(input, out output))
            {
                foreach (WordAnalysis wa in output)
                {
                    if (m_headRequiredPOSs != null && m_headRequiredPOSs.Count > 0)
                    {
                        foreach (PartOfSpeech pos in m_headRequiredPOSs)
                        {
                            wa.AddPOS(pos);
                        }
                    }
                    else if (m_outPOS == null)
                    {
                        wa.UninstantiatePOS();
                    }

                    if (m_nonHeadRequiredPOSs != null)
                    {
                        foreach (PartOfSpeech pos in m_nonHeadRequiredPOSs)
                        {
                            wa.NonHead.AddPOS(pos);
                        }
                    }

                    wa.MorphologicalRuleUnapplied(this);

                    if (TraceAnalysis)
                    {
                        // create the morphological rule analysis trace record for each output analysis
                        MorphologicalRuleAnalysisTrace trace = new MorphologicalRuleAnalysisTrace(this, input.Clone());
                        trace.RuleAllomorph = m_subrules[srIndex];
                        trace.Output        = wa.Clone();
                        wa.CurrentTrace.AddChild(trace);
                        // set current trace record to the morphological rule trace record for each
                        // output analysis
                        wa.CurrentTrace = trace;
                    }
                }
                return(true);
            }

            output = null;
            return(false);
        }
Example #3
0
		/// <summary>
		/// Unapplies the specified subrule to the specified word analysis.
		/// </summary>
		/// <param name="input">The input word analysis.</param>
		/// <param name="srIndex">Index of the subrule.</param>
		/// <param name="output">All resulting word analyses.</param>
		/// <returns>
		/// 	<c>true</c> if the subrule was successfully unapplied, otherwise <c>false</c>
		/// </returns>
		public override bool Unapply(WordAnalysis input, int srIndex, out ICollection<WordAnalysis> output)
		{
			if (m_subrules[srIndex].Unapply(input, out output))
			{
				foreach (WordAnalysis wa in output)
				{
					if (m_headRequiredPOSs != null && m_headRequiredPOSs.Count > 0)
					{
						foreach (PartOfSpeech pos in m_headRequiredPOSs)
							wa.AddPOS(pos);
					}
					else if (m_outPOS == null)
					{
						wa.UninstantiatePOS();
					}

					if (m_nonHeadRequiredPOSs != null)
					{
						foreach (PartOfSpeech pos in m_nonHeadRequiredPOSs)
							wa.NonHead.AddPOS(pos);
					}

					wa.MorphologicalRuleUnapplied(this);

					if (TraceAnalysis)
					{
						// create the morphological rule analysis trace record for each output analysis
						MorphologicalRuleAnalysisTrace trace = new MorphologicalRuleAnalysisTrace(this, input.Clone());
						trace.RuleAllomorph = m_subrules[srIndex];
						trace.Output = wa.Clone();
						wa.CurrentTrace.AddChild(trace);
						// set current trace record to the morphological rule trace record for each
						// output analysis
						wa.CurrentTrace = trace;
					}
				}
				return true;
			}

			output = null;
			return false;
		}
Example #4
0
        protected virtual void Write(Trace trace, bool printTraceInputs)
        {
            switch (trace.Type)
            {
            case Trace.TraceType.WORD_ANALYSIS:
                WordAnalysisTrace waTrace = trace as WordAnalysisTrace;
                m_xmlWriter.WriteStartElement(waTrace.GetType().Name);
                m_xmlWriter.WriteElementString("InputWord", waTrace.InputWord);
                break;

            case Trace.TraceType.STRATUM_ANALYSIS:
                StratumAnalysisTrace saTrace = trace as StratumAnalysisTrace;
                m_xmlWriter.WriteStartElement(saTrace.GetType().Name + (saTrace.IsInput ? "In" : "Out"));
                Write("Stratum", saTrace.Stratum);
                Write(saTrace.IsInput ? "Input" : "Output", saTrace.Analysis);
                break;

            case Trace.TraceType.STRATUM_SYNTHESIS:
                StratumSynthesisTrace ssTrace = trace as StratumSynthesisTrace;
                m_xmlWriter.WriteStartElement(ssTrace.GetType().Name + (ssTrace.IsInput ? "In" : "Out"));
                Write("Stratum", ssTrace.Stratum);
                Write(ssTrace.IsInput ? "Input" : "Output", ssTrace.Synthesis);
                break;

            case Trace.TraceType.LEX_LOOKUP:
                LexLookupTrace llTrace = trace as LexLookupTrace;
                m_xmlWriter.WriteStartElement(llTrace.GetType().Name);
                m_xmlWriter.WriteElementString("Stratum", llTrace.Stratum.Description);
                m_xmlWriter.WriteElementString("Shape", llTrace.Stratum.CharacterDefinitionTable.ToRegexString(llTrace.Shape,
                                                                                                               ModeType.ANALYSIS, true));
                break;

            case Trace.TraceType.WORD_SYNTHESIS:
                WordSynthesisTrace wsTrace = trace as WordSynthesisTrace;
                m_xmlWriter.WriteStartElement(wsTrace.GetType().Name);
                Write("RootAllomorph", wsTrace.RootAllomorph);
                m_xmlWriter.WriteStartElement("MorphologicalRules");
                foreach (MorphologicalRule rule in wsTrace.MorphologicalRules)
                {
                    Write("MorphologicalRule", rule);
                }
                m_xmlWriter.WriteEndElement();                         // MorphologicalRules
                m_xmlWriter.WriteElementString("RealizationalFeatures", wsTrace.RealizationalFeatures.ToString());
                break;

            case Trace.TraceType.PHONOLOGICAL_RULE_ANALYSIS:
                PhonologicalRuleAnalysisTrace paTrace = trace as PhonologicalRuleAnalysisTrace;
                m_xmlWriter.WriteStartElement(paTrace.GetType().Name);
                Write("PhonologicalRule", paTrace.Rule);
                if (printTraceInputs)
                {
                    Write("Input", paTrace.Input);
                }
                Write("Output", paTrace.Output);
                break;

            case Trace.TraceType.PHONOLOGICAL_RULE_SYNTHESIS:
                PhonologicalRuleSynthesisTrace psTrace = trace as PhonologicalRuleSynthesisTrace;
                m_xmlWriter.WriteStartElement(psTrace.GetType().Name);
                Write("PhonologicalRule", psTrace.Rule);
                if (printTraceInputs)
                {
                    Write("Input", psTrace.Input);
                }
                Write("Output", psTrace.Output);
                break;

            case Trace.TraceType.PHONOLOGICAL_RULE_SYNTHESIS_REQUIREDPOS:
                PhonologicalRuleSynthesisRequiredPOSTrace psposTrace = trace as PhonologicalRuleSynthesisRequiredPOSTrace;
                m_xmlWriter.WriteStartElement(psposTrace.GetType().Name);
                Write("PhonologicalRuleStemPOS", psposTrace.PartOfSpeech);
                m_xmlWriter.WriteStartElement("PhonologicalRuleRequiredPOSes");
                foreach (var partOfSpeech in psposTrace.RequiredPOSs)
                {
                    Write("PhonologicalRuleRequiredPOS", partOfSpeech);
                }
                m_xmlWriter.WriteEndElement();
                break;

            case Trace.TraceType.PHONOLOGICAL_RULE_SYNTHESIS_MPRFEATURES:
                PhonologicalRuleSynthesisMPRFeaturesTrace psmprTrace = trace as PhonologicalRuleSynthesisMPRFeaturesTrace;
                m_xmlWriter.WriteStartElement(psmprTrace.GetType().Name);
                string type = "required";
                if (psmprTrace.MPRFeatureType == PhonologicalRuleSynthesisMPRFeaturesTrace.PhonologicalRuleSynthesisMPRFeaturesTraceType.EXCLUDED)
                {
                    type = "excluded";
                }
                m_xmlWriter.WriteAttributeString("type", type);
                m_xmlWriter.WriteStartElement("PhonologicalRuleMPRFeatures");
                foreach (var mprFeature in psmprTrace.MPRFeatures)
                {
                    Write("PhonologicalRuleMPRFeature", mprFeature);
                }
                m_xmlWriter.WriteEndElement();
                m_xmlWriter.WriteStartElement("PhonologicalRuleConstrainingMPRFeatrues");
                foreach (var mprFeature in psmprTrace.ConstrainingMPRFeatures)
                {
                    Write("PhonologicalRuleMPRFeature", mprFeature);
                }
                m_xmlWriter.WriteEndElement();
                break;

            case Trace.TraceType.TEMPLATE_ANALYSIS:
                TemplateAnalysisTrace taTrace = trace as TemplateAnalysisTrace;
                m_xmlWriter.WriteStartElement(taTrace.GetType().Name + (taTrace.IsInput ? "In" : "Out"));
                Write("AffixTemplate", taTrace.Template);
                Write(taTrace.IsInput ? "Input" : "Output", taTrace.Analysis);
                break;

            case Trace.TraceType.TEMPLATE_SYNTHESIS:
                TemplateSynthesisTrace tsTrace = trace as TemplateSynthesisTrace;
                m_xmlWriter.WriteStartElement(tsTrace.GetType().Name + (tsTrace.IsInput ? "In" : "Out"));
                Write("AffixTemplate", tsTrace.Template);
                Write(tsTrace.IsInput ? "Input" : "Output", tsTrace.Synthesis);
                break;

            case Trace.TraceType.MORPHOLOGICAL_RULE_ANALYSIS:
                MorphologicalRuleAnalysisTrace maTrace = trace as MorphologicalRuleAnalysisTrace;
                m_xmlWriter.WriteStartElement(maTrace.GetType().Name);
                Write("MorphologicalRule", maTrace.Rule);
                if (maTrace.RuleAllomorph != null)
                {
                    Write("RuleAllomorph", maTrace.RuleAllomorph);
                }
                if (printTraceInputs)
                {
                    Write("Input", maTrace.Input);
                }
                Write("Output", maTrace.Output);
                break;

            case Trace.TraceType.MORPHOLOGICAL_RULE_SYNTHESIS:
                MorphologicalRuleSynthesisTrace msTrace = trace as MorphologicalRuleSynthesisTrace;
                m_xmlWriter.WriteStartElement(msTrace.GetType().Name);
                Write("MorphologicalRule", msTrace.Rule);
                if (msTrace.RuleAllomorph != null)
                {
                    Write("RuleAllomorph", msTrace.RuleAllomorph);
                }
                if (printTraceInputs)
                {
                    Write("Input", msTrace.Input);
                }
                Write("Output", msTrace.Output);
                break;

            case Trace.TraceType.BLOCKING:
                BlockingTrace bTrace = trace as BlockingTrace;
                m_xmlWriter.WriteStartElement(bTrace.GetType().Name);
                Write("BlockingEntry", bTrace.BlockingEntry);
                break;

            case Trace.TraceType.REPORT_SUCCESS:
                ReportSuccessTrace rsTrace = trace as ReportSuccessTrace;
                m_xmlWriter.WriteStartElement(rsTrace.GetType().Name);
                Write("Result", rsTrace.Output);
                break;
            }
            foreach (Trace child in trace.Children)
            {
                Write(child, printTraceInputs);
            }
            m_xmlWriter.WriteEndElement();
        }