public SynthesisAffixTemplatesRule(SpanFactory <ShapeNode> spanFactory, Morpher morpher, Stratum stratum) { _morpher = morpher; _stratum = stratum; _templates = stratum.AffixTemplates.ToList(); _templateRules = _templates.Select(temp => temp.CompileSynthesisRule(spanFactory, morpher)).ToList(); }
/// <summary> /// Initializes a new instance of the <see cref="WordSynthesis"/> class. /// </summary> /// <param name="rootAllomorph">The root allomorph.</param> /// <param name="nonHead">The non-head synthesis.</param> /// <param name="rzFeatures">The realizational features.</param> /// <param name="mrules">The morphological rules to apply.</param> /// <param name="curTrace">The current trace record.</param> internal WordSynthesis(LexEntry.RootAllomorph rootAllomorph, WordSynthesis nonHead, FeatureValues rzFeatures, IEnumerable <MorphologicalRule> mrules, Trace curTrace) { m_root = (LexEntry)rootAllomorph.Morpheme; m_mprFeatures = m_root.MPRFeatures != null?m_root.MPRFeatures.Clone() : new MPRFeatureSet(); m_headFeatures = m_root.HeadFeatures != null?m_root.HeadFeatures.Clone() : new FeatureValues(); m_footFeatures = m_root.FootFeatures != null?m_root.FootFeatures.Clone() : new FeatureValues(); m_pos = m_root.POS; m_stratum = m_root.Stratum; m_nonHead = nonHead; m_morphs = new Morphs(); Morph morph = new Morph(rootAllomorph); morph.Shape.AddMany(rootAllomorph.Shape.Segments); m_morphs.Add(morph); m_shape = new PhoneticShape(); m_shape.Add(new Margin(Direction.LEFT)); m_shape.AddPartition(rootAllomorph.Shape.Segments, morph.Partition); m_shape.Add(new Margin(Direction.RIGHT)); m_obligHeadFeatures = new HCObjectSet <Feature>(); m_mrules = new List <MorphologicalRule>(mrules); m_rzFeatures = rzFeatures; m_curTrace = curTrace; m_mrulesApplied = new Dictionary <MorphologicalRule, int>(); }
/// <summary> /// Initializes a new instance of the <see cref="WordAnalysis"/> class. /// </summary> /// <param name="shape">The shape.</param> /// <param name="stratum"></param> internal WordAnalysis(PhoneticShape shape, Stratum stratum) { m_shape = shape; m_pos = new HCObjectSet<PartOfSpeech>(); m_mrules = new List<MorphologicalRule>(); m_mrulesUnapplied = new Dictionary<MorphologicalRule, int>(); m_rzFeatures = new FeatureValues(); m_stratum = stratum; }
public override void BeginUnapplyStratum(Stratum stratum, WordAnalysis input) { if (TraceStrataAnalysis) { ((XElement) input.CurrentTraceObject).Add(new XElement("StratumAnalysisTraceIn", Write("Stratum", stratum), Write("Input", input))); } }
public override void EndUnapplyStratum(Stratum stratum, WordAnalysis output) { if (TraceStrataAnalysis) { ((XElement) output.CurrentTraceObject).Add(new XElement("StratumAnalysisTraceOut", Write("Stratum", stratum), Write("Output", output))); } }
/// <summary> /// Initializes a new instance of the <see cref="WordAnalysis"/> class. /// </summary> /// <param name="shape">The shape.</param> /// <param name="curTrace">The current trace record.</param> internal WordAnalysis(PhoneticShape shape, Stratum stratum, Trace curTrace) { m_shape = shape; m_pos = new HCObjectSet <PartOfSpeech>(); m_mrules = new List <MorphologicalRule>(); m_mrulesUnapplied = new Dictionary <MorphologicalRule, int>(); m_rzFeatures = new FeatureValues(); m_stratum = stratum; m_curTrace = curTrace; }
/// <summary> /// Copy constructor. /// </summary> /// <param name="wa">The word analysis.</param> public WordAnalysis(WordAnalysis wa) { m_shape = wa.m_shape.Clone(); m_pos = new HCObjectSet<PartOfSpeech>(wa.m_pos); m_rootAllomorph = wa.m_rootAllomorph; if (wa.m_nonHead != null) m_nonHead = wa.m_nonHead.Clone(); m_mrules = new List<MorphologicalRule>(wa.m_mrules); m_mrulesUnapplied = new Dictionary<MorphologicalRule, int>(wa.m_mrulesUnapplied); m_rzFeatures = wa.m_rzFeatures.Clone(); m_curTrace = wa.m_curTrace; m_stratum = wa.m_stratum; }
/// <summary> /// Copy constructor. /// </summary> /// <param name="wa">The word analysis.</param> public WordAnalysis(WordAnalysis wa) { m_shape = wa.m_shape.Clone(); m_pos = new HCObjectSet <PartOfSpeech>(wa.m_pos); m_rootAllomorph = wa.m_rootAllomorph; if (wa.m_nonHead != null) { m_nonHead = wa.m_nonHead.Clone(); } m_mrules = new List <MorphologicalRule>(wa.m_mrules); m_mrulesUnapplied = new Dictionary <MorphologicalRule, int>(wa.m_mrulesUnapplied); m_rzFeatures = wa.m_rzFeatures.Clone(); m_curTrace = wa.m_curTrace; m_stratum = wa.m_stratum; }
public Word(Stratum stratum, Shape shape) { _allomorphs = new Dictionary <string, Allomorph>(); Stratum = stratum; _shape = shape; ResetDirty(); SyntacticFeatureStruct = new FeatureStruct(); RealizationalFeatureStruct = new FeatureStruct(); _mprFeatures = new MprFeatureSet(); _mrules = new Stack <IMorphologicalRule>(); _mrulesUnapplied = new Dictionary <IMorphologicalRule, int>(); _mrulesApplied = new Dictionary <IMorphologicalRule, int>(); _nonHeads = new Stack <Word>(); _obligatorySyntacticFeatures = new IDBearerSet <Feature>(); _isLastAppliedRuleFinal = null; _isPartial = false; }
public SynthesisStratumRule(SpanFactory <ShapeNode> spanFactory, Morpher morpher, Stratum stratum) { _templatesRule = new SynthesisAffixTemplatesRule(spanFactory, morpher, stratum); _mrulesRule = null; IEnumerable <IRule <Word, ShapeNode> > mrules = stratum.MorphologicalRules.Select(mrule => mrule.CompileSynthesisRule(spanFactory, morpher)); switch (stratum.MorphologicalRuleOrder) { case MorphologicalRuleOrder.Linear: _mrulesRule = new LinearRuleCascade <Word, ShapeNode>(mrules, true, FreezableEqualityComparer <Word> .Default); break; case MorphologicalRuleOrder.Unordered: _mrulesRule = new CombinationRuleCascade <Word, ShapeNode>(mrules, true, FreezableEqualityComparer <Word> .Default); break; } _prulesRule = new LinearRuleCascade <Word, ShapeNode>(stratum.PhonologicalRules.Select(prule => prule.CompileSynthesisRule(spanFactory, morpher))); _stratum = stratum; _morpher = morpher; }
/// <summary> /// Copy constructor. /// </summary> /// <param name="ws">The word synthesis.</param> public WordSynthesis(WordSynthesis ws) { m_root = ws.m_root; if (ws.m_nonHead != null) { m_nonHead = ws.m_nonHead.Clone(); } m_shape = ws.m_shape.Clone(); m_morphs = ws.m_morphs.Clone(); m_pos = ws.m_pos; m_mprFeatures = ws.m_mprFeatures.Clone(); m_headFeatures = ws.m_headFeatures.Clone(); m_footFeatures = ws.m_footFeatures.Clone(); m_obligHeadFeatures = new HCObjectSet <Feature>(ws.m_obligHeadFeatures); m_mrules = new List <MorphologicalRule>(ws.m_mrules); m_curRuleIndex = ws.m_curRuleIndex; m_rzFeatures = ws.m_rzFeatures.Clone(); m_curTrace = ws.m_curTrace; m_stratum = ws.m_stratum; m_mrulesApplied = new Dictionary <MorphologicalRule, int>(ws.m_mrulesApplied); }
public AnalysisStratumRule(SpanFactory <ShapeNode> spanFactory, Morpher morpher, Stratum stratum) { _stratum = stratum; _morpher = morpher; _prulesRule = new LinearRuleCascade <Word, ShapeNode>(stratum.PhonologicalRules.Select(prule => prule.CompileAnalysisRule(spanFactory, morpher)).Reverse()); _templatesRule = new RuleBatch <Word, ShapeNode>(stratum.AffixTemplates.Select(template => template.CompileAnalysisRule(spanFactory, morpher)), false, FreezableEqualityComparer <Word> .Default); _mrulesRule = null; IEnumerable <IRule <Word, ShapeNode> > mrules = stratum.MorphologicalRules.Select(mrule => mrule.CompileAnalysisRule(spanFactory, morpher)).Reverse(); switch (stratum.MorphologicalRuleOrder) { case MorphologicalRuleOrder.Linear: _mrulesRule = new LinearRuleCascade <Word, ShapeNode>(mrules, true, FreezableEqualityComparer <Word> .Default); break; case MorphologicalRuleOrder.Unordered: #if SINGLE_THREADED _mrulesRule = new CombinationRuleCascade <Word, ShapeNode>(mrules, true, FreezableEqualityComparer <Word> .Default); #else _mrulesRule = new ParallelCombinationRuleCascade <Word, ShapeNode>(mrules, true, FreezableEqualityComparer <Word> .Default); #endif break; } }
void LoadStratum(XmlElement stratumNode) { string id = stratumNode.GetAttribute("id"); string name = stratumNode.SelectSingleNode("Name").InnerText; Stratum stratum = new Stratum(id, name, m_curMorpher); stratum.CharacterDefinitionTable = GetCharDefTable(stratumNode.GetAttribute("characterDefinitionTable")); stratum.IsCyclic = stratumNode.GetAttribute("cyclicity") == "cyclic"; stratum.PhonologicalRuleOrder = GetPRuleOrder(stratumNode.GetAttribute("phonologicalRuleOrder")); stratum.MorphologicalRuleOrder = GetMRuleOrder(stratumNode.GetAttribute("morphologicalRuleOrder")); string tempIdsStr = stratumNode.GetAttribute("affixTemplates"); if (!string.IsNullOrEmpty(tempIdsStr)) { string[] tempIds = tempIdsStr.Split(' '); foreach (string tempId in tempIds) { AffixTemplate template = m_curMorpher.GetAffixTemplate(tempId); if (template == null) throw CreateUndefinedObjectException(string.Format(HCStrings.kstidUnknownTemplate, tempId), tempId); stratum.AddAffixTemplate(template); } } m_curMorpher.AddStratum(stratum); }
/// <summary> /// Initializes a new instance of the <see cref="StratumSynthesisTrace"/> class. /// </summary> /// <param name="stratum">The stratum.</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 StratumSynthesisTrace(Stratum stratum, bool input, WordSynthesis synthesis) : base(stratum, input) { m_synthesis = synthesis; }
public abstract void EndApplyStratum(Stratum stratum, WordSynthesis output);
public void LexicalLookup(Stratum stratum, Word input) { var trace = new XElement("LexLookupTrace", new XElement("Stratum", stratum.Name), new XElement("Shape", input.Shape.ToRegexString(stratum.SymbolTable, true))); ((XElement) input.CurrentTrace).Add(trace); }
/// <summary> /// Initializes a new instance of the <see cref="StratumTrace"/> class. /// </summary> /// <param name="stratum">The stratum.</param> /// <param name="input">if <c>true</c> this is an input record, if <c>false</c> this is an output record.</param> internal StratumTrace(Stratum stratum, bool input) { m_stratum = stratum; m_input = input; }
public abstract void LexLookup(Stratum stratum, WordAnalysis input);
public void BeginUnapplyStratum(Stratum stratum, Word input) { }
void LoadAllomorph(XmlElement alloNode, LexEntry entry, Stratum stratum) { string alloId = alloNode.GetAttribute("id"); string shapeStr = alloNode.SelectSingleNode("PhoneticShape").InnerText; PhoneticShape shape = stratum.CharacterDefinitionTable.ToPhoneticShape(shapeStr, ModeType.SYNTHESIS); if (shape == null) { LoadException le = new LoadException(LoadException.LoadErrorType.INVALID_ENTRY_SHAPE, this, string.Format(HCStrings.kstidInvalidLexEntryShape, shapeStr, entry.ID, stratum.CharacterDefinitionTable.ID)); le.Data["shape"] = shapeStr; le.Data["charDefTable"] = stratum.CharacterDefinitionTable.ID; le.Data["entry"] = entry.ID; throw le; } LexEntry.RootAllomorph allomorph = new LexEntry.RootAllomorph(alloId, shapeStr, m_curMorpher, shape); allomorph.RequiredEnvironments = LoadEnvs(alloNode.SelectSingleNode("RequiredEnvironments")); allomorph.ExcludedEnvironments = LoadEnvs(alloNode.SelectSingleNode("ExcludedEnvironments")); allomorph.Properties = LoadProperties(alloNode.SelectSingleNode("Properties")); entry.AddAllomorph(allomorph); m_curMorpher.AddAllomorph(allomorph); }
/// <summary> /// Initializes a new instance of the <see cref="StratumAnalysisTrace"/> class. /// </summary> /// <param name="stratum">The stratum.</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 StratumAnalysisTrace(Stratum stratum, bool input, WordAnalysis analysis) : base(stratum, input) { m_analysis = analysis; }
public override void LexLookup(Stratum stratum, WordAnalysis input) { if (TraceLexLookup) { var trace = new XElement("LexLookupTrace", new XElement("Stratum", stratum.Description), new XElement("Shape", stratum.CharacterDefinitionTable.ToRegexString(input.Shape, ModeType.ANALYSIS, true))); ((XElement) input.CurrentTraceObject).Add(trace); } }
public abstract void BeginUnapplyStratum(Stratum stratum, WordAnalysis input);
public abstract void EndUnapplyStratum(Stratum stratum, WordAnalysis output);
/// <summary> /// Adds the stratum. /// </summary> /// <param name="stratum">The stratum.</param> public void AddStratum(Stratum stratum) { m_strata.Add(stratum); }
internal IEnumerable <RootAllomorph> SearchRootAllomorphs(Stratum stratum, Shape shape) { RootAllomorphTrie alloSearcher = _allomorphTries[stratum]; return(alloSearcher.Search(shape).Distinct()); }
private void LoadStratum(XElement stratumElem) { var stratum = new Stratum(_tables[(string) stratumElem.Attribute("characterDefinitionTable")]) { Name = (string) stratumElem.Element("Name"), MorphologicalRuleOrder = GetMorphologicalRuleOrder((string) stratumElem.Attribute("morphologicalRuleOrder")) }; var pruleIdsStr = (string) stratumElem.Attribute("phonologicalRules"); if (!string.IsNullOrEmpty(pruleIdsStr)) { foreach (string pruleId in pruleIdsStr.Split(' ')) { IPhonologicalRule prule; if (_prules.TryGetValue(pruleId, out prule)) stratum.PhonologicalRules.Add(prule); } } var mrules = new Dictionary<string, IMorphologicalRule>(); foreach (XElement mruleElem in stratumElem.Elements("MorphologicalRuleDefinitions").Elements().Where(IsActive)) { IMorphologicalRule mrule = null; bool loaded = false; switch (mruleElem.Name.LocalName) { case "MorphologicalRule": loaded = TryLoadAffixProcessRule(mruleElem, stratum.CharacterDefinitionTable, out mrule); break; case "RealizationalRule": loaded = TryLoadRealizationalRule(mruleElem, stratum.CharacterDefinitionTable, out mrule); break; case "CompoundingRule": loaded = TryLoadCompoundingRule(mruleElem, stratum.CharacterDefinitionTable, out mrule); break; } if (loaded) mrules[(string) mruleElem.Attribute("id")] = mrule; } var mruleIdsStr = (string) stratumElem.Attribute("morphologicalRules"); if (!string.IsNullOrEmpty(mruleIdsStr)) { foreach (string mruleId in mruleIdsStr.Split(' ')) { IMorphologicalRule mrule; if (mrules.TryGetValue(mruleId, out mrule)) stratum.MorphologicalRules.Add(mrule); } } foreach (XElement tempElem in stratumElem.Elements("AffixTemplates").Elements("AffixTemplate").Where(IsActive)) stratum.AffixTemplates.Add(LoadAffixTemplate(tempElem, mrules)); foreach (XElement entryElem in stratumElem.Elements("LexicalEntries").Elements("LexicalEntry").Where(IsActive)) { LexEntry entry; if (TryLoadLexEntry(entryElem, stratum.CharacterDefinitionTable, out entry)) stratum.Entries.Add(entry); } _language.Strata.Add(stratum); }
/// <summary> /// Initializes a new instance of the <see cref="LexLookupTrace"/> class. /// </summary> /// <param name="stratum">The stratum.</param> /// <param name="shape">The shape.</param> internal LexLookupTrace(Stratum stratum, PhoneticShape shape) { m_stratum = stratum; m_shape = shape; }
public abstract void BeginApplyStratum(Stratum stratum, WordSynthesis input);
public override void LexLookup(Stratum stratum, WordAnalysis input) { if (TraceLexLookup) { // create lexical lookup trace record var trace = new LexLookupTrace(stratum, input.Shape.Clone()); ((Trace) input.CurrentTraceObject).AddChild(trace); } }
public void NonFinalTemplateAppliedLast(Stratum stratum, Word word) { ((XElement) word.CurrentTrace).Add(new XElement("FailureReason", new XAttribute("type", "nonFinalTemplate"))); }
public override void BeginApplyStratum(Stratum stratum, WordSynthesis input) { if (TraceStrataSynthesis) ((Trace) input.CurrentTraceObject).AddChild(new StratumSynthesisTrace(stratum, true, input.Clone())); }
public void EndUnapplyStratum(Stratum stratum, Word output) { }
public override void EndApplyStratum(Stratum stratum, WordSynthesis output) { if (TraceStrataSynthesis) ((Trace) output.CurrentTraceObject).AddChild(new StratumSynthesisTrace(stratum, false, output.Clone())); }
public override void BeginUnapplyStratum(Stratum stratum, WordAnalysis input) { if (TraceStrataAnalysis) ((Trace) input.CurrentTraceObject).AddChild(new StratumAnalysisTrace(stratum, true, input.Clone())); }
public override void EndUnapplyStratum(Stratum stratum, WordAnalysis output) { if (TraceStrataAnalysis) ((Trace) output.CurrentTraceObject).AddChild(new StratumAnalysisTrace(stratum, false, output.Clone())); }
internal IEnumerable<RootAllomorph> SearchRootAllomorphs(Stratum stratum, Shape shape) { RootAllomorphTrie alloSearcher = _allomorphTries[stratum]; return alloSearcher.Search(shape).Distinct(); }