예제 #1
0
 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)));
 }
예제 #2
0
		public override void BeginUnapplyTemplate(AffixTemplate template, WordAnalysis input)
		{
			if (TraceTemplatesAnalysis)
			{
				((XElement) input.CurrentTraceObject).Add(new XElement("TemplateAnalysisTraceIn",
					Write("AffixTemplate", template),
					Write("Input", input)));
			}
		}
예제 #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;
 }
예제 #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;
 }
예제 #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;
 }
예제 #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);
		}
예제 #7
0
파일: Trace.cs 프로젝트: bbriggs/FieldWorks
		/// <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;
		}
예제 #8
0
 /// <summary>
 /// Adds the affix template.
 /// </summary>
 /// <param name="template">The affix template.</param>
 public void AddAffixTemplate(AffixTemplate template)
 {
     m_templates.Add(template);
 }
예제 #9
0
		public void BeginUnapplyTemplate(AffixTemplate template, Word input)
		{
			((XElement) input.CurrentTrace).Add(new XElement("TemplateAnalysisTraceIn",
				CreateHCRuleElement("AffixTemplate", template),
				CreateWordElement("Input", input, true)));
		}
예제 #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)));
			}
		}
예제 #11
0
		/// <summary>
		/// Adds the affix template.
		/// </summary>
		/// <param name="template">The affix template.</param>
		public void AddAffixTemplate(AffixTemplate template)
		{
			m_templates.Add(template);
		}
예제 #12
0
		public abstract void EndApplyTemplate(AffixTemplate template, WordSynthesis output, bool applied);
예제 #13
0
		public abstract void BeginApplyTemplate(AffixTemplate template, WordSynthesis input);
예제 #14
0
		public abstract void EndUnapplyTemplate(AffixTemplate template, WordAnalysis output, bool unapplied);
예제 #15
0
		public abstract void BeginUnapplyTemplate(AffixTemplate template, WordAnalysis input);
예제 #16
0
		public void BeginApplyTemplate(AffixTemplate template, Word input)
		{
			((XElement) input.CurrentTrace).Add(new XElement("TemplateSynthesisTraceIn",
				CreateHCRuleElement("AffixTemplate", template),
				CreateWordElement("Input", input, false)));
		}
예제 #17
0
		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)));
		}
예제 #18
0
		public override void EndApplyTemplate(AffixTemplate template, WordSynthesis output, bool applied)
		{
			if (TraceTemplatesSynthesis)
				((Trace) output.CurrentTraceObject).AddChild(new TemplateSynthesisTrace(template, false, applied ? output.Clone() : null));
		}
예제 #19
0
		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)));
		}
예제 #20
0
		public override void BeginUnapplyTemplate(AffixTemplate template, WordAnalysis input)
		{
			if (TraceTemplatesAnalysis)
				((Trace) input.CurrentTraceObject).AddChild(new TemplateAnalysisTrace(template, true, input.Clone()));
		}
예제 #21
0
파일: Trace.cs 프로젝트: bbriggs/FieldWorks
		/// <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;
		}
예제 #22
0
		public override void EndUnapplyTemplate(AffixTemplate template, WordAnalysis output, bool unapplied)
		{
			if (TraceTemplatesAnalysis)
				((Trace) output.CurrentTraceObject).AddChild(new TemplateAnalysisTrace(template, false, unapplied ? output.Clone() : null));
		}
예제 #23
0
파일: Trace.cs 프로젝트: bbriggs/FieldWorks
		/// <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;
		}
예제 #24
0
        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;
        }