public override EntityRegexMatchState Interpret(EntityRegexMatchInfo info, EntityRegexMatchState state)
        {
            if (state == null || state.Count == 0)
            {
                return(null);
            }

            EntityRegexMatchState result = state.Clone();

            EntityRegexMatchState temp = new EntityRegexMatchState();

            foreach (StateItem item in state)
            {
                if (Validator.Interpret(info.GetNextEntity(item)))
                {
                    item.AddPassed(info.CurrentPatternIndex);
                    temp.Add(item);
                }
            }

            temp = this.Interpret(info, temp);
            if (temp != null)
            {
                result.AddRange(temp);
            }

            return(result);
        }
        public EntityRegexMatchState Clone()
        {
            EntityRegexMatchState result = new EntityRegexMatchState(this.Count);

            foreach (StateItem item in this)
            {
                result.Add(new StateItem(item));
            }

            return(result);
        }
        public EntityRegexMatchState Clone(int lastIndex)
        {
            EntityRegexMatchState result = new EntityRegexMatchState(this.Count);

            foreach (StateItem item in this)
            {
                if (item.LastPatternIndex == lastIndex)
                {
                    result.Add(new StateItem(item));
                }
            }

            return(result);
        }
Ejemplo n.º 4
0
        public override EntityRegexMatchState Interpret(EntityRegexMatchInfo info, EntityRegexMatchState state)
        {
            if (state == null || state.Count == 0)
            {
                return(null);
            }

            EntityRegexMatchState result = new EntityRegexMatchState();

            //foreach stateItem in original state
            foreach (StateItem stateItem in state)
            {
                if (info.StartIndex + stateItem.NextEntityIndex < info.Entities.Length)
                {
                    //evaluate regex
                    IEntity             entity           = info.Entities[info.StartIndex + stateItem.NextEntityIndex];
                    ChangeableEntity    changeableEntity = entity as ChangeableEntity;
                    WordHolder.WordItem item             = null;
                    if (changeableEntity != null)
                    {
                        foreach (IEntity allowedEntity in changeableEntity.AllowedEntities)
                        {
                            item = Holder.Find(allowedEntity.Value.ToUpper());
                            if (item != null)
                            {
                                break;
                            }
                        }
                    }
                    else
                    {
                        item = Holder.Find(entity.Value.ToUpper());
                    }

                    if (item != null)
                    {
                        stateItem.AddPassed(info.CurrentPatternIndex, item.Value);
                        result.Add(stateItem);
                    }
                }
            }
            return(result);
        }
        public override EntityRegexMatchState Interpret(EntityRegexMatchInfo info, EntityRegexMatchState state)
        {
            if (state == null || state.Count == 0)
            {
                return(null);
            }

            EntityRegexMatchState result = state.Clone();

            foreach (StateItem item in state)
            {
                if (info.NextEntityExists(item) && Validator.Interpret(info.GetNextEntity(item)))
                {
                    item.AddPassed(info.CurrentPatternIndex);
                    result.Add(item);
                }
            }

            return(result);
        }
Ejemplo n.º 6
0
        public override EntityRegexMatchState Interpret(EntityRegexMatchInfo info, EntityRegexMatchState state)
        {
            if (state == null || state.Count == 0)
            {
                return(null);
            }

            EntityRegexMatchState result = new EntityRegexMatchState();

            foreach (StateItem item in state)
            {
                if (info.StartIndex + item.NextEntityIndex < info.Entities.Length && Validator.Interpret(info.GetNextEntity(item)))
                {
                    item.AddPassed(info.CurrentPatternIndex);
                    result.Add(item);
                }
            }

            return(result);
        }
Ejemplo n.º 7
0
        public EntityRegexMatchInfo Interpret(IEntity[] entities, int startIndex)
        {
            EntityRegexMatchInfo  info  = new EntityRegexMatchInfo(startIndex, this, entities);
            EntityRegexMatchState state = new EntityRegexMatchState();

            state.Add(new StateItem());

            for (int i = 0; i < AllRegex.Length; i++)
            {
                info.CurrentPatternIndex = i;
                state = AllRegex[i].Interpret(info, state);
            }

            info.States = state;
#if DEBUG
            if (state != null && state.Count > 1)
            {
                throw new Exception("Multi state situation arise!");
            }
#endif

            return(info);
        }
        public override EntityRegexMatchState Interpret(EntityRegexMatchInfo info, EntityRegexMatchState state)
        {
            if (state == null || state.Count == 0)
            {
                return(null);
            }

            EntityRegexMatchState result = new EntityRegexMatchState();

            //foeach Regex (ClauseHolder item) in ClauseHolder
            foreach (ClauseHolder.ClauseItem clauseHolderItem in Holder.Items)
            {
                //foreach stateItem in original state
                foreach (StateItem stateItem in state)
                {
                    if (info.StartIndex + stateItem.NextEntityIndex < info.Entities.Length)
                    {
                        //evaluate regex
                        EntityRegexMatchInfo temp = clauseHolderItem.Regex.Interpret(info.Entities, info.StartIndex + stateItem.NextEntityIndex);
                        if (temp.States != null)
                        {
                            //foreach stateItem in evaluated result
                            foreach (StateItem subStateItem in temp.States)
                            {
                                //new state item
                                StateItem tempStateItem = new StateItem(stateItem);
                                //item passed for current pattern index, subStateItem only clauseHolderItem.Index indexes.
                                tempStateItem.AddPassed(info.CurrentPatternIndex, subStateItem, clauseHolderItem.Index, clauseHolderItem.Value);
                                result.Add(tempStateItem);
                            }
                        }
                    }
                }
            }
            return(result);
        }