public void Open(MeCabParam param) { this.dic = new MeCabDictionary[param.UserDic.Length + 1]; this.property.Open(); this.unkDic.Open(Properties.Resources.unk); if (this.unkDic.Type != DictionaryType.Unk) { throw new MeCabInvalidFileException("not a unk dictionary", "unk.resource"); } MeCabDictionary sysDic = new MeCabDictionary(); sysDic.Open(Properties.Resources.sys); if (sysDic.Type != DictionaryType.Sys) { throw new MeCabInvalidFileException("not a system dictionary", "sys.resource"); } this.dic[0] = sysDic; /* * for (int i = 0; i < param.UserDic.Length; i++) * { * MeCabDictionary d = new MeCabDictionary(); * d.Open(Path.Combine(prefix, param.UserDic[i])); * if (d.Type != DictionaryType.Usr) * throw new MeCabInvalidFileException("not a user dictionary", d.FileName); * if (!sysDic.IsCompatible(d)) * throw new MeCabInvalidFileException("incompatible dictionary", d.FileName); * this.dic[i + 1] = d; * } */ this.unkTokens = new Token[this.property.Size][]; for (int i = 0; i < this.unkTokens.Length; i++) { string key = this.property.Name(i); DoubleArray.ResultPair n = this.unkDic.ExactMatchSearch(key); if (n.Value == -1) { throw new MeCabInvalidFileException("cannot find UNK category: " + key, "unk.resource"); } this.unkTokens[i] = this.unkDic.GetToken(n); } this.space = this.property.GetCharInfo(' '); this.bosFeature = param.BosFeature; this.unkFeature = param.UnkFeature; this.maxGroupingSize = param.MaxGroupingSize; if (this.maxGroupingSize <= 0) { this.maxGroupingSize = DefaltMaxGroupingSize; } }
public void Open(MeCabParam param) { this.dic = new MeCabDictionary[param.UserDic.Length + 1]; string dicDir = param.DicDir; this.property.Open(dicDir); this.unkDic.Open(Path.Combine(dicDir, "unk.dic")); if (this.unkDic.Type != DictionaryType.Unk) { throw new MeCabInvalidFileException("not a unk dictionary", this.unkDic.FileName); } MeCabDictionary meCabDictionary = new MeCabDictionary(); meCabDictionary.Open(Path.Combine(dicDir, "sys.dic")); if (meCabDictionary.Type != 0) { throw new MeCabInvalidFileException("not a system dictionary", meCabDictionary.FileName); } this.dic[0] = meCabDictionary; for (int i = 0; i < param.UserDic.Length; i++) { MeCabDictionary meCabDictionary2 = new MeCabDictionary(); meCabDictionary2.Open(Path.Combine(dicDir, param.UserDic[i])); if (meCabDictionary2.Type != DictionaryType.Usr) { throw new MeCabInvalidFileException("not a user dictionary", meCabDictionary2.FileName); } if (!meCabDictionary.IsCompatible(meCabDictionary2)) { throw new MeCabInvalidFileException("incompatible dictionary", meCabDictionary2.FileName); } this.dic[i + 1] = meCabDictionary2; } this.unkTokens = new Token[this.property.Size][]; for (int j = 0; j < this.unkTokens.Length; j++) { string text = this.property.Name(j); DoubleArray.ResultPair n = this.unkDic.ExactMatchSearch(text); if (n.Value == -1) { throw new MeCabInvalidFileException("cannot find UNK category: " + text, this.unkDic.FileName); } this.unkTokens[j] = this.unkDic.GetToken(n); } this.space = this.property.GetCharInfo(' '); this.bosFeature = param.BosFeature; this.unkFeature = param.UnkFeature; this.maxGroupingSize = param.MaxGroupingSize; if (this.maxGroupingSize <= 0) { this.maxGroupingSize = 24; } }