Example #1
0
 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();
 }
Example #2
0
        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);
        }
Example #3
0
        private CompoundingSubrule LoadCompoundingSubrule(XElement compSubruleElem, CharacterDefinitionTable defaultTable)
        {
            var subrule = new CompoundingSubrule();

            Dictionary<string, Tuple<string, SymbolicFeature>> variables = LoadVariables(compSubruleElem.Element("VariableFeatures"));

            XElement headElem = compSubruleElem.Element("HeadMorphologicalInput");
            Debug.Assert(headElem != null);

            subrule.RequiredMprFeatures.UnionWith(LoadMprFeatures((string) headElem.Attribute("requiredMPRFeatures")));
            subrule.ExcludedMprFeatures.UnionWith(LoadMprFeatures((string) headElem.Attribute("excludedMPRFeatures")));

            var partNames = new Dictionary<string, string>();
            LoadMorphologicalLhs(headElem, variables, partNames, subrule.HeadLhs, defaultTable, "head_");

            XElement nonHeadElem = compSubruleElem.Element("NonHeadMorphologicalInput");
            Debug.Assert(nonHeadElem != null);

            LoadMorphologicalLhs(nonHeadElem, variables, partNames, subrule.NonHeadLhs, defaultTable, "nonhead_");

            XElement outputElem = compSubruleElem.Element("MorphologicalOutput");
            Debug.Assert(outputElem != null);

            subrule.OutMprFeatures.UnionWith(LoadMprFeatures((string) outputElem.Attribute("MPRFeatures")));

            LoadMorphologicalRhs(outputElem, variables, partNames, subrule.Rhs, defaultTable);

            return subrule;
        }