Beispiel #1
0
 public bool IsCompatible(MeCabDictionary d)
 {
     return(this.Version == d.Version &&
            this.LSize == d.LSize &&
            this.RSize == d.RSize &&
            this.CharSet == d.CharSet);
 }
Beispiel #2
0
 public bool IsCompatible(MeCabDictionary d)
 {
     return(this.Version == d.Version &&
            this.LSize == d.LSize &&
            this.RSize == d.RSize &&
            this.Encoding.CodePage == d.Encoding.CodePage);
 }
Beispiel #3
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.SetFeature(token.Feature, dic);
		}
Beispiel #4
0
        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;
            }
        }
Beispiel #5
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); //そのかわり遅延取得を可能にする
 }
Beispiel #6
0
		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;
			}
		}
Beispiel #7
0
 private void ReadNodeInfo(MeCabDictionary dic, in Token token, TNode node)