Пример #1
0
        private void textBox_NewConcept_TextChanged(object sender, TextChangedEventArgs e)
        {
            Word_ID w_i = new Word_ID();

            w_i.word = textBox_NewConcept.Text;
            w_i.id   = GetTextBoxId(textBox_NewID);
            if (w_i.id == -1)
            {
                return;
            }

            Word_ID exist1 = _baseConcepts.Find(wi => wi.WeakSame(w_i));
            Word_ID exist2 = _nonBaseConcepts.Find(wi => wi.WeakSame(w_i));

            if (exist1 != null || exist2 != null)
            {
                string          message  = "Exist";
                Connection_Info con_info = SearchConnectionInfo(w_i);
                if (con_info != null)//输入连接信息
                {
                    message += ": " + con_info.ToString();
                }
                if (exist1 != null)
                {
                    message += ": Base.";
                }
                textBlock_NewConceptInfo.Text = message;
            }
            else
            {
                textBlock_NewConceptInfo.Text = "Not Exist";
            }
        }
Пример #2
0
        private void CheckHasNoConnections(Word_ID newWord)
        {
            Connection_Info info = _connectionInfos.Find(c => c.me.WeakSame(newWord));

            if (info != null)
            {
                throw new ApplicationException("It has some connections!");
            }
        }
Пример #3
0
        private List <Connection_Info> InputConnectionFromFile(string filename)
        {
            List <Connection_Info> res = new List <Connection_Info>();
            StreamReader           sr  = new StreamReader(filename, MyEncoding);

            while (!sr.EndOfStream)
            {
                string        line       = sr.ReadLine();
                string[]      splitArray = line.Split(' ');
                List <string> split      = new List <string>();
                for (int i = 0; i < splitArray.Length; ++i)
                {
                    split.Add(splitArray[i]);
                }

                if (split.Count < 2)
                {
                    throw new ArgumentOutOfRangeException("Error in InputConnectionFromFile");
                }

                Connection_Info connnection_info = new Connection_Info();
                //读取当前的word和id
                connnection_info.me = TransformToIdentity(split[0], split[1]);

                if (split.Count == 2)             //没有ConceptEdge就继续下个循环
                {
                    res.Add(connnection_info);
                    continue;
                }

                //读取Edge
                int index = 2;              //开始遍历后面的string
                while (true)
                {
                    if (split[index] != "to")
                    {
                        throw new ArgumentOutOfRangeException("Error in InputConnectionFromFile");
                    }
                    else
                    {
                        index++;
                    }

                    //读取依赖的word及其id
                    Edge_Info edge_info = new Edge_Info();
                    edge_info.to = TransformToIdentity(split[index], split[index + 1]);
                    index       += 2;

                    //读取修饰词
                    int nextTo = split.FindIndex(index, s => s == "to");
                    if (nextTo == -1)//reach end
                    {
                        nextTo = split.Count;
                    }

                    if (nextTo - index == 1)
                    {
                        edge_info.mods = split[index];
                    }
                    else
                    {
                        edge_info.mods = ParseModification(split, index, nextTo);
                    }

                    connnection_info.edge_infos.Add(edge_info);

                    if (nextTo == split.Count)
                    {
                        break;
                    }

                    index = nextTo;                  //移动index到下一个to的位置。
                }

                res.Add(connnection_info);
            }

            return(res);
        }