コード例 #1
0
        private void WriteConnnectionFile(Word_ID newWord, Word_ID toWord, List <Word_ID> mods)
        {
            StreamWriter sw = new StreamWriter(HopeLoveMindPath + ConceptConnections_InitialFilename, true, MyEncoding);

            string modStr = "";

            mods.ForEach(m =>
            {
                if (modStr != "")
                {
                    modStr += " ";
                }
                modStr += m.ToWeakString();
            });

            string outStr = "\r\n" + newWord.ToWeakString() + " to " + toWord.ToWeakString();

            if (modStr != "")
            {
                outStr += " " + modStr;
            }

            sw.Write(outStr);
            sw.Flush();
            sw.Close();
        }
コード例 #2
0
 private void CheckWordNoEmptyWeak(Word_ID w_i)
 {
     if (w_i.id == -1 || w_i.word == "")
     {
         throw new ApplicationException("Invalid Word");
     }
 }
コード例 #3
0
        private List <Word_ID> GetConnectionConcepts()
        {
            Word_ID edgeWord1 = new Word_ID();

            edgeWord1.word = textBox_Mod1.Text;
            edgeWord1.id   = GetTextBoxId(textBox_Mod1ID);

            Word_ID edgeWord2 = new Word_ID();

            edgeWord2.word = textBox_Mod2.Text;
            edgeWord2.id   = GetTextBoxId(textBox_Mod2ID);

            List <Word_ID> res = new List <Word_ID>();

            if (edgeWord1.id >= 0)
            {
                res.Add(edgeWord1);
            }
            if (edgeWord2.id >= 0)
            {
                res.Add(edgeWord2);
            }

            return(res);
        }
コード例 #4
0
 private void CheckWordNoEmpty(Word_ID w_i)
 {
     if (w_i.id == -1 || w_i.pos == PartOfSpeech.Unknown || w_i.word == "")
     {
         throw new ApplicationException("Invalid Word");
     }
 }
コード例 #5
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";
            }
        }
コード例 #6
0
 private void CheckWordExisted(Word_ID newWord)
 {
     //检查新的Concept是否已经存在
     if (WordInList(newWord, _baseConcepts) || WordInList(newWord, _nonBaseConcepts))
     {
         throw new ApplicationException("The concept already exists!");
     }
 }
コード例 #7
0
        private void WriteBaseFile(Word_ID newWord)
        {
            StreamWriter sw = new StreamWriter(HopeLoveMindPath + BaseConceptsStringFilename, true, MyEncoding);

            sw.Write("\r\n" + newWord.ToString());
            sw.Flush();
            sw.Close();
        }
コード例 #8
0
        private Word_ID GetToConcept()
        {
            Word_ID newWord = new Word_ID();

            newWord.word = textBox_toConcept.Text;
            newWord.id   = GetTextBoxId(textBox_toConceptID);

            return(newWord);
        }
コード例 #9
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!");
            }
        }
コード例 #10
0
        private Word_ID GetNewConcept()
        {
            Word_ID newWord = new Word_ID();

            newWord.word = textBox_NewConcept.Text;
            newWord.id   = GetTextBoxId(textBox_NewID);
            newWord.pos  = GetTextBoxPOS(textBox_POS);

            return(newWord);
        }
コード例 #11
0
        private Word_ID TransformToIdentity(string id, string word)
        {
            Word_ID res = new Word_ID();

            res.word = word;
            res.id   = Convert.ToInt32(id);
            SearchWordPos(res);

            return(res);
        }
コード例 #12
0
        private void CheckPOSUnique(Word_ID newWord)
        {
            List <Word_ID> wordNonBase     = SearchWordOfSameStr(newWord.word, _nonBaseConcepts);
            List <Word_ID> wordBase        = SearchWordOfSameStr(newWord.word, _baseConcepts);
            Word_ID        samePos_NonBase = wordNonBase.Find(w => w.pos == newWord.pos);
            Word_ID        samePos_Base    = wordBase.Find(w => w.pos == newWord.pos);

            if (samePos_Base != null || samePos_NonBase != null)
            {
                throw new ApplicationException("The POS is not unique!");
            }
        }
コード例 #13
0
        private void CheckPos_Me_To(Word_ID newWord, Word_ID toWord)
        {
            Word_ID toWordSearch = SearchWordOfSameWordID_inTotalWord(toWord);

            if (toWordSearch != null)
            {
                if (toWordSearch.pos != newWord.pos && toWordSearch.pos != PartOfSpeech.Noun)
                {
                    throw new ApplicationException("The POS between new word and to word is not matched!!");
                }
            }
        }
コード例 #14
0
        private void CheckWordID(Word_ID newWord)
        {
            //检查ID是否现有的最大ID加1.
            int maxID_base    = MaxID(newWord.word, _baseConcepts);
            int maxID_nonbase = MaxID(newWord.word, _nonBaseConcepts);
            int maxID         = maxID_base > maxID_nonbase ? maxID_base : maxID_nonbase;

            if (newWord.id != maxID + 1)
            {
                throw new ApplicationException("The concept ID is not continuous!");
            }
        }
コード例 #15
0
        private bool WordInList(Word_ID w_i, List <Word_ID> wiList)
        {
            Word_ID exist1 = wiList.Find(wi => wi.WeakSame(w_i));

            if (exist1 == null)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
コード例 #16
0
        private void SearchWordPos(Word_ID w_i)
        {
            Word_ID exist1 = _baseConcepts.Find(wi => w_i.word == wi.word && w_i.id == wi.id);
            Word_ID exist2 = _nonBaseConcepts.Find(wi => w_i.word == wi.word && w_i.id == wi.id);

            if (exist1 != null)
            {
                w_i.pos = exist1.pos;
            }
            else if (exist2 != null)
            {
                w_i.pos = exist2.pos;
            }
        }
コード例 #17
0
        public static Word_ID StringToWordID(string str)
        {
            string[] sp = str.Split(' ');
            if (sp.Length != 2)
            {
                throw new ArgumentOutOfRangeException("StringToWordID");
            }

            Word_ID res = new Word_ID();

            res.id   = Convert.ToInt32(sp[0]);
            res.word = sp[1];

            return(res);
        }
コード例 #18
0
        private XmlElement CreateFromToNode(string fromTo, string nodeTag)
        {
            XmlElement fromNode = _document.CreateElement(nodeTag);

            if (ContainSpecialSymbol(fromTo))//if it is Arbitrariness
            {
                fromNode.InnerText = fromTo;
            }
            else//if it is a common symbol
            {
                Word_ID from = CommonForAppendForm.StringToWordID(fromTo);
                fromNode.SetAttribute("ID", Convert.ToString(from.id));
                fromNode.SetAttribute("Word", from.word);
            }

            return(fromNode);
        }
コード例 #19
0
        private Word_ID SearchWordOfSameWordID_inTotalWord(Word_ID w_i)
        {
            Word_ID bRes  = _baseConcepts.Find(bc => bc.WeakSame(w_i));
            Word_ID nbRes = _nonBaseConcepts.Find(nbc => nbc.WeakSame(w_i));

            if (bRes != null)
            {
                return(bRes);
            }
            else if (nbRes != null)
            {
                return(nbRes);
            }
            else
            {
                return(null);
            }
        }
コード例 #20
0
        private void button_Append_Click(object sender, RoutedEventArgs e)
        {
            Word_ID        newWord = GetNewConcept();
            Word_ID        toWord  = GetToConcept();
            List <Word_ID> mods    = GetConnectionConcepts();

            try
            {
                CheckWordNoEmpty(newWord);
                if (checkBox_IsBase.IsChecked == false)
                {
                    CheckWordNoEmptyWeak(toWord);
                }
                else
                {
                    CheckHasNoConnections(newWord);
                }
                CheckWordExisted(newWord);
                CheckWordID(newWord);
                CheckPOSUnique(newWord);
                CheckPos_Me_To(newWord, toWord);
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }

            if (checkBox_IsBase.IsChecked == true)
            {
                WriteBaseFile(newWord);
            }
            else
            {
                WriteNonBaseFile(newWord);
                WriteConnnectionFile(newWord, toWord, mods);
            }

            Init();
        }
コード例 #21
0
        private List <Word_ID> InputWordFromFile(string filename)
        {
            List <Word_ID> res = new List <Word_ID>();
            StreamReader   sr  = new StreamReader(filename, MyEncoding);

            while (!sr.EndOfStream)
            {
                string   line  = sr.ReadLine();
                string[] split = line.Split(' ');
                if (split.Length != 3)
                {
                    throw new ArgumentOutOfRangeException();
                }

                Word_ID w_i = new Word_ID();
                w_i.id   = Convert.ToInt32(split[0]);
                w_i.word = split[1];
                w_i.pos  = (PartOfSpeech)Convert.ToInt32(split[2]);

                res.Add(w_i);
            }

            return(res);
        }
コード例 #22
0
 /// <summary>
 /// Ignore the difference of POS
 /// </summary>
 /// <param name="w_i"></param>
 /// <returns></returns>
 public bool WeakSame(Word_ID w_i)
 {
     return(word == w_i.word && id == w_i.id);
 }
コード例 #23
0
 private Connection_Info SearchConnectionInfo(Word_ID w_i)
 {
     return(_connectionInfos.Find(con => con.me.WeakSame(w_i)));
 }
コード例 #24
0
 public bool Same(Word_ID w_i)
 {
     return(word == w_i.word && id == w_i.id && pos == w_i.pos);
 }