Esempio n. 1
0
 private void Options_Load(object sender, EventArgs e)
 {
     flags = WritePadAPI.HWR_GetRecognitionFlags(WritePadAPI.getRecoHandle());
     SeparateLetters.Checked     = WritePadAPI.isRecoFlagSet(flags, WritePadAPI.FLAG_SEPLET);
     DisableSegmentation.Checked = WritePadAPI.isRecoFlagSet(flags, WritePadAPI.FLAG_SINGLEWORDONLY);
     AutoLearner.Checked         = WritePadAPI.isRecoFlagSet(flags, WritePadAPI.FLAG_ANALYZER);
     AutoCorrector.Checked       = WritePadAPI.isRecoFlagSet(flags, WritePadAPI.FLAG_CORRECTOR);
     UserDictionary.Checked      = WritePadAPI.isRecoFlagSet(flags, WritePadAPI.FLAG_USERDICT);
     DictionaryOnly.Checked      = WritePadAPI.isRecoFlagSet(flags, WritePadAPI.FLAG_ONLYDICT);
 }
Esempio n. 2
0
        private void Options_OnLoaded(object sender, RoutedEventArgs e)
        {
            recoFlags = WritePadAPI.HWR_GetRecognitionFlags(WritePadAPI.getRecoHandle());

            separate_letters.IsChecked = WritePadAPI.isRecoFlagSet(recoFlags, WritePadAPI.FLAG_SEPLET);
            single_word.IsChecked      = WritePadAPI.isRecoFlagSet(recoFlags, WritePadAPI.FLAG_SINGLEWORDONLY);
            autocorrector.IsChecked    = WritePadAPI.isRecoFlagSet(recoFlags, WritePadAPI.FLAG_CORRECTOR);
            autolearner.IsChecked      = WritePadAPI.isRecoFlagSet(recoFlags, WritePadAPI.FLAG_ANALYZER);
            user_dictionary.IsChecked  = WritePadAPI.isRecoFlagSet(recoFlags, WritePadAPI.FLAG_USERDICT);
            dict_words.IsChecked       = WritePadAPI.isRecoFlagSet(recoFlags, WritePadAPI.FLAG_ONLYDICT);

            var langId = WritePadAPI.getLanguage();

            UpdateSelectedLanguage(langId);
        }
Esempio n. 3
0
        private async void OnDictionaryChanged()
        {
            StorageFolder userpath = null;

            WritePadAPI.resetRecognizer();
            try
            {
                userpath = await ApplicationData.Current.LocalFolder.CreateFolderAsync("Dictionaries");
            }
            catch (Exception)
            {
            }
            if (userpath == null)
            {
                userpath = await ApplicationData.Current.LocalFolder.GetFolderAsync("Dictionaries");
            }
            var flags = WritePadAPI.HWR_GetRecognitionFlags(WritePadAPI.getRecoHandle());

            WritePadAPI.initRecognizerForLanguage((int)WritePadAPI.language, userpath.Path, Package.Current.InstalledLocation.Path, flags);
        }
Esempio n. 4
0
        private void LanguagesCombo_SelectedIndexChanged(object sender, EventArgs e)
        {
            var selIndex = (sender as ComboBox).SelectedIndex;
            var language = WritePadAPI.LanguageType.en;

            switch (selIndex)
            {
            case 0:
                language = WritePadAPI.LanguageType.en;
                break;

            case 1:
                language = WritePadAPI.LanguageType.en_uk;
                break;

            case 2:
                language = WritePadAPI.LanguageType.de;
                break;

            case 3:
                language = WritePadAPI.LanguageType.fr;
                break;

            case 4:
                language = WritePadAPI.LanguageType.es;
                break;

            case 5:
                language = WritePadAPI.LanguageType.pt_PT;
                break;

            case 6:
                language = WritePadAPI.LanguageType.pt_BR;
                break;

            case 7:
                language = WritePadAPI.LanguageType.nl;
                break;

            case 8:
                language = WritePadAPI.LanguageType.it;
                break;

            case 9:
                language = WritePadAPI.LanguageType.fi;
                break;

            case 10:
                language = WritePadAPI.LanguageType.sv;
                break;

            case 11:
                language = WritePadAPI.LanguageType.nb;
                break;

            case 12:
                language = WritePadAPI.LanguageType.da;
                break;

            case 13:
                language = WritePadAPI.LanguageType.id;
                break;
            }
            var flags = WritePadAPI.HWR_GetRecognitionFlags(WritePadAPI.getRecoHandle());

            ClearInk();
            WritePadAPI.releaseRecognizer();
            WritePadAPI.language = language;
            DictionaryChanged();
            WritePadAPI.HWR_SetRecognitionFlags(WritePadAPI.getRecoHandle(), flags);
        }
Esempio n. 5
0
        /// <summary>n
        /// Recognizes a collection of Polyline objects into text. Words are recognized with alternatives, eash weighted with probability.
        /// </summary>
        /// <param name="strokes">Strokes to recognize</param>
        /// <returns></returns>
        public string RecognizeStrokes(List <List <Point> > strokes, bool bLearn)
        {
            WritePadAPI.HWR_Reset(WritePadAPI.getRecoHandle());

            if (InkData != IntPtr.Zero)
            {
                WritePadAPI.INK_Erase(InkData);
                InkData = IntPtr.Zero;
            }
            InkData = WritePadAPI.INK_InitData();

            foreach (var polyline in strokes)
            {
                WritePadAPI.AddStroke(InkData, polyline);
            }

            var res = "";
            var resultStringList = new List <string>();
            var wordList         = new List <List <WordAlternative> >();
            var defaultResultPtr = WritePadAPI.recognizeInkData(InkData, 0);
            var defaultResult    = Marshal.PtrToStringUni(defaultResultPtr);

            resultStringList.Add(defaultResult);
            var wordCount = WritePadAPI.HWR_GetResultWordCount(WritePadAPI.getRecoHandle());

            for (var i = 0; i < wordCount; i++)
            {
                var wordAlternativesList = new List <WordAlternative>();
                var altCount             = WritePadAPI.HWR_GetResultAlternativeCount(WritePadAPI.getRecoHandle(), i);
                for (var j = 0; j < altCount; j++)
                {
                    var wordPtr = WritePadAPI.getResultWord(i, j);
                    var word    = Marshal.PtrToStringUni(wordPtr);
                    if (word == "<--->")
                    {
                        word = "*Error*";
                    }
                    if (string.IsNullOrEmpty(word))
                    {
                        continue;
                    }
                    uint flags  = WritePadAPI.HWR_GetRecognitionFlags(WritePadAPI.getRecoHandle());
                    var  weight = WritePadAPI.HWR_GetResultWeight(WritePadAPI.getRecoHandle(), i, j);
                    if (weight == 0)
                    {
                        continue;
                    }
                    if (j == 0 && bLearn && weight > 75 && 0 != (flags & WritePadAPI.FLAG_ANALYZER))
                    {
                        // if learner is enabled, learn default word(s) when the Return gesture is used
                        WritePadAPI.recoLearnWord(word, weight);
                    }
                    if (wordAlternativesList.All(x => x.Word != word))
                    {
                        wordAlternativesList.Add(new WordAlternative
                        {
                            Word   = word,
                            Weight = weight
                        }
                                                 );
                    }
                    while (resultStringList.Count < j + 2)
                    {
                        var emptyStr = "";
                        for (int k = 0; k < i; k++)
                        {
                            emptyStr += "\t";
                        }
                        resultStringList.Add(emptyStr);
                    }
                    if (resultStringList[j + 1].Length > 0)
                    {
                        resultStringList[j + 1] += "\t\t";
                    }
                    resultStringList[j + 1] += word + "\t[" + weight + "%]";
                }
                wordList.Add(wordAlternativesList);
            }

            foreach (var line in resultStringList)
            {
                if (string.IsNullOrEmpty(line))
                {
                    continue;
                }
                if (res.Length > 0)
                {
                    res += Environment.NewLine;
                }
                res += line;
            }

            return(res);
        }