Ejemplo n.º 1
0
 public bool IsCompatible(MeCabDictionary d)
 {
     return(this.Version == d.Version &&
            this.LSize == d.LSize &&
            this.RSize == d.RSize &&
            this.CharSet == d.CharSet);
 }
Ejemplo n.º 2
0
 private void ReadNodeInfo(MeCabDictionary dic, Token token, MeCabNode node)
 {
     node.LCAttr = token.LcAttr;
     node.RCAttr = token.RcAttr;
     node.PosId  = token.PosId;
     node.WCost  = token.WCost;
     //node.Token = token;
     //node.Feature = dic.GetFeature(token); //この段階では素性情報を取得しない
     node.SetFeature(token.Feature, dic); //そのかわり遅延取得を可能にする
 }
Ejemplo n.º 3
0
        public void Open(MeCabParam param)
        {
            this.dic = new MeCabDictionary[param.UserDic.Length + 1];

            string prefix = param.DicDir;

            this.property.Open(prefix);

            this.unkDic.Open(Path.Combine(prefix, UnkDicFile));
            if (this.unkDic.Type != DictionaryType.Unk)
            {
                throw new MeCabInvalidFileException("not a unk dictionary", this.unkDic.FileName);
            }

            MeCabDictionary sysDic = new MeCabDictionary();

            sysDic.Open(Path.Combine(prefix, SysDicFile));
            if (sysDic.Type != DictionaryType.Sys)
            {
                throw new MeCabInvalidFileException("not a system dictionary", sysDic.FileName);
            }
            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, this.unkDic.FileName);
                }
                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;
            }
        }