public void ParseFailed(Language lang, Word word, FailureReason reason, Allomorph allomorph, object failureObj) { ((Trace)word.CurrentTrace).Children.Add(new Trace(TraceType.ParseFailed, lang) { Output = word, FailureReason = reason }); }
private bool Exists(Allomorph operand) { if (Position == Position.BeforeSource) { while (operand.HasPrevious) { if (operand.Morpheme.Id == Operand) { return(true); } operand = operand.Previous; } } if (Position == Position.AfterTarget) { if (operand.Morpheme.Id == Operand) { return(true); } while (operand.HasNext) { operand = operand.Next; if (operand.Morpheme.Id == Operand) { return(true); } } } throw new ArgumentException("Invalid position for MorphemeExists: " + Position); }
public override bool IsTrueFor(Allomorph allomorph) { string neighbourSurface = allomorph.GetSurface(Position); char? penultVowel = neighbourSurface.PenultimateOccurrenceOfAny(Alphabet.Vowels); return(penultVowel.HasValue && Operand.IndexOf((char)penultVowel) != -1); }
private XElement CreateAllomorphElement(Allomorph allomorph) { bool isNull = (bool?)allomorph.Properties["IsNull"] ?? false; if (isNull) { var slotID = (int)allomorph.Morpheme.Properties["SlotID"]; IMoInflAffixSlot slot; if (!m_cache.ServiceLocator.GetInstance <IMoInflAffixSlotRepository>().TryGetObject(slotID, out slot)) { return(null); } var nullInflTypeID = (int)allomorph.Morpheme.Properties["InflTypeID"]; ILexEntryInflType nullInflType; if (!m_cache.ServiceLocator.GetInstance <ILexEntryInflTypeRepository>().TryGetObject(nullInflTypeID, out nullInflType)) { return(null); } var isPrefix = (bool)allomorph.Properties["IsPrefix"]; return(new XElement("Allomorph", new XAttribute("id", 0), new XAttribute("type", isPrefix ? MoMorphTypeTags.kMorphPrefix : MoMorphTypeTags.kMorphSuffix), new XElement("Form", "^0"), new XElement("Morpheme", new XAttribute("id", 0), new XAttribute("type", "infl"), new XElement("HeadWord", string.Format("Automatically generated null affix for the {0} irregularly inflected form", nullInflType.Name.BestAnalysisAlternative.Text)), new XElement("Gloss", (nullInflType.GlossPrepend.BestAnalysisAlternative.Text == "***" ? "" : nullInflType.GlossPrepend.BestAnalysisAlternative.Text) + (nullInflType.GlossAppend.BestAnalysisAlternative.Text == "***" ? "" : nullInflType.GlossAppend.BestAnalysisAlternative.Text)), new XElement("Category", slot.OwnerOfClass <IPartOfSpeech>().Abbreviation.BestAnalysisAlternative.Text), new XElement("Slot", new XAttribute("optional", slot.Optional), slot.Name.BestAnalysisAlternative.Text)))); } var formID = (int?)allomorph.Properties["ID"] ?? 0; IMoForm form; if (formID == 0 || !m_cache.ServiceLocator.GetInstance <IMoFormRepository>().TryGetObject(formID, out form)) { return(null); } var formID2 = (int?)allomorph.Properties["ID2"] ?? 0; var msaID = (int)allomorph.Morpheme.Properties["ID"]; IMoMorphSynAnalysis msa; if (!m_cache.ServiceLocator.GetInstance <IMoMorphSynAnalysisRepository>().TryGetObject(msaID, out msa)) { return(null); } var inflTypeID = (int?)allomorph.Morpheme.Properties["InflTypeID"] ?? 0; ILexEntryInflType inflType = null; if (inflTypeID != 0 && !m_cache.ServiceLocator.GetInstance <ILexEntryInflTypeRepository>().TryGetObject(inflTypeID, out inflType)) { return(null); } return(HCParser.CreateAllomorphElement("Allomorph", form, msa, inflType, formID2 != 0)); }
protected override bool ConstraintsEqual(Allomorph other) { var otherAllo = other as RootAllomorph; if (otherAllo == null) return false; return base.ConstraintsEqual(other) && IsBound == otherAllo.IsBound; }
public void Do(Allomorph allomorph, Position position) { Allomorph operand; if (TryGetOperandMorpheme(allomorph, out operand, position)) { Do(operand); } }
public bool IsTrue(Allomorph allomorph) { if (IsEmpty) { return(true); } return(_flag ? AreAllConditionsTrue(allomorph) : IsAnyConditionTrue(allomorph)); }
public override void Do(Allomorph allomorph, Position position) { Allomorph operand; if (TryGetOperandMorpheme(allomorph, out operand, position)) { operand.Surface = _Replace(operand.Surface); } }
public Word ApplyRhs(PatternRule <Word, ShapeNode> rule, Match <Word, ShapeNode> match) { Word output = match.Input.DeepClone(); output.Shape.Clear(); var existingMorphNodes = new Dictionary <Annotation <ShapeNode>, List <ShapeNode> >(); var newMorphNodes = new List <ShapeNode>(); foreach (MorphologicalOutputAction outputAction in _allomorph.Rhs) { foreach (Tuple <ShapeNode, ShapeNode> mapping in outputAction.Apply(match, output)) { if (mapping.Item1 != null && _nonAllomorphActions.Contains(outputAction)) { if (mapping.Item1.Annotation.Parent != null) { Annotation <ShapeNode> morph = mapping.Item1.Annotation.Parent; existingMorphNodes.GetValue(morph, () => new List <ShapeNode>()).Add(mapping.Item2); } } else { newMorphNodes.Add(mapping.Item2); } } } Annotation <ShapeNode> outputNewMorph = MarkMorphs(newMorphNodes, output, _allomorph); var markedAllomorphs = new HashSet <Allomorph>(); foreach (Annotation <ShapeNode> inputMorph in match.Input.Morphs) { Allomorph allomorph = match.Input.GetAllomorph(inputMorph); List <ShapeNode> nodes; if (existingMorphNodes.TryGetValue(inputMorph, out nodes)) { Annotation <ShapeNode> outputMorph = MarkMorphs(nodes, output, allomorph); MarkSubsumedMorphs(match.Input, output, inputMorph, outputMorph); } else if (inputMorph.Parent == null && !markedAllomorphs.Contains(allomorph)) { // an existing morph has been completely subsumed by the new morph // mark the subsumed morph so we don't lose track of it // this is only necessary if the allomorph hasn't already been marked elsewhere Annotation <ShapeNode> outputMorph = output.MarkSubsumedMorph(outputNewMorph, allomorph); MarkSubsumedMorphs(match.Input, output, inputMorph, outputMorph); } markedAllomorphs.Add(allomorph); } output.MprFeatures.AddOutput(_allomorph.OutMprFeatures); return(output); }
private bool IsAnyConditionTrue(Allomorph allomorph) { foreach (ConditionBase condition in _conditions) { if (condition.IsTrueFor(allomorph)) { return(true); } } return(false); }
public override bool IsTrueFor(Allomorph allomorph) { Allomorph operand; if (TryGetOperandMorpheme(allomorph, out operand)) { return(!operand.HasNext); } return(false); }
public void Process(Allomorph allomorph) { foreach (Transformation transformation in _transformations) { if (transformation.Condition.IsTrue(allomorph)) { transformation.Transform(allomorph); break; } } }
public override bool IsTrueFor(Allomorph allomorph) { Allomorph neighbour; if (TryGetOperandMorpheme(allomorph, out neighbour)) { return(IterateSequence(neighbour)); } return(false); }
public override bool IsTrueFor(Allomorph allomorph) { Allomorph operand; if (TryGetOperandMorpheme(allomorph, out operand)) { return(operand.Morpheme.HasLabel(_label)); } return(false); }
public override bool IsTrueFor(Allomorph allomorph) { Allomorph operand; if (TryGetOperandMorpheme(allomorph, out operand)) { return(Operand == operand.Morpheme.Id); } return(false); }
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; } }
protected override bool ConstraintsEqual(Allomorph other) { var otherAllo = other as AffixProcessAllomorph; if (otherAllo == null) { return(false); } return(base.ConstraintsEqual(other) && _requiredMprFeatures.SetEquals(otherAllo._requiredMprFeatures) && _excludedMprFeatures.SetEquals(otherAllo._excludedMprFeatures) && _lhs.SequenceEqual(otherAllo._lhs, FreezableEqualityComparer <Pattern <Word, ShapeNode> > .Default) && RequiredSyntacticFeatureStruct.ValueEquals(otherAllo.RequiredSyntacticFeatureStruct)); }
private void MarkSubsumedMorphs(Word input, Word output, Annotation <ShapeNode> inputMorph, Annotation <ShapeNode> outputMorph) { if (inputMorph.IsLeaf) { return; } foreach (Annotation <ShapeNode> inputChild in inputMorph.Children.Where(ann => ann.Type() == HCFeatureSystem.Morph)) { Allomorph allomorph = input.GetAllomorph(inputChild); Annotation <ShapeNode> outputChild = output.MarkSubsumedMorph(outputMorph, allomorph); MarkSubsumedMorphs(input, output, inputChild, outputChild); } }
public Word ApplyRhs(PatternRule <Word, ShapeNode> rule, Match <Word, ShapeNode> match) { Word output = match.Input.Clone(); output.Shape.Clear(); var existingMorphNodes = new Dictionary <Allomorph, List <ShapeNode> >(); var newMorphNodes = new List <ShapeNode>(); foreach (MorphologicalOutputAction outputAction in _allomorph.Rhs) { foreach (Tuple <ShapeNode, ShapeNode> mapping in outputAction.Apply(match, output)) { if (mapping.Item1 != null && _nonAllomorphActions.Contains(outputAction)) { if (mapping.Item1.Annotation.Parent != null) { Allomorph allomorph = match.Input.GetAllomorph(mapping.Item1.Annotation.Parent); existingMorphNodes.GetOrCreate(allomorph, () => new List <ShapeNode>()).Add(mapping.Item2); } } else { newMorphNodes.Add(mapping.Item2); } } } Annotation <ShapeNode> outputNewMorph = output.MarkMorph(newMorphNodes, _allomorph); foreach (Annotation <ShapeNode> inputMorph in match.Input.Morphs) { Allomorph allomorph = match.Input.GetAllomorph(inputMorph); List <ShapeNode> nodes; if (existingMorphNodes.TryGetValue(allomorph, out nodes)) { Annotation <ShapeNode> outputMorph = output.MarkMorph(nodes, allomorph); MarkSubsumedMorphs(match.Input, output, inputMorph, outputMorph); } else if (inputMorph.Parent == null) { Annotation <ShapeNode> outputMorph = output.MarkSubsumedMorph(outputNewMorph, allomorph); MarkSubsumedMorphs(match.Input, output, inputMorph, outputMorph); } } output.MprFeatures.AddOutput(_allomorph.OutMprFeatures); return(output); }
protected override void Write(string localName, Allomorph allo) { m_xmlWriter.WriteStartElement(localName); m_xmlWriter.WriteAttributeString("id", allo.ID); m_xmlWriter.WriteElementString("Description", allo.Description); string formIdsStr = allo.GetProperty("FormID"); string msaId = allo.GetProperty("MsaID"); if (!string.IsNullOrEmpty(formIdsStr) || !string.IsNullOrEmpty(msaId)) { m_xmlWriter.WriteStartElement("Morph"); if (!string.IsNullOrEmpty(formIdsStr)) { string[] formIds = formIdsStr.Split(' '); string[] wordTypes = allo.GetProperty("WordCategory").Split(' '); for (int i = 0; i < formIds.Length; i++) { m_xmlWriter.WriteStartElement("MoForm"); m_xmlWriter.WriteAttributeString("DbRef", formIds[i]); m_xmlWriter.WriteAttributeString("wordType", wordTypes[i]); m_xmlWriter.WriteEndElement(); m_xmlWriter.WriteStartElement("props"); foreach (KeyValuePair <string, string> prop in allo.Properties) { if (prop.Key == "FeatureDescriptors") { m_xmlWriter.WriteString(prop.Value); } } m_xmlWriter.WriteEndElement(); } } if (!string.IsNullOrEmpty(msaId)) { m_xmlWriter.WriteStartElement("MSI"); m_xmlWriter.WriteAttributeString("DbRef", msaId); m_xmlWriter.WriteEndElement(); } m_xmlWriter.WriteEndElement(); } m_xmlWriter.WriteEndElement(); }
public override void Do(Allomorph allomorph, Position position) { Allomorph neighbour = allomorph; switch (position) { case Position.Next: neighbour = allomorph.Next; break; case Position.Previous: neighbour = allomorph.Previous; break; } neighbour.Surface = neighbour.Surface.DeleteLastChar(); }
private Word ApplySubrule(CompoundingSubrule sr, Match <Word, ShapeNode> headMatch, Match <Word, ShapeNode> nonHeadMatch) { // TODO: unify the variable bindings from the head and non-head matches Word output = headMatch.Input.DeepClone(); output.Shape.Clear(); var existingMorphNodes = new Dictionary <Annotation <ShapeNode>, List <ShapeNode> >(); var newMorphNodes = new List <ShapeNode>(); foreach (MorphologicalOutputAction outputAction in sr.Rhs) { if (outputAction.PartName != null && nonHeadMatch.GroupCaptures.Captured(outputAction.PartName)) { newMorphNodes.AddRange(outputAction.Apply(nonHeadMatch, output).Select(mapping => mapping.Item2)); } else { foreach (Tuple <ShapeNode, ShapeNode> mapping in outputAction.Apply(headMatch, output)) { if (mapping.Item1 != null && mapping.Item1.Annotation.Parent != null) { Annotation <ShapeNode> morph = mapping.Item1.Annotation.Parent; existingMorphNodes.GetValue(morph, () => new List <ShapeNode>()).Add(mapping.Item2); } } } } if (existingMorphNodes.Count > 0) { foreach (Annotation <ShapeNode> inputMorph in headMatch.Input.Morphs) { List <ShapeNode> nodes; if (existingMorphNodes.TryGetValue(inputMorph, out nodes)) { Allomorph allomorph = headMatch.Input.GetAllomorph(inputMorph); output.MarkMorph(nodes, allomorph); } } } output.MarkMorph(newMorphNodes, headMatch.Input.CurrentNonHead.RootAllomorph); return(output); }
protected bool TryGetOperandMorpheme(Allomorph allomorph, out Allomorph operand, Position position) // out parameter for result { switch (position) { case Position.This: operand = allomorph; return(true); case Position.Next: operand = allomorph.Next; return(allomorph.HasNext); case Position.Previous: operand = allomorph.Previous; return(allomorph.HasPrevious); default: throw new ArgumentException("Invalid Position for Action : " + position); } }
private bool IterateSequence(Allomorph neighbour) { if (Position == Position.BeforeSource) { for (int i = _sequence.Length - 1; i >= 0; i--) { if (_sequence[i] != neighbour.Morpheme.Id) { return(false); } if (neighbour.HasPrevious) { neighbour = neighbour.Previous; } } return(true); } if (Position == Position.AfterTarget) { for (int i = 0; i < _sequence.Length; i++) { if (_sequence[i] != neighbour.Morpheme.Id) { return(false); } if (neighbour.HasNext) { neighbour = neighbour.Next; } } return(true); } throw new ArgumentException("Invalid Morpheme Position for MorphemeSequenceEquals: " + Position); }
protected bool TryGetOperandMorpheme(Allomorph allomorph, out Allomorph operand) // out parameter for result { switch (Position) { case Position.Next: case Position.Target: operand = allomorph.Next; return(allomorph.HasNext); case Position.Previous: case Position.BeforeSource: operand = allomorph.Previous; return(allomorph.HasPrevious); case Position.This: case Position.Source: operand = allomorph; return(true); case Position.First: operand = allomorph.First; return(true); case Position.AfterTarget: if (allomorph.HasNext) { operand = allomorph.Next.Next; return(allomorph.Next.HasNext); } operand = null; return(false); default: throw new ArgumentException($"Invalid Argument : {Position}"); } }
public override bool ConstraintsEqual(Allomorph other) { Subrule otherSubrule = (Subrule) other; if (m_requiredMPRFeatures == null) { if (otherSubrule.m_requiredMPRFeatures != null) return false; } else { if (!m_requiredMPRFeatures.Equals(otherSubrule.m_requiredMPRFeatures)) return false; } if (m_excludedMPRFeatures == null) { if (otherSubrule.m_excludedMPRFeatures != null) return false; } else { if (!m_excludedMPRFeatures.Equals(otherSubrule.m_excludedMPRFeatures)) return false; } return m_lhsTemp.Equals(otherSubrule.m_lhsTemp) && base.ConstraintsEqual(other); }
public void ParseFailed(Language lang, Word word, FailureReason reason, Allomorph allomorph, object failureObj) { XElement trace; switch (reason) { case FailureReason.ExcludedAllomorphCoOccurrences: var alloRule = (AllomorphCoOccurrenceRule) failureObj; trace = CreateParseCompleteElement(word, new XElement("FailureReason", new XAttribute("type", "adhocProhibitionRule"), new XElement("RuleType", "Allomorph"), CreateAllomorphElement(allomorph), new XElement("Others", alloRule.Others.Select(CreateAllomorphElement)), new XElement("Adjacency", alloRule.Adjacency))); break; case FailureReason.ExcludedMorphemeCoOccurrences: var morphemeRule = (MorphemeCoOccurrenceRule) failureObj; trace = CreateParseCompleteElement(word, new XElement("FailureReason", new XAttribute("type", "adhocProhibitionRule"), new XElement("RuleType", "Morpheme"), CreateMorphemeElement(allomorph.Morpheme), new XElement("Others", morphemeRule.Others.Select(CreateMorphemeElement)), new XElement("Adjacency", morphemeRule.Adjacency))); break; case FailureReason.RequiredEnvironments: trace = CreateParseCompleteElement(word, new XElement("FailureReason", new XAttribute("type", "environment"), CreateAllomorphElement(allomorph), new XElement("Environment", failureObj))); break; case FailureReason.SurfaceFormMismatch: trace = CreateParseCompleteElement(word, new XElement("FailureReason", new XAttribute("type", "formMismatch"))); break; case FailureReason.RequiredSyntacticFeatureStruct: trace = CreateParseCompleteElement(word, new XElement("FailureReason", new XAttribute("type", "affixInflFeats"), CreateAllomorphElement(allomorph), CreateInflFeaturesElement("InflFeatures", word.SyntacticFeatureStruct), CreateInflFeaturesElement("RequiredInflFeatures", (FeatureStruct) failureObj))); break; case FailureReason.StemName: trace = CreateParseCompleteElement(word, new XElement("FailureReason", new XAttribute("type", "stemName"), CreateAllomorphElement(allomorph), new XElement("StemName", failureObj))); break; case FailureReason.BoundRoot: trace = CreateParseCompleteElement(word, new XElement("FailureReason", new XAttribute("type", "boundStem"))); break; case FailureReason.DisjunctiveAllomorph: trace = CreateParseCompleteElement(word, new XElement("FailureReason", new XAttribute("type", "disjunctiveAllomorph"), CreateWordElement("Word", (Word) failureObj, false))); break; case FailureReason.PartialParse: trace = CreateParseCompleteElement(word, new XElement("FailureReason", new XAttribute("type", "partialParse"))); break; default: return; } ((XElement) word.CurrentTrace).Add(trace); }
protected override void Write(string localName, Allomorph allo) { m_xmlWriter.WriteStartElement(localName); m_xmlWriter.WriteAttributeString("id", allo.ID); m_xmlWriter.WriteElementString("Description", allo.Description); string formIdsStr = allo.GetProperty("FormID"); string msaId = allo.GetProperty("MsaID"); if (!string.IsNullOrEmpty(formIdsStr) || !string.IsNullOrEmpty(msaId)) { m_xmlWriter.WriteStartElement("Morph"); if (!string.IsNullOrEmpty(formIdsStr)) { string[] formIds = formIdsStr.Split(' '); string[] wordTypes = allo.GetProperty("WordCategory").Split(' '); for (int i = 0; i < formIds.Length; i++) { m_xmlWriter.WriteStartElement("MoForm"); m_xmlWriter.WriteAttributeString("DbRef", formIds[i]); m_xmlWriter.WriteAttributeString("wordType", wordTypes[i]); m_xmlWriter.WriteEndElement(); } } if (!string.IsNullOrEmpty(msaId)) { m_xmlWriter.WriteStartElement("MSI"); m_xmlWriter.WriteAttributeString("DbRef", msaId); m_xmlWriter.WriteEndElement(); } m_xmlWriter.WriteEndElement(); } m_xmlWriter.WriteEndElement(); }
public abstract void MorphologicalRuleApplied(MorphologicalRule rule, WordSynthesis input, WordSynthesis output, Allomorph allomorph);
public override bool IsTrueFor(Allomorph allomorph) { return(!base.IsTrueFor(allomorph)); }
/// <summary> /// Applies the simple context to the input partition and copies it over to the output /// phonetic shape. /// </summary> /// <param name="match">The match.</param> /// <param name="input">The input word synthesis.</param> /// <param name="output">The output word synthesis.</param> /// <param name="morpheme">The morpheme info.</param> public override void Apply(Match match, WordSynthesis input, WordSynthesis output, Allomorph allomorph) { IList<PhoneticShapeNode> nodes = match.GetPartition(m_partition); if (nodes != null && nodes.Count > 0) { Morph morph = null; if (allomorph != null) { morph = new Morph(allomorph); output.Morphs.Add(morph); } for (PhoneticShapeNode node = nodes[0]; node != nodes[nodes.Count - 1].Next; node = node.Next) { PhoneticShapeNode newNode = node.Clone(); if (node.Type == PhoneticShapeNode.NodeType.SEGMENT) { Segment seg = newNode as Segment; // sets the context's features on the segment m_ctxt.Apply(seg, match.VariableValues); seg.IsClean = false; seg.Partition = morph == null ? -1 : morph.Partition; } if (morph != null) morph.Shape.Add(newNode.Clone()); output.Shape.Add(newNode); } } }
/// <summary> /// Adds the allomorph. /// </summary> /// <param name="allomorph">The allomorph.</param> public void AddAllomorph(Allomorph allomorph) { m_allomorphs.Add(allomorph); }
public abstract void MorphologicalRuleUnapplied(MorphologicalRule rule, WordAnalysis input, WordAnalysis output, Allomorph allomorph);
protected virtual XElement Write(string name, Allomorph allomorph) { XElement elem = Write(name, (HCObject) allomorph); elem.Add(Write("Morpheme", allomorph.Morpheme)); elem.Add(new XElement("Properties", allomorph.Properties.Select(prop => new XElement("Property", new XElement("Key", prop.Key), new XElement("Value", prop.Value))))); return elem; }
public override void MorphologicalRuleApplied(MorphologicalRule rule, WordSynthesis input, WordSynthesis output, Allomorph allomorph) { if (IsSynthesisTracingEnabled(rule.ID)) { var trace = new XElement("MorphologicalRuleSynthesisTrace", Write("MorphologicalRule", rule)); if (allomorph != null) trace.Add(Write("RuleAllomorph", allomorph)); if (WriteInputs) trace.Add(Write("Input", input)); trace.Add(Write("Output", output)); ((XElement) output.CurrentTraceObject).Add(trace); output.CurrentTraceObject = trace; } }
protected virtual void Write(string localName, Allomorph allo) { m_xmlWriter.WriteStartElement(localName); m_xmlWriter.WriteAttributeString("id", allo.ID); m_xmlWriter.WriteElementString("Description", allo.Description); Write("Morpheme", allo.Morpheme); m_xmlWriter.WriteStartElement("Properties"); foreach (KeyValuePair<string, string> prop in allo.Properties) { m_xmlWriter.WriteStartElement("Property"); m_xmlWriter.WriteElementString("Key", prop.Key); m_xmlWriter.WriteElementString("Value", prop.Value); m_xmlWriter.WriteEndElement(); } m_xmlWriter.WriteEndElement(); m_xmlWriter.WriteEndElement(); }
/// <summary> /// Copies a partition from the input phonetic shape to the output phonetic shape. /// </summary> /// <param name="match">The match.</param> /// <param name="input">The input word synthesis.</param> /// <param name="output">The output word synthesis.</param> /// <param name="morpheme">The morpheme info.</param> public override void Apply(Match match, WordSynthesis input, WordSynthesis output, Allomorph allomorph) { IList<PhoneticShapeNode> nodes = match.GetPartition(m_partition); if (nodes != null && nodes.Count > 0) { Morph morph = null; for (PhoneticShapeNode node = nodes[0]; node != nodes[nodes.Count - 1].Next; node = node.Next) { PhoneticShapeNode newNode = node.Clone(); // mark the reduplicated segments with the gloss partition if (m_redup) { if (allomorph != null) { if (morph == null) { morph = new Morph(allomorph); output.Morphs.Add(morph); } newNode.Partition = morph.Partition; morph.Shape.Add(node.Clone()); } else { newNode.Partition = -1; } } else if (node.Partition != -1) { if (morph == null || morph.Partition != node.Partition) { morph = input.Morphs[node.Partition].Clone(); morph.Shape.Clear(); output.Morphs.Add(morph); } newNode.Partition = morph.Partition; morph.Shape.Add(node.Clone()); } output.Shape.Add(newNode); } } }
/// <summary> /// Inserts a segment based on a simple context to the output. /// </summary> /// <param name="match">The match.</param> /// <param name="input">The input word synthesis.</param> /// <param name="output">The output word synthesis.</param> /// <param name="morpheme">The morpheme info.</param> public override void Apply(Match match, WordSynthesis input, WordSynthesis output, Allomorph allomorph) { Segment newSeg = m_ctxt.ApplyInsertion(match.VariableValues); if (allomorph != null) { Morph morph = new Morph(allomorph); output.Morphs.Add(morph); morph.Shape.Add(newSeg.Clone()); newSeg.Partition = morph.Partition; } output.Shape.Add(newSeg); }
private XElement CreateAllomorphElement(Allomorph allomorph) { bool isNull = (bool?) allomorph.Properties["IsNull"] ?? false; if (isNull) { var slotID = (int) allomorph.Morpheme.Properties["SlotID"]; IMoInflAffixSlot slot; if (!m_cache.ServiceLocator.GetInstance<IMoInflAffixSlotRepository>().TryGetObject(slotID, out slot)) return null; var inflTypeID = (int) allomorph.Morpheme.Properties["InflTypeID"]; ILexEntryInflType inflType; if (!m_cache.ServiceLocator.GetInstance<ILexEntryInflTypeRepository>().TryGetObject(inflTypeID, out inflType)) return null; var isPrefix = (bool) allomorph.Properties["IsPrefix"]; return new XElement("Allomorph", new XAttribute("id", 0), new XAttribute("type", isPrefix ? MoMorphTypeTags.kMorphPrefix : MoMorphTypeTags.kMorphSuffix), new XElement("Form", "^0"), new XElement("Morpheme", new XAttribute("id", 0), new XAttribute("type", "infl"), new XElement("HeadWord", string.Format("Automatically generated null affix for the {0} irregularly inflected form", inflType.Name.BestAnalysisAlternative.Text)), new XElement("Gloss", (inflType.GlossPrepend.BestAnalysisAlternative.Text == "***" ? "" : inflType.GlossPrepend.BestAnalysisAlternative.Text) + (inflType.GlossAppend.BestAnalysisAlternative.Text == "***" ? "" : inflType.GlossAppend.BestAnalysisAlternative.Text)), new XElement("Category", slot.OwnerOfClass<IPartOfSpeech>().Abbreviation.BestAnalysisAlternative.Text), new XElement("Slot", new XAttribute("optional", slot.Optional), slot.Name.BestAnalysisAlternative.Text))); } var formID = (int?) allomorph.Properties["ID"] ?? 0; IMoForm form; if (formID == 0 || !m_cache.ServiceLocator.GetInstance<IMoFormRepository>().TryGetObject(formID, out form)) return null; var formID2 = (int?) allomorph.Properties["ID2"] ?? 0; var msaID = (int) allomorph.Morpheme.Properties["ID"]; IMoMorphSynAnalysis msa; if (!m_cache.ServiceLocator.GetInstance<IMoMorphSynAnalysisRepository>().TryGetObject(msaID, out msa)) return null; return HCParser.CreateAllomorphElement("Allomorph", form, msa, formID2 != 0); }
protected override void Do(Allomorph allomorph) { allomorph.Surface = allomorph.Surface.DeleteFirstChar(); }
public override void Do(Allomorph allomorph, Position position) { allomorph.Surface = allomorph.Surface.DeleteLastOccurrenceOfAny(Alphabet.Vowels); }
protected override void Do(Allomorph allomorph) { allomorph.Surface = ""; }
private Annotation <ShapeNode> MarkMorphs(List <ShapeNode> nodes, Word output, Allomorph allomorph) { Annotation <ShapeNode> longestMorph = null; var curMorphNodes = new List <ShapeNode>(); for (int i = 0; i < nodes.Count; i++) { curMorphNodes.Add(nodes[i]); // only contiguous nodes should be marked as a morph if (i == nodes.Count - 1 || nodes[i].Next != nodes[i + 1]) { Annotation <ShapeNode> morph = output.MarkMorph(curMorphNodes, allomorph); if (longestMorph == null || morph.Range.Length > longestMorph.Range.Length) { longestMorph = morph; } curMorphNodes.Clear(); } } return(longestMorph); }
/// <summary> /// Inserts the segments and boundaries in to the output phonetic shape. /// </summary> /// <param name="match">The match.</param> /// <param name="input">The input word synthesis.</param> /// <param name="output">The output word synthesis.</param> /// <param name="morpheme">The morpheme info.</param> public override void Apply(Match match, WordSynthesis input, WordSynthesis output, Allomorph allomorph) { Morph morph = null; if (allomorph != null) { morph = new Morph(allomorph); output.Morphs.Add(morph); } for (PhoneticShapeNode node = m_pshape.Begin; node != m_pshape.Last; node = node.Next) { PhoneticShapeNode newNode = node.Clone(); if (morph != null) { newNode.Partition = morph.Partition; morph.Shape.Add(node.Clone()); } else { newNode.Partition = -1; } output.Shape.Add(newNode); } }
protected override XElement Write(string name, Allomorph allomorph) { XElement elem = Write(name, (HCObject)allomorph); string formIdsStr = allomorph.GetProperty("FormID"); string msaId = allomorph.GetProperty("MsaID"); if (!String.IsNullOrEmpty(formIdsStr) || !String.IsNullOrEmpty(msaId)) { var morphElem = new XElement("Morph"); string firstFormId = null; string firstWordType = null; string featDesc = allomorph.GetProperty("FeatureDescriptors"); if (!String.IsNullOrEmpty(formIdsStr)) { string[] formIds = formIdsStr.Split(' '); string[] wordTypes = allomorph.GetProperty("WordCategory").Split(' '); for (int i = 0; i < formIds.Length; i++) { int wordTypeIndex = WordTypeIndex(i, wordTypes.Length); string wordType = wordTypes[wordTypeIndex]; morphElem.Add(new XElement("MoForm", new XAttribute("DbRef", formIds[i]), new XAttribute("wordType", wordType))); morphElem.Add(string.IsNullOrEmpty(featDesc) ? new XElement("props") : new XElement("props", featDesc)); if (i == 0) { firstFormId = formIds[i]; firstWordType = wordType; } } } if (!String.IsNullOrEmpty(msaId)) { var msiElement = new XElement("MSI", new XAttribute("DbRef", msaId)); using (XmlWriter writer = msiElement.CreateWriter()) writer.WriteMsaElement(m_cache, firstFormId, msaId, null, firstWordType); morphElem.Add(msiElement); } using (XmlWriter writer = morphElem.CreateWriter()) writer.WriteMorphInfoElements(m_cache, firstFormId, msaId, firstWordType, featDesc); elem.Add(morphElem); } return elem; }
public void ParseFailed(Language lang, Word word, FailureReason reason, Allomorph allomorph, object failureObj) { ((Trace) word.CurrentTrace).Children.Add(new Trace(TraceType.ParseFailed, lang) {Output = word, FailureReason = reason}); }
protected override void Do(Allomorph allomorph) { allomorph.Surface = allomorph.Surface.DeleteFirstOccurrenceOfAny(Alphabet.Vowels); }
protected override bool ConstraintsEqual(Allomorph other) { var otherAllo = other as AffixProcessAllomorph; if (otherAllo == null) return false; return base.ConstraintsEqual(other) && _requiredMprFeatures.SetEquals(otherAllo._requiredMprFeatures) && _excludedMprFeatures.SetEquals(otherAllo._excludedMprFeatures) && _lhs.SequenceEqual(otherAllo._lhs, FreezableEqualityComparer<Pattern<Word, ShapeNode>>.Default) && RequiredSyntacticFeatureStruct.ValueEquals(otherAllo.RequiredSyntacticFeatureStruct); }
public override bool IsTrueFor(Allomorph allomorph) { string neighbourSurface = allomorph.GetSurface(Position); return(neighbourSurface.LastCharEqualsAny(Alphabet.Vowels)); }
/// <summary> /// Applies this output record to the specified word synthesis. /// </summary> /// <param name="match">The match.</param> /// <param name="input">The input word synthesis.</param> /// <param name="output">The output word synthesis.</param> /// <param name="morpheme">The morpheme info.</param> public abstract void Apply(Match match, WordSynthesis input, WordSynthesis output, Allomorph allomorph);