0

現在、Unity を使用して Android アプリを開発しています。NetSpell はデスクトップでは問題なく動作しますが、辞書のテキスト ファイルにアクセスできないため、タブレットでは動作しません。Unity で TextAsset を使用してファイルをロードできることはわかっていますが、NetSpell で確認できる唯一の方法は、フォルダーとファイル パスによるロードです。辞書データを読み込んで文字列として NetSpell に渡すにはどうすればよいですか? これを行う方法はありますか?

編集:コードを追加する...辞書ファイルを文字列として受け入れることができるように、次をどのように変更すればよいですか?

// open dictionary file
        FileStream fs = new FileStream(dictionaryPath, FileMode.Open, FileAccess.Read, FileShare.Read);
        StreamReader sr = new StreamReader(fs, Encoding.UTF8);

        // read line by line
        while (sr.Peek() >= 0) 
        {
            string tempLine = sr.ReadLine().Trim();
            if (tempLine.Length > 0)
            {
                // check for section flag
                switch (tempLine)
                {
                    case "[Copyright]" :
                    case "[Try]" : 
                    case "[Replace]" : 
                    case "[Prefix]" :
                    case "[Suffix]" :
                    case "[Phonetic]" :
                    case "[Words]" :
                        // set current section that is being parsed
                        currentSection = tempLine;
                        break;
                    default :       
                        // parse line and place in correct object
                    switch (currentSection)
                    {
                        case "[Copyright]" :
                            this.Copyright += tempLine + "\r\n";
                            break;
                        case "[Try]" : // ISpell try chars
                            this.TryCharacters += tempLine;
                            break;
                        case "[Replace]" : // ISpell replace chars
                            this.ReplaceCharacters.Add(tempLine);
                            break;
                        case "[Prefix]" : // MySpell prefix rules
                        case "[Suffix]" : // MySpell suffix rules

                            // split line by white space
                            partMatches = _spaceRegx.Matches(tempLine);

                            // if 3 parts, then new rule  
                            if (partMatches.Count == 3)
                            {
                                currentRule = new AffixRule();

                                // part 1 = affix key
                                currentRule.Name = partMatches[0].Value;
                                // part 2 = combine flag
                                if (partMatches[1].Value == "Y") currentRule.AllowCombine = true;
                                // part 3 = entry count, not used

                                if (currentSection == "[Prefix]")
                                {
                                    // add to prefix collection
                                    this.PrefixRules.Add(currentRule.Name, currentRule);
                                }
                                else 
                                {
                                    // add to suffix collection
                                    this.SuffixRules.Add(currentRule.Name, currentRule);
                                }
                            }
                                //if 4 parts, then entry for current rule
                            else if (partMatches.Count == 4)
                            {
                                // part 1 = affix key
                                if (currentRule.Name == partMatches[0].Value)
                                {
                                    AffixEntry entry = new AffixEntry();

                                    // part 2 = strip char
                                    if (partMatches[1].Value != "0") entry.StripCharacters = partMatches[1].Value;
                                    // part 3 = add chars
                                    entry.AddCharacters = partMatches[2].Value;
                                    // part 4 = conditions
                                    AffixUtility.EncodeConditions(partMatches[3].Value, entry);

                                    currentRule.AffixEntries.Add(entry);
                                }
                            }   
                            break;
                        case "[Phonetic]" : // ASpell phonetic rules
                            // split line by white space
                            partMatches = _spaceRegx.Matches(tempLine);
                            if (partMatches.Count >= 2)
                            {
                                PhoneticRule rule = new PhoneticRule();
                                PhoneticUtility.EncodeRule(partMatches[0].Value, ref rule);
                                rule.ReplaceString = partMatches[1].Value;
                                _phoneticRules.Add(rule);
                            }
                            break;
                        case "[Words]" : // dictionary word list
                            // splits word into its parts
                            string[] parts = tempLine.Split('/');
                            Word tempWord = new Word();
                            // part 1 = base word
                            tempWord.Text = parts[0];
                            // part 2 = affix keys
                            if (parts.Length >= 2) tempWord.AffixKeys = parts[1];
                            // part 3 = phonetic code
                            if (parts.Length >= 3) tempWord.PhoneticCode = parts[2];

                            this.BaseWords.Add(tempWord.Text, tempWord);
                            break;
                    } // currentSection swith
                        break;
                } //tempLine switch
            } // if templine
        } // read line
        // close files
        sr.Close();
        fs.Close();
4

0 に答える 0