Пример #1
0
 public List <string> Suggest(string word)
 {
     lock (lockObj)
     {
         requireValidHandle();
         List <string> suggestions = new List <string>();
         if (!isValidInput(word))
         {
             return(suggestions);
         }
         IntPtr voikkoSuggestCstr = Libvoikko.voikkoSuggestCstr(handle, ByteArray.s2n(word));
         if (voikkoSuggestCstr == IntPtr.Zero)
         {
             return(suggestions);
         }
         unsafe
         {
             for (byte **cStr = (byte **)voikkoSuggestCstr; *cStr != (byte *)0; cStr++)
             {
                 suggestions.Add(ByteArray.n2s(new IntPtr(*cStr)));
             }
         }
         Libvoikko.voikkoFreeCstrArray(voikkoSuggestCstr);
         return(suggestions);
     }
 }
Пример #2
0
        public Voikko(String language, String path)
        {
            IntPtr error = new IntPtr();

            handle = Libvoikko.voikkoInit(ref error, ByteArray.s2n(language), ByteArray.s2ansi(path));
            if (handle == IntPtr.Zero && error != IntPtr.Zero)
            {
                throw new VoikkoException(ByteArray.n2s(error));
            }
        }
Пример #3
0
 public string GetHyphenationPattern(string word)
 {
     lock (lockObj)
     {
         requireValidHandle();
         if (!isValidInput(word))
         {
             // return string of spaces
             return(new string(' ', word.Length));
         }
         IntPtr cPattern = Libvoikko.voikkoHyphenateCstr(handle, ByteArray.s2n(word));
         string pattern  = ByteArray.n2s(cPattern);
         Libvoikko.voikkoFreeCstr(cPattern);
         return(pattern);
     }
 }
Пример #4
0
        public static List <VoikkoDictionary> listDicts(string path)
        {
            List <VoikkoDictionary> dicts = new List <VoikkoDictionary>();
            IntPtr cDicts = Libvoikko.voikko_list_dicts(ByteArray.s2ansi(path));

            unsafe
            {
                for (void **cDict = (void **)cDicts; *cDict != (void *)0; cDict++)
                {
                    dicts.Add(new VoikkoDictionary(ByteArray.n2s(Libvoikko.voikko_dict_language(new IntPtr(*cDict))),
                                                   ByteArray.n2s(Libvoikko.voikko_dict_variant(new IntPtr(*cDict))),
                                                   ByteArray.n2s(Libvoikko.voikko_dict_description(new IntPtr(*cDict)))));
                }
            }
            Libvoikko.voikko_free_dicts(cDicts);
            return(dicts);
        }
Пример #5
0
        public List <Analysis> Analyze(string word)
        {
            lock (lockObj)
            {
                requireValidHandle();
                List <Analysis> analysisList = new List <Analysis>();
                if (!isValidInput(word))
                {
                    return(analysisList);
                }

                IntPtr cAnalysisList = Libvoikko.voikkoAnalyzeWordCstr(handle, ByteArray.s2n(word));

                if (cAnalysisList == IntPtr.Zero)
                {
                    return(analysisList);
                }

                unsafe
                {
                    for (void **cAnalysis = (void **)cAnalysisList; *cAnalysis != (void *)0; cAnalysis++)
                    {
                        IntPtr   cKeys    = Libvoikko.voikko_mor_analysis_keys(new IntPtr(*cAnalysis));
                        Analysis analysis = new Analysis();
                        for (byte **cKey = (byte **)cKeys; *cKey != (byte *)0; cKey++)
                        {
                            string key = ByteArray.n2s(new IntPtr(*cKey));
                            IntPtr val = Libvoikko.voikko_mor_analysis_value_cstr(new IntPtr(*cAnalysis), ByteArray.s2n(key));
                            analysis[key] = ByteArray.n2s(val);
                            Libvoikko.voikko_free_mor_analysis_value_cstr(val);
                        }
                        analysisList.Add(analysis);
                    }
                }
                Libvoikko.voikko_free_mor_analysis(cAnalysisList);

                return(analysisList);
            }
        }
Пример #6
0
        private GrammarError getGrammarError(IntPtr cError, int offset, string language)
        {
            int           errorCode    = Libvoikko.voikkoGetGrammarErrorCode(cError);
            IntPtr        startPos     = Libvoikko.voikkoGetGrammarErrorStartPos(cError);
            IntPtr        errorLength  = Libvoikko.voikkoGetGrammarErrorLength(cError);
            IntPtr        cSuggestions = Libvoikko.voikkoGetGrammarErrorSuggestions(cError);
            List <string> suggestions  = new List <string>();

            if (cSuggestions != IntPtr.Zero)
            {
                unsafe
                {
                    for (byte **cStr = (byte **)cSuggestions; *cStr != (byte *)0; cStr++)
                    {
                        suggestions.Add(ByteArray.n2s(new IntPtr(*cStr)));
                    }
                }
            }
            IntPtr cShortDescription = Libvoikko.voikkoGetGrammarErrorShortDescription(cError, ByteArray.s2n(language));
            string shortDescription  = ByteArray.n2s(cShortDescription);

            Libvoikko.voikkoFreeErrorMessageCstr(cShortDescription);
            return(new GrammarError(errorCode, offset + (int)startPos, (int)errorLength, suggestions, shortDescription));
        }