public AnalysisCompoundingSubruleRuleSpec(CompoundingSubrule subrule) : base(subrule.HeadLhs.Concat(subrule.NonHeadLhs), subrule.Rhs) { _subrule = subrule; Pattern.Acceptable = match => _subrule.HeadLhs.Any(part => IsPartCaptured(match, part.Name)); Pattern.Freeze(); }
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.Clone(); output.Shape.Clear(); var existingMorphNodes = new Dictionary <string, 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) { var allomorphID = (string)mapping.Item1.Annotation.Parent.FeatureStruct .GetValue(HCFeatureSystem.Allomorph); existingMorphNodes.GetOrCreate(allomorphID, () => new List <ShapeNode>()).Add(mapping.Item2); } } } } if (existingMorphNodes.Count > 0) { foreach (Allomorph allomorph in headMatch.Input.AllomorphsInMorphOrder) { List <ShapeNode> nodes; if (existingMorphNodes.TryGetValue(allomorph.ID, out nodes)) { output.MarkMorph(nodes, allomorph); } } } output.MarkMorph(newMorphNodes, headMatch.Input.CurrentNonHead.RootAllomorph); return(output); }