Exemple #1
0
        internal bool Connect(ActiveEdge edge)
        {
            if (!_activeEdges.Add(edge))
            {
                return(false);
            }

            var currentTerm = edge.Label.CurrentTerm;
            var terminal    = edge.Label.TerminalLabel;

            if (terminal != null)
            {
                //label is waiting for terminal
                _waitingTerminals.Add(terminal);
            }


            HashSet <ActiveEdge> extensible;

            if (!_extensibleEdges.TryGetValue(currentTerm, out extensible))
            {
                extensible = new HashSet <ActiveEdge>();
                _extensibleEdges[currentTerm] = extensible;
            }

            extensible.Add(edge);
            return(true);
        }
Exemple #2
0
        internal ActiveEdge(ActiveEdge extendedEdge, CompleteEdge extendingEdge)
            : base(extendedEdge.StartContext, extendingEdge.EndContext)
        {
            ExtendingEdge = extendingEdge;

            ExtendedEdge = extendedEdge;
            Label        = ExtendedEdge.Label.NextInChain;
        }
Exemple #3
0
 internal CompleteEdge(ActiveEdge extendedEdge, CompleteEdge extendingEdge)
     : base(extendedEdge.StartContext, extendingEdge.EndContext)
 {
     CompleteLabel = extendedEdge.Label.CompleteLabel;
     Parent        = CompleteLabel.Parent;
     ExtendedEdge  = extendedEdge;
     ExtendingEdge = extendingEdge;
 }
Exemple #4
0
        private static void predict(CompleteEdge constituent, ActiveEdge edge)
        {
            //TODO check if new possible interpretation of input is added
            var newEdge    = edge.ExtendBy(constituent);
            var endContext = newEdge.EndContext;

            if (endContext.Connect(newEdge))
            {
                foreach (var transition in newEdge.Label.Transitions)
                {
                    var transitionEdge = new ActiveEdge(transition, newEdge);
                    endContext.Connect(transitionEdge);
                }
            }
        }
Exemple #5
0
        private void complete(CompleteEdge constituent, ActiveEdge edge)
        {
            //new constituent will be created
            var newConstituent = edge.CompleteBy(constituent);
            var endContext     = newConstituent.EndContext;

            if (endContext.Connect(newConstituent))
            {
                //constituent doesn't exists in the graph yet
                _agenda.Enqueue(newConstituent);
            }

            if (newConstituent.IsFinal && newConstituent.EndContext.EOF && newConstituent.StartContext.BOF)
            {
                _result = newConstituent;
                //prevent further processing
                _agenda.Clear();
            }
        }
Exemple #6
0
 /// <summary>
 /// Creates self edge
 /// </summary>
 /// <param name="label"></param>
 /// <param name="extendedEdge"></param>
 internal ActiveEdge(ActiveLabel label, ActiveEdge extendedEdge)
     : base(extendedEdge.EndContext, extendedEdge.EndContext)
 {
     Label = label;
     //       ExtendedEdge = extendedEdge;
 }