Пример #1
0
 /// <summary>
 /// 获取父义原
 /// </summary>
 /// <param name="sem"></param>
 /// <returns></returns>
 public Semanteme GetParentSemantem(Semanteme sem)
 {
     if (this.IndexSemantmes != null)
     {
         return this.IndexSemantmes[sem.ParentID] as Semanteme;
     }
     else
     {
         return null;
     }
 }
Пример #2
0
        /// <summary>
        /// 加载HowNet义原树
        /// </summary>
        /// <returns></returns>
        private bool ConstructSemantems()
        {
            if (!File.Exists(_SemantemeFileName))
            {
                return false;
            }

            this.Semantems = new System.Collections.Hashtable();
            this.IndexSemantmes = new System.Collections.Hashtable();

            StreamReader sr = new StreamReader(_SemantemeFileName, Encoding.GetEncoding("gb2312"), true);
            string str = "";
            while ((str = sr.ReadLine()) != null)
            {
                char[] separator = { ' ' };
                string[] words = str.Split(separator, StringSplitOptions.RemoveEmptyEntries);
                if (words.Length >= 3)
                {
                    Semanteme item = new Semanteme(int.Parse(words[0]), words[1].Trim(), int.Parse(words[2]));
                    if (this.Semantems.ContainsKey(item.Sema))
                    {
                        this.Semantems[item.Sema] = item;
                    }
                    else
                    {
                        this.Semantems.Add(item.Sema, item);
                    }
                    this.IndexSemantmes.Add(item.ID, item);
                }
                else
                {
                    continue;
                }
            }
            return true;
        }