public AnalysisAffixTemplateRule(SpanFactory <ShapeNode> spanFactory, Morpher morpher, AffixTemplate template)
 {
     _morpher  = morpher;
     _template = template;
     _rules    = new List <IRule <Word, ShapeNode> >(template.Slots
                                                     .Select(slot => new RuleBatch <Word, ShapeNode>(slot.Rules.Select(mr => mr.CompileAnalysisRule(spanFactory, morpher)), false, FreezableEqualityComparer <Word> .Default)));
 }
		public override void BeginUnapplyTemplate(AffixTemplate template, WordAnalysis input)
		{
			if (TraceTemplatesAnalysis)
			{
				((XElement) input.CurrentTraceObject).Add(new XElement("TemplateAnalysisTraceIn",
					Write("AffixTemplate", template),
					Write("Input", input)));
			}
		}
Exemple #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TemplateSynthesisTrace"/> class.
 /// </summary>
 /// <param name="template">The template.</param>
 /// <param name="input">if <c>true</c> this is an input record, if <c>false</c> this is an output record.</param>
 /// <param name="synthesis">The input or output word synthesis.</param>
 internal TemplateSynthesisTrace(AffixTemplate template, bool input, WordSynthesis synthesis)
     : base(template, input)
 {
     m_synthesis = synthesis;
 }
Exemple #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TemplateAnalysisTrace"/> class.
 /// </summary>
 /// <param name="template">The template.</param>
 /// <param name="input">if <c>true</c> this is an input record, if <c>false</c> this is an output record.</param>
 /// <param name="analysis">The input or output word analysis.</param>
 internal TemplateAnalysisTrace(AffixTemplate template, bool input, WordAnalysis analysis)
     : base(template, input)
 {
     m_analysis = analysis;
 }
Exemple #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TemplateTrace"/> class.
 /// </summary>
 /// <param name="template">The template.</param>
 /// <param name="input">if <c>true</c> this is an input record, if <c>false</c> this is an output record.</param>
 internal TemplateTrace(AffixTemplate template, bool input)
 {
     m_template = template;
     m_input    = input;
 }
Exemple #6
0
		void LoadAffixTemplate(XmlElement tempNode, HCObjectSet<MorphologicalRule> templateRules)
		{
			string id = tempNode.GetAttribute("id");
			string name = tempNode.SelectSingleNode("Name").InnerText;
			AffixTemplate template = new AffixTemplate(id, name, m_curMorpher);

			string posIdsStr = tempNode.GetAttribute("requiredPartsOfSpeech");
			template.RequiredPOSs = LoadPOSs(posIdsStr);

			XmlNodeList slotList = tempNode.SelectNodes("Slot[@isActive='yes']");
			foreach (XmlNode slotNode in slotList)
			{
				XmlElement slotElem = slotNode as XmlElement;
				string slotId = slotElem.GetAttribute("id");
				string slotName = slotElem.SelectSingleNode("Name").InnerText;

				Slot slot = new Slot(slotId, slotName, m_curMorpher);
				string ruleIdsStr = slotElem.GetAttribute("morphologicalRules");
				string[] ruleIds = ruleIdsStr.Split(' ');
				MorphologicalRule lastRule = null;
				foreach (string ruleId in ruleIds)
				{
					MorphologicalRule rule = m_curMorpher.GetMorphologicalRule(ruleId);
					if (rule != null)
					{
						slot.AddRule(rule);
						lastRule = rule;
						templateRules.Add(rule);
					}
					else
					{
						if (m_quitOnError)
							throw CreateUndefinedObjectException(string.Format(HCStrings.kstidUnknownMRule, ruleId), ruleId);
					}
				}

				string optionalStr = slotElem.GetAttribute("optional");
				if (string.IsNullOrEmpty(optionalStr) && lastRule is RealizationalRule)
					slot.IsOptional = (lastRule as RealizationalRule).RealizationalFeatures.NumFeatures > 0;
				else
					slot.IsOptional = optionalStr == "true";
				template.AddSlot(slot);
			}

			m_curMorpher.AddAffixTemplate(template);
		}
Exemple #7
0
		/// <summary>
		/// Initializes a new instance of the <see cref="TemplateAnalysisTrace"/> class.
		/// </summary>
		/// <param name="template">The template.</param>
		/// <param name="input">if <c>true</c> this is an input record, if <c>false</c> this is an output record.</param>
		/// <param name="analysis">The input or output word analysis.</param>
		internal TemplateAnalysisTrace(AffixTemplate template, bool input, WordAnalysis analysis)
			: base(template, input)
		{
			m_analysis = analysis;
		}
Exemple #8
0
 /// <summary>
 /// Adds the affix template.
 /// </summary>
 /// <param name="template">The affix template.</param>
 public void AddAffixTemplate(AffixTemplate template)
 {
     m_templates.Add(template);
 }
		public void BeginUnapplyTemplate(AffixTemplate template, Word input)
		{
			((XElement) input.CurrentTrace).Add(new XElement("TemplateAnalysisTraceIn",
				CreateHCRuleElement("AffixTemplate", template),
				CreateWordElement("Input", input, true)));
		}
Exemple #10
0
		public override void EndUnapplyTemplate(AffixTemplate template, WordAnalysis output, bool unapplied)
		{
			if (TraceTemplatesAnalysis)
			{
				((XElement) output.CurrentTraceObject).Add(new XElement("TemplateAnalysisTraceOut",
					Write("AffixTemplate", template),
					Write("Output", unapplied ? output : null)));
			}
		}
Exemple #11
0
		/// <summary>
		/// Adds the affix template.
		/// </summary>
		/// <param name="template">The affix template.</param>
		public void AddAffixTemplate(AffixTemplate template)
		{
			m_templates.Add(template);
		}
Exemple #12
0
		public abstract void EndApplyTemplate(AffixTemplate template, WordSynthesis output, bool applied);
Exemple #13
0
		public abstract void BeginApplyTemplate(AffixTemplate template, WordSynthesis input);
Exemple #14
0
		public abstract void EndUnapplyTemplate(AffixTemplate template, WordAnalysis output, bool unapplied);
Exemple #15
0
		public abstract void BeginUnapplyTemplate(AffixTemplate template, WordAnalysis input);
		public void BeginApplyTemplate(AffixTemplate template, Word input)
		{
			((XElement) input.CurrentTrace).Add(new XElement("TemplateSynthesisTraceIn",
				CreateHCRuleElement("AffixTemplate", template),
				CreateWordElement("Input", input, false)));
		}
		public void EndApplyTemplate(AffixTemplate template, Word output, bool applied)
		{
			((XElement) output.CurrentTrace).Add(new XElement("TemplateSynthesisTraceOut",
				CreateHCRuleElement("AffixTemplate", template),
				CreateWordElement("Output", applied ? output : null, false)));
		}
		public override void EndApplyTemplate(AffixTemplate template, WordSynthesis output, bool applied)
		{
			if (TraceTemplatesSynthesis)
				((Trace) output.CurrentTraceObject).AddChild(new TemplateSynthesisTrace(template, false, applied ? output.Clone() : null));
		}
		public void EndUnapplyTemplate(AffixTemplate template, Word output, bool unapplied)
		{
			((XElement) output.CurrentTrace).Add(new XElement("TemplateAnalysisTraceOut",
				CreateHCRuleElement("AffixTemplate", template),
				CreateWordElement("Output", unapplied ? output : null, true)));
		}
		public override void BeginUnapplyTemplate(AffixTemplate template, WordAnalysis input)
		{
			if (TraceTemplatesAnalysis)
				((Trace) input.CurrentTraceObject).AddChild(new TemplateAnalysisTrace(template, true, input.Clone()));
		}
Exemple #21
0
		/// <summary>
		/// Initializes a new instance of the <see cref="TemplateTrace"/> class.
		/// </summary>
		/// <param name="template">The template.</param>
		/// <param name="input">if <c>true</c> this is an input record, if <c>false</c> this is an output record.</param>
		internal TemplateTrace(AffixTemplate template, bool input)
		{
			m_template = template;
			m_input = input;
		}
		public override void EndUnapplyTemplate(AffixTemplate template, WordAnalysis output, bool unapplied)
		{
			if (TraceTemplatesAnalysis)
				((Trace) output.CurrentTraceObject).AddChild(new TemplateAnalysisTrace(template, false, unapplied ? output.Clone() : null));
		}
Exemple #23
0
		/// <summary>
		/// Initializes a new instance of the <see cref="TemplateSynthesisTrace"/> class.
		/// </summary>
		/// <param name="template">The template.</param>
		/// <param name="input">if <c>true</c> this is an input record, if <c>false</c> this is an output record.</param>
		/// <param name="synthesis">The input or output word synthesis.</param>
		internal TemplateSynthesisTrace(AffixTemplate template, bool input, WordSynthesis synthesis)
			: base(template, input)
		{
			m_synthesis = synthesis;
		}
        private AffixTemplate LoadAffixTemplate(XElement tempElem, Dictionary<string, IMorphologicalRule> mrules)
        {
            var template = new AffixTemplate {Name = (string) tempElem.Element("Name"), IsFinal = (bool) tempElem.Attribute("final")};

            var requiredPos = (string) tempElem.Attribute("requiredPartsOfSpeech");
            if (!string.IsNullOrEmpty(requiredPos))
                template.RequiredSyntacticFeatureStruct = FeatureStruct.New().Feature(_posFeature).EqualTo(ParsePartsOfSpeech(requiredPos)).Value;

            foreach (XElement slotElem in tempElem.Elements("Slot").Where(IsActive))
            {
                var rules = new List<MorphemicMorphologicalRule>();
                var ruleIDsStr = (string) slotElem.Attribute("morphologicalRules");
                IMorphologicalRule lastRule = null;
                foreach (string ruleID in ruleIDsStr.Split(' '))
                {
                    IMorphologicalRule rule;
                    if (mrules.TryGetValue(ruleID, out rule))
                    {
                        rules.Add((MorphemicMorphologicalRule) rule);
                        lastRule = rule;
                    }
                }
                var slot = new AffixTemplateSlot(rules) {Name = (string) slotElem.Element("Name")};

                var optionalStr = (string) slotElem.Attribute("optional");
                var realRule = lastRule as RealizationalAffixProcessRule;
                if (string.IsNullOrEmpty(optionalStr) && realRule != null)
                    slot.Optional = !realRule.RealizationalFeatureStruct.IsEmpty;
                else
                    slot.Optional = optionalStr == "true";
                template.Slots.Add(slot);
            }

            return template;
        }