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(); }
private void CheckWordNoEmptyWeak(Word_ID w_i) { if (w_i.id == -1 || w_i.word == "") { throw new ApplicationException("Invalid Word"); } }
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); }
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"); } }
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"; } }
private void CheckWordExisted(Word_ID newWord) { //检查新的Concept是否已经存在 if (WordInList(newWord, _baseConcepts) || WordInList(newWord, _nonBaseConcepts)) { throw new ApplicationException("The concept already exists!"); } }
private void WriteBaseFile(Word_ID newWord) { StreamWriter sw = new StreamWriter(HopeLoveMindPath + BaseConceptsStringFilename, true, MyEncoding); sw.Write("\r\n" + newWord.ToString()); sw.Flush(); sw.Close(); }
private Word_ID GetToConcept() { Word_ID newWord = new Word_ID(); newWord.word = textBox_toConcept.Text; newWord.id = GetTextBoxId(textBox_toConceptID); return(newWord); }
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!"); } }
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); }
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); }
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!"); } }
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!!"); } } }
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!"); } }
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); } }
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; } }
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); }
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); }
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); } }
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(); }
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); }
/// <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); }
private Connection_Info SearchConnectionInfo(Word_ID w_i) { return(_connectionInfos.Find(con => con.me.WeakSame(w_i))); }
public bool Same(Word_ID w_i) { return(word == w_i.word && id == w_i.id && pos == w_i.pos); }