예제 #1
0
        public override HiddenModel createModel(IEnumerable <BaseTrajectory> traces, StrokeMap strokeMap)
        {
            var strokes      = traces.ToArray();
            var symbolTraces = strokes.Select(s => strokeMap.getSymbolTrace(s)).ToArray();

            var transitionDatas = strokeMap.Areas.Select((a, i) => transitionSetup.createTransitionDataToArea(i, "S" + strokeMap.ID + "_A" + (i + 1))).ToArray();

            foreach (var symTrace in symbolTraces)
            {
                var prevT = symTrace[0].Time;
                for (int i = 1; i < symTrace.Length; i++)
                {
                    var dT = (int)(symTrace[i].Time - prevT);
                    prevT = symTrace[i].Time;
                    transitionDatas[i - 1].addData(dT);
                }
            }

            var   startState = new StartState();
            State curState   = startState;
            State nextState;

            foreach (var transData in transitionDatas)
            {
                nextState = new State();
                var transition = transData.createTransition(nextState);
                curState.addTransition(transition);
                curState = nextState;
            }

            var model = new HiddenModel(startState, curState);

            return(model);
        }
        public override CHnMModel createModel(IEnumerable <BaseTrajectory> traces, StrokeMap strokeMap)
        {
            var strokes      = traces.ToArray();
            var symbolTraces = strokes.Select(s => strokeMap.getSymbolTrace(s)).ToArray();

            var transitionDatas = strokeMap.Areas.Select((a, i) => transitionSetup.createTransitionDataToArea(i, "S" + strokeMap.ID + "_A" + (i + 1))).ToArray();

            foreach (var symTrace in symbolTraces)
            {
                if (symTrace != null)
                {
                    var has_empty = symTrace.Where(w => w == null).ToArray();
                    if (has_empty.Length == 0)
                    {
                        var symTrace_clean = symTrace.Where(w => w.Symbol != "GestureStart").ToArray();
                        var prevT          = symTrace[0].Time;
                        for (int i = 0; i < symTrace_clean.Length; i++)
                        {
                            var dT = (int)(symTrace_clean[i].Time - prevT);
                            prevT = symTrace_clean[i].Time;
                            transitionDatas[i].addData(dT);;
                        }
                    }
                    else
                    {
                        //handle the empty datas here
                    }
                }
            }

            var   startState = new StartState();
            State curState   = startState;
            State nextState;

            int ai = 0;

            foreach (var transData in transitionDatas)
            {
                nextState = new State();
                var transition = transData.createTransition(nextState, strokeMap.Areas[ai++]);
                curState.addTransition(transition);
                curState = nextState;
            }

            var model = new CHnMModel(startState, curState);

            return(model);
        }
        public override CHnMModel createModel(IEnumerable <BaseTrajectory> traces, StrokeMap strokeMap)
        {
            var strokes      = traces.ToArray();
            var symbolTraces = strokes.Select(s => strokeMap.getSymbolTrace(s)).ToArray();

            var transitionDatas = strokeMap.Areas.Select((a, i) => transitionSetup.createTransitionDataToArea("S" + strokeMap.ID + "_A" + (i + 1))).ToArray();

            ////number of areas -> transitiondata to endState
            //var endTransitions = new Dictionary<int,TransitionData>(15);

            var endTransitionData = transitionSetup.createTransitionDataToEnd();


            foreach (var symTrace in symbolTraces)
            {
                var prevT = symTrace[0].Time;             //GestureStart is dummy symbol marking the beginning
                for (int i = 1; i < symTrace.Length; i++) //go through all symbols of a trace (except GestureEnd)
                {
                    var dT = (int)(symTrace[i].Time - prevT);
                    prevT = symTrace[i].Time;

                    if (i == symTrace.Length - 1)
                    {
                        endTransitionData.addData(dT);
                        //TransitionData endTransition;
                        //if(endTransitions.TryGetValue(i, out endTransition))
                        //{
                        //    endTransition.addData(dT);
                        //}
                        //else
                        //{
                        //    Debug.Assert(symTrace[i].Symbol == "GestureEnd");
                        //    endTransition = transitionSetup.createTransitionDataToEnd(); //use endtransition
                        //    endTransition.addData(dT);
                        //    endTransitions[i] = endTransition;
                        //}
                    }
                    else
                    {
                        transitionDatas[i - 1].addData(dT);
                    }
                }
            }

            //var endTransPositions = endTransitions.Select(e => e.Key).OrderBy(x => x).ToArray();
            //Debug.Assert(endTransPositions.Last() - endTransPositions.First() == endTransitions.Count-1);

            var   startState = new StartState();
            var   areaStates = new State[strokeMap.Areas.Length];
            var   endState   = new State();
            State curState   = startState;
            State nextState;

            int curAreaState = 0;

            foreach (var transData in transitionDatas)
            {
                nextState = new State();
                areaStates[curAreaState++] = nextState;
                var transition = transData.createTransition(nextState, null);
                curState.addTransition(transition);
                curState = nextState;
            }

            curState.addTransition(endTransitionData.createTransition(endState, null));

            //add end transitions
            //foreach(var end in endTransitions)
            //{
            //    var prevAreaState = areaStates[end.Key - 2];
            //    prevAreaState.addTransition(end.Value.createTransition(endState));
            //}

            var model = new CHnMModel(startState, endState);

            return(model);
        }