Exemple #1
0
        public void Optimize(ISymbol searchSymbol, int index)
        {
            var earleySet = _chart.EarleySets[index];

            var transitiveState = earleySet.FindTransitionState(searchSymbol);
            if (transitiveState != null)
            {
                Transition = transitiveState;
                return;
            }

            var sourceState = earleySet.FindSourceState(searchSymbol);
            if (sourceState == null)
                return;

            var sourceStateNext = sourceState.NextState();
            if (!sourceStateNext.IsComplete)
                return;

            Transition = sourceStateNext;

            Optimize(
                sourceState.Production.LeftHandSide,
                sourceState.Origin);

            if (Transition == null)
                return;

            // TODO:
            // 1. create the parse node from the source state
            // 2. take the transition item's parse node and add it as the child
            //      to the source state's parse node
            var transitionItem = new TransitionState(
                searchSymbol,
                Transition,
                sourceState,
                index);

            if (_chart.Enqueue(index, transitionItem))
                Log("Transition", index, transitionItem);
        }
Exemple #2
0
        private void OptimizeReductionPathRecursive(
            ISymbol searchSymbol,
            int k,
            ref IState t_rule,
            ref ITransitionState previousTransitionState)
        {
            var earleySet = _chart.EarleySets[k];

            // if Ii contains a transitive item of the for [B -> b., A, k]
            var transitionState = earleySet.FindTransitionState(searchSymbol);
            if (transitionState != null)
            {
                // then t_rule := B-> b.; t_pos = k;
                previousTransitionState = transitionState;
                t_rule = transitionState;
                return;
            }

            // else if Ii contains exactly one item of the form [B -> a.Ab, k]
            var sourceState = earleySet.FindSourceState(searchSymbol);
            if (sourceState == null)
                return;

            // and [B-> aA.b, k] is quasi complete (is b null)
            if (!IsNextStateQuasiComplete(sourceState))
                return;

            // then t_rule := [B->aAb.]; t_pos=k;
            t_rule = sourceState.NextState();

            // T_Update(I0...Ik, B);
            OptimizeReductionPathRecursive(
                sourceState.Production.LeftHandSide,
                sourceState.Origin,
                ref t_rule,
                ref previousTransitionState);

            if (t_rule == null)
                return;

            ITransitionState currentTransitionState = null;
            if (previousTransitionState != null)
            {
                currentTransitionState = new TransitionState(
                  searchSymbol,
                  t_rule,
                  sourceState,
                  previousTransitionState.Index);

                previousTransitionState.NextTransition = currentTransitionState;
            }
            else
                currentTransitionState = new TransitionState(
                  searchSymbol,
                  t_rule,
                  sourceState,
                  k);

            if (_chart.Enqueue(k, currentTransitionState))
                Log("Transition", k, currentTransitionState);

            previousTransitionState = currentTransitionState;
        }
Exemple #3
0
        private void OptimizeReductionPathRecursive(
            ISymbol searchSymbol,
            int k,
            ref IState t_rule,
            ref ITransitionState previousTransitionState)
        {
            var earleySet = _chart.EarleySets[k];
            var transitionState = earleySet.FindTransitionState(searchSymbol);
            if (transitionState != null)
            {
                previousTransitionState = transitionState;
                t_rule = transitionState;
                return;
            }
            var sourceState = earleySet.FindSourceState(searchSymbol);
            if (sourceState == null)
                return;

            if (!IsNextStateQuasiComplete(sourceState))
                return;

            t_rule = sourceState.NextState();

            OptimizeReductionPathRecursive(
                sourceState.Production.LeftHandSide,
                sourceState.Origin,
                ref t_rule,
                ref previousTransitionState);

            if (t_rule == null)
                return;

            ITransitionState currentTransitionState = null;
            if (previousTransitionState != null)
            {
                currentTransitionState = new TransitionState(
                  searchSymbol,
                  t_rule,
                  sourceState,
                  previousTransitionState.Position);

                previousTransitionState.NextTransition = currentTransitionState;
            }
            else
                currentTransitionState = new TransitionState(
                  searchSymbol,
                  t_rule,
                  sourceState,
                  k);

            if (_chart.Enqueue(k, currentTransitionState))
                Log("Transition", k, currentTransitionState);

            previousTransitionState = currentTransitionState;
        }