Пример #1
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);
            }
        }
Пример #2
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));
        }