Пример #1
0
        /// <summary>
        /// Create new automaton
        /// </summary>
        /// <param name="current"></param>
        /// <param name="c"></param>
        /// <param name="next"></param>
        /// <param name="customAdd"></param>
        internal bool CreateAutomaton(InputAutomaton current, string c, InputAutomaton next, BitFlag customAdd)
        {
            // Previous automaton
            InputAutomaton prev = current;

            if (!_kanamap.ContainsKey(c))
            {
                // Input is not supported
                return(false);
            }

            var kanamap = _kanamap[c];

            if (VersionHelper.WTVersion == 404)
            {
                // There is a bug in the version 405
                // To be compatible with that, we add ぱ/ぴ/ぺ with Shift Handakuten
                if ((_imAuthor == "Denasu System") &&
                    (_imName == "JISかな") &&
                    (c == "パ" || c == "ピ" || c == "ペ"))
                {
                    kanamap = new List <KeyStroke>();
                    foreach (var j in _kanamap[c])
                    {
                        kanamap.Add(j);

                        if (j.Stroke.Count() == 2 &&
                            ((j.Stroke[0] & (int)WTKeyCode.Shift) != (int)WTKeyCode.Shift) &&
                            (j.Stroke[1] & (int)WTKeyCode.Shift) != (int)WTKeyCode.Shift)
                        {
                            kanamap.Add(new KeyStroke()
                            {
                                Custom = j.Custom,
                                Input  = j.Input,
                                Stroke = new int[2]
                                {
                                    j.Stroke[0] | (int)WTKeyCode.Shift,
                                    j.Stroke[1] | (int)WTKeyCode.Shift,
                                }
                            });
                        }
                    }
                }
            }

            foreach (var j in kanamap)
            {
                if (j.Stroke.Count() == 0)
                {
                    continue;
                }

                current = prev;

                // Create new automaton for each stroke
                for (var k = 0; k < j.Stroke.Count(); k++)
                {
                    if (j.Stroke[k] == (int)WTKeyCode.NoKey)
                    {
                        continue;
                    }

                    if (k + 1 == j.Stroke.Count())
                    {
                        // The last alphabet
                        InputAutomaton.Connect connect = new InputAutomaton.Connect()
                        {
                            Automaton = next,
                            Flags     = j.Custom.Or(customAdd),
                            Character = j.Input,
                        };
                        current.SetConnect(j.Stroke[k], connect);
                        current = next;
                    }
                    else
                    {
                        InputAutomaton.Connect connect = current.GetConnect(j.Stroke[k]);
                        if (connect == null)
                        {
                            // Create a automaton with Flags
                            connect = new InputAutomaton.Connect()
                            {
                                Automaton = new InputAutomaton(),
                                Flags     = j.Custom.Or(customAdd),
                                Character = "",
                            };
                            current.SetConnect(j.Stroke[k], connect);
                            current = connect.Automaton;
                        }
                        else
                        {
                            // To make it deterministic, use existing automaton
                            connect.Flags = connect.Flags.Or(j.Custom);

                            current = connect.Automaton;
                        }
                    }
                }
            }

            return(true);
        }
Пример #2
0
        /// <summary>
        /// Create new automaton
        /// </summary>
        /// <param name="plane">Plane</param>
        /// <param name="current">Current Automaton</param>
        /// <param name="c">char</param>
        /// <param name="next">Next Automaton</param>
        /// <param name="customAdd">Custom to add</param>
        internal void CreateAutomaton(int plane, InputAutomaton current, string c, InputAutomaton next, BitFlag customAdd)
        {
            // Previous automaton
            InputAutomaton prev = current;

            if (!_strokemap[plane].ContainsKey(c))
            {
                // Input is not supported
                return;
            }

            // For all the stroke for c (e.g. "か"->ka, ca)
            foreach (var stroke in _strokemap[plane][c])
            {
                if (stroke.Stroke.Count() == 0)
                {
                    continue;
                }

                current = prev;

                // Create new automaton for each stroke
                for (var alphabet = 0; alphabet < stroke.Stroke.Count(); alphabet++)
                {
                    if (stroke.Stroke[alphabet] == (int)WTKeyCode.NoKey)
                    {
                        // Unknown
                        continue;
                    }

                    if (alphabet + 1 == stroke.Stroke.Count())
                    {
                        // The last alphabet
                        current.SetConnect(stroke.Stroke[alphabet], new InputAutomaton.Connect()
                        {
                            Automaton = next,
                            Flags     = stroke.Custom.Or(customAdd),
                            Character = stroke.Input.Substring(alphabet, 1),
                        });
                        current = next;
                    }
                    else
                    {
                        // Middle alphabet

                        InputAutomaton.Connect connect = current.GetConnect(stroke.Stroke[alphabet]);
                        if (connect == null)
                        {
                            // This automaton doesn't have the connection for this alphabet

                            // Create a new connection for this alphabet
                            connect = new InputAutomaton.Connect()
                            {
                                Automaton = new InputAutomaton(),
                                Flags     = stroke.Custom.Or(customAdd),
                                Character = stroke.Input.Substring(alphabet, 1),
                            };

                            // Connect
                            current.SetConnect(stroke.Stroke[alphabet], connect);
                            current = connect.Automaton;
                        }
                        else
                        {
                            // This automaton already have a connection for this alphabet

                            // To make it deterministic, use existing automaton
                            connect.Flags = connect.Flags.Or(stroke.Custom);

                            current = connect.Automaton;
                        }
                    }
                }
            }
        }