Ejemplo n.º 1
0
        public bool MatchSubrule(PhonologicalPatternRule rule, Match<Word, ShapeNode> match, out PhonologicalSubruleMatch subruleMatch)
        {
            foreach (RewriteSubruleSpec subruleSpec in _subruleSpecs)
            {
                if (!subruleSpec.IsApplicable(match.Input))
                    continue;

                ShapeNode leftNode, rightNode, startNode, endNode;
                if (_isTargetEmpty)
                {
                    if (match.Matcher.Direction == Direction.LeftToRight)
                    {
                        leftNode = match.Span.Start;
                        rightNode = match.Span.End.Next;
                    }
                    else
                    {
                        leftNode = match.Span.Start.Prev;
                        rightNode = match.Span.End;
                    }

                    startNode = leftNode;
                    endNode = rightNode;
                }
                else
                {
                    leftNode = match.Span.Start.Prev;
                    rightNode = match.Span.End.Next;
                    startNode = match.Span.Start;
                    endNode = match.Span.End;
                }

                if (leftNode == null || rightNode == null)
                {
                    subruleMatch = null;
                    return false;
                }

                VariableBindings varBindings = match.VariableBindings;
                Match<Word, ShapeNode> leftEnvMatch = subruleSpec.LeftEnvironmentMatcher == null ? null : subruleSpec.LeftEnvironmentMatcher.Match(match.Input, leftNode, varBindings);
                if (leftEnvMatch == null || leftEnvMatch.Success)
                {
                    if (leftEnvMatch != null && leftEnvMatch.VariableBindings != null)
                        varBindings = leftEnvMatch.VariableBindings;

                    Match<Word, ShapeNode> rightEnvMatch = subruleSpec.RightEnvironmentMatcher == null ? null : subruleSpec.RightEnvironmentMatcher.Match(match.Input, rightNode, varBindings);
                    if (rightEnvMatch == null || rightEnvMatch.Success)
                    {
                        if (rightEnvMatch != null && rightEnvMatch.VariableBindings != null)
                            varBindings = rightEnvMatch.VariableBindings;

                        subruleMatch = new PhonologicalSubruleMatch(subruleSpec, rule.SpanFactory.Create(startNode, endNode), varBindings);
                        return true;
                    }
                }
            }

            subruleMatch = null;
            return false;
        }
Ejemplo n.º 2
0
 public bool MatchSubrule(PhonologicalPatternRule rule, Match <Word, ShapeNode> match, out PhonologicalSubruleMatch subruleMatch)
 {
     subruleMatch = new PhonologicalSubruleMatch(this, match.Span, match.VariableBindings);
     return(true);
 }
 public bool MatchSubrule(PhonologicalPatternRule rule, Match<Word, ShapeNode> match, out PhonologicalSubruleMatch subruleMatch)
 {
     subruleMatch = new PhonologicalSubruleMatch(this, match.Span, match.VariableBindings);
     return true;
 }
Ejemplo n.º 4
0
        public bool MatchSubrule(PhonologicalPatternRule rule, Match <Word, ShapeNode> match, out PhonologicalSubruleMatch subruleMatch)
        {
            foreach (RewriteSubruleSpec subruleSpec in _subruleSpecs)
            {
                if (!subruleSpec.IsApplicable(match.Input))
                {
                    continue;
                }

                ShapeNode leftNode, rightNode, startNode, endNode;
                if (_isTargetEmpty)
                {
                    if (match.Matcher.Direction == Direction.LeftToRight)
                    {
                        leftNode  = match.Span.Start;
                        rightNode = match.Span.End.Next;
                    }
                    else
                    {
                        leftNode  = match.Span.Start.Prev;
                        rightNode = match.Span.End;
                    }

                    startNode = leftNode;
                    endNode   = rightNode;
                }
                else
                {
                    leftNode  = match.Span.Start.Prev;
                    rightNode = match.Span.End.Next;
                    startNode = match.Span.Start;
                    endNode   = match.Span.End;
                }

                if (leftNode == null || rightNode == null)
                {
                    subruleMatch = null;
                    return(false);
                }

                VariableBindings        varBindings  = match.VariableBindings;
                Match <Word, ShapeNode> leftEnvMatch = subruleSpec.LeftEnvironmentMatcher == null ? null : subruleSpec.LeftEnvironmentMatcher.Match(match.Input, leftNode, varBindings);
                if (leftEnvMatch == null || leftEnvMatch.Success)
                {
                    if (leftEnvMatch != null && leftEnvMatch.VariableBindings != null)
                    {
                        varBindings = leftEnvMatch.VariableBindings;
                    }

                    Match <Word, ShapeNode> rightEnvMatch = subruleSpec.RightEnvironmentMatcher == null ? null : subruleSpec.RightEnvironmentMatcher.Match(match.Input, rightNode, varBindings);
                    if (rightEnvMatch == null || rightEnvMatch.Success)
                    {
                        if (rightEnvMatch != null && rightEnvMatch.VariableBindings != null)
                        {
                            varBindings = rightEnvMatch.VariableBindings;
                        }

                        subruleMatch = new PhonologicalSubruleMatch(subruleSpec, rule.SpanFactory.Create(startNode, endNode), varBindings);
                        return(true);
                    }
                }
            }

            subruleMatch = null;
            return(false);
        }