private string RelationshipAnalogy(Feature old, Feature newOld, Feature prevOfCurr, Feature current) { string return_message = ""; /*Console.WriteLine("old: " + old.Data); Console.WriteLine("new: " + newOld.Data); Console.WriteLine("relationship: " + old.getRelationshipNeighbor(newOld.Data)); Console.WriteLine("previous of current: " + prevOfCurr.Data); Console.WriteLine("current: " + current.Data); Console.WriteLine("relationship: " + prevOfCurr.getRelationshipNeighbor(current.Data)); */ // Senten Patterns list - for 3 nodes List<string> sentencePatterns = new List<string>(); Random rnd = new Random(); //Define A1, B1, A2, B2, R1,and R2. // Node A1 has relationship R1 with node B1. // Node A2 has relaitonship R2 with node B2. // AND R1 and R2 are in the same list inside equivalent_relationship list. string a1 = ""; string b1 = ""; string a2 = ""; string b2 = ""; string r1 = ""; string r2 = ""; //Check equivalent and similarity bool found = false; bool directional = false; //Check if the relationship is a directional word. if (Directional_Words.Contains(old.getRelationshipNeighbor(newOld.Data)) || Directional_Words.Contains(newOld.getRelationshipNeighbor(old.Data))) { directional = true; }//end if foreach (List<string> list in equivalent_relationships) { if (found == true) break; if ((list.Contains(old.getRelationshipNeighbor(newOld.Data)) && list.Contains(prevOfCurr.getRelationshipNeighbor(current.Data))) || old.getRelationshipNeighbor(newOld.Data).Equals(prevOfCurr.getRelationshipNeighbor(current.Data))) { a1 = old.Data; b1 = newOld.Data; a2 = prevOfCurr.Data; b2 = current.Data; r1 = old.getRelationshipNeighbor(newOld.Data); r2 = prevOfCurr.getRelationshipNeighbor(current.Data); found = true; } else if ((list.Contains(newOld.getRelationshipNeighbor(old.Data)) && list.Contains(current.getRelationshipNeighbor(prevOfCurr.Data))) || newOld.getRelationshipNeighbor(old.Data).Equals(current.getRelationshipNeighbor(prevOfCurr.Data))) { a1 = newOld.Data; b1 = old.Data; a2 = current.Data; b2 = prevOfCurr.Data; r1 = newOld.getRelationshipNeighbor(old.Data); r2 = current.getRelationshipNeighbor(prevOfCurr.Data); found = true; } else if ((list.Contains(newOld.getRelationshipNeighbor(old.Data)) && list.Contains(prevOfCurr.getRelationshipNeighbor(current.Data))) || newOld.getRelationshipNeighbor(old.Data).Equals(prevOfCurr.getRelationshipNeighbor(current.Data))) { a1 = newOld.Data; b1 = old.Data; a2 = prevOfCurr.Data; b2 = current.Data; r1 = newOld.getRelationshipNeighbor(old.Data); r2 = prevOfCurr.getRelationshipNeighbor(current.Data); found = true; } else if ((list.Contains(old.getRelationshipNeighbor(newOld.Data)) && list.Contains(current.getRelationshipNeighbor(prevOfCurr.Data))) || old.getRelationshipNeighbor(newOld.Data).Equals(current.getRelationshipNeighbor(prevOfCurr.Data))) { a1 = old.Data; b1 = newOld.Data; a2 = current.Data; b2 = prevOfCurr.Data; r1 = old.getRelationshipNeighbor(newOld.Data); r2 = current.getRelationshipNeighbor (prevOfCurr.Data); found = true; } } //If there is a blank relationship, no analogy may be made. if (r1.Equals("") || r2.Equals("")) return ""; //if a1 equals a2 and b1 equals b2, no analogy may be made. if (a1.Equals(a2) && b1.Equals(b2)) return ""; //If the relationship is directional and b1 does NOT equal b2, then //no analogy may be made. if (directional && !(b1.Equals(b2))) { return ""; }//end if //if (old.getRelationshipNeighbor(newOld.Data).Equals(prevOfCurr.getRelationshipNeighbor(current.Data)) && // old.getRelationshipNeighbor(newOld.Data) != "" && prevOfCurr.getRelationshipNeighbor(current.Data) != "") //{ //string relationship = old.getRelationshipNeighbor(newOld.Data); // enable bilingual mode string a1_en = a1; string a1_cn = a1; if (a1.Contains("##")) { a1_en = a1.Split(new string[] { "##" }, StringSplitOptions.None)[0]; a1_cn = a1.Split(new string[] { "##" }, StringSplitOptions.None)[1]; } string b1_en = b1; string b1_cn = b1; if (b1.Contains("##")) { b1_en = b1.Split(new string[] { "##" }, StringSplitOptions.None)[0]; b1_cn = b1.Split(new string[] { "##" }, StringSplitOptions.None)[1]; } string r1_en = r1; string r1_cn = r1; if (r1.Contains("##")) { r1_en = r1.Split(new string[] { "##" }, StringSplitOptions.None)[0]; r1_cn = r1.Split(new string[] { "##" }, StringSplitOptions.None)[1]; } string a2_en = a2; string a2_cn = a2; if (a2.Contains("##")) { a2_en = a2.Split(new string[] { "##" }, StringSplitOptions.None)[0]; a2_cn = a2.Split(new string[] { "##" }, StringSplitOptions.None)[1]; } string b2_en = b2; string b2_cn = b2; if (b2.Contains("##")) { b2_en = b2.Split(new string[] { "##" }, StringSplitOptions.None)[0]; b2_cn = b2.Split(new string[] { "##" }, StringSplitOptions.None)[1]; } string r2_en = r2; string r2_cn = r2; if (r2.Contains("##")) { r2_en = r2.Split(new string[] { "##" }, StringSplitOptions.None)[0]; r2_cn = r2.Split(new string[] { "##" }, StringSplitOptions.None)[1]; } // 4 nodes sentencePatterns.Add("[Just as " + a1_en + " " + r1_en + " " + b1_en + ", so too " + a2_en + " " + r2_en + " " + b2_en + ".] " + "##" + "[正像" + a1_cn + r1_cn + b1_cn + "一样," + a2_cn + r2_cn + b2_cn + "。] " + "##"); sentencePatterns.Add("[" + a2_en + " " + r2_en + " " + b2_en + ", much like " + a1_en + " " + r1_en + " " + b1_en + ".] " + "##" + "[" + a2_cn + r2_cn + b2_cn + "," + "就像" + a1_cn + r1_cn + b1_cn + "。] " + "##"); sentencePatterns.Add("[Like " + a1_en + " " + r1_en + " " + b1_en + ", " + a2_en + " also " + r2_en + " " + b2_en + ".] " + "##" + "[像" + a1_cn + r1_cn + b1_cn + "一样," + a2_cn + "也" + r2_cn + b2_cn + "。] " + "##"); sentencePatterns.Add("[The same way that " + a1_en + " " + r1_en + " " + b1_en + ", " + a2_en + " " + r2_en + " " + b2_en + ".] " + "##" + "[如同" + a1_cn + r1_cn + b1_cn + "一般," + a2_cn + r2_cn + b2_cn + "。] " + "##"); sentencePatterns.Add("[Remember how " + a1_en + " " + r1_en + " " + b1_en + "? Well, in the same way, " + a2_en + " also " + r2_en + " " + b2_en + ".] " + "##" + "[就像" + a1_cn + r1_cn + b1_cn + "一样," + a2_cn + "也" + r2_cn + b2_cn + "。] " + "##"); sentencePatterns.Add("[" + a2_en + " also " + r2_en + " " + b2_en + ", similar to how " + a1_en + " " + r1_en + " " + b1_en + ".] " + "##" + "[" + a2_cn + r2_cn + b2_cn + "," + "正像" + a1_cn + r1_cn + b1_cn + "。] " + "##"); int random_int = rnd.Next(sentencePatterns.Count); return_message += sentencePatterns[random_int]; //} //DEBUG Console.WriteLine("return_message: " + return_message); return return_message; }
//optional parameter for_additional_info, if set true, will avoid any actual leading statements //except for relationship mentions. If no relationship mention can be made, then blank string //is returned. private string LeadingTopic(Feature last, Feature first, bool for_additional_info = false) { string return_message = ""; string first_data_en = first.Data; string first_data_cn = first.Data; if (first.Data.Contains("##")) { first_data_en = first.Data.Split(new string[] { "##" }, StringSplitOptions.None)[0]; first_data_cn = first.Data.Split(new string[] { "##" }, StringSplitOptions.None)[1]; } Console.WriteLine("In LeadingTopic, first_data_en " + first_data_en + " first_data_cn " + first_data_cn); string last_data_en = last.Data; string last_data_cn = last.Data; if (last.Data.Contains("##")) { last_data_en = last.Data.Split(new string[] { "##" }, StringSplitOptions.None)[0]; last_data_cn = last.Data.Split(new string[] { "##" }, StringSplitOptions.None)[1]; } Console.WriteLine("In LeadingTopic, last_data_en " + last_data_en + " last_data_cn " + last_data_cn); //First is the current node (the one that has just been traversed to) //A set of possible lead-in statements. List<string> lead_in_statements = new List<string>(); lead_in_statements.Add("{There's also " + first_data_en + ".} " + "##" + "{还有" + first_data_cn + "呢。} " + "##"); lead_in_statements.Add("{But let's talk about " + first_data_en + ".} " + "##" + "{我们来聊聊" + first_data_cn + "吧。} " + "##"); lead_in_statements.Add("{And have I mentioned " + first_data_en + "?} " + "##" + "{之前我说过" + first_data_cn + "吗?} " + "##"); lead_in_statements.Add("{Now, about " + first_data_en + ".} " + "##" + "{接下来是" + first_data_cn + "。} " + "##"); lead_in_statements.Add("{Now, let's talk about " + first_data_en + ".} " + "##" + "{接着我们说说" + first_data_cn + "吧。} " + "##"); lead_in_statements.Add("{I should touch on " + first_data_en + ".} " + "##" + "{我要谈谈关于" + first_data_cn + "。} " + "##"); lead_in_statements.Add("{Have you heard of " + first_data_en + "?} " + "##" + "{你听说过" + first_data_cn + "吗?} " + "##"); //A set of lead-in statements for non-novel nodes List<string> non_novel_lead_in_statements = new List<string>(); non_novel_lead_in_statements.Add("{There's also " + first_data_en + ".} " + "##" + "{还有" + first_data_cn + "呢。} " + "##"); non_novel_lead_in_statements.Add("{Let's talk about " + first_data_en + ".} " + "##" + "{我们谈谈" + first_data_cn + "吧。} " + "##"); non_novel_lead_in_statements.Add("{I'll mention " + first_data_en + " real quick.} " + "##" + "{我想简要提提" + first_data_cn + "。} " + "##"); non_novel_lead_in_statements.Add("{So, about " + first_data_en + ".} " + "##" + "{那么,说说" + first_data_cn + "。} " + "##"); non_novel_lead_in_statements.Add("{Now then, about " + first_data_en + ".} " + "##" + "{现在谈谈" + first_data_cn + "吧。} " + "##"); non_novel_lead_in_statements.Add("{Let's talk about " + first_data_en + " for a moment.} " + "##" + "{我们聊一会儿" + first_data_cn + " 吧。} " + "##"); non_novel_lead_in_statements.Add("{Have I mentioned " + first_data_en + "?} " + "##" + "{之前我说过" + first_data_cn + "吗?} " + "##"); non_novel_lead_in_statements.Add("{Now, about " + first_data_en + ".} " + "##" + "{接着是" + first_data_cn + "。} " + "##"); non_novel_lead_in_statements.Add("{Now, let's talk about " + first_data_en + ".} " + "##" + "{现在我们谈谈" + first_data_cn + "吧。} " + "##"); non_novel_lead_in_statements.Add("{I should touch on " + first_data_en + ".} " + "##" + "{我要说说" + first_data_cn + "。} " + "##"); //A set of lead-in statements for novel nodes //TODO: Author these again; things like let's talk about something different now. List<string> novel_lead_in_statements = new List<string>(); novel_lead_in_statements.Add("{Let's talk about something different. " + "##" + "{我们聊点别的吧。" + "##"); novel_lead_in_statements.Add("{Let's talk about something else. " + "##" + "{我们说点其他的吧。" + "##"); novel_lead_in_statements.Add("{Let's switch gears. " + "##" + "{我们换个话题吧。" + "##"); Random rand = new Random(); // Check if there is a relationship between two nodes if (last.getNeighbor(first.Data) != null || first.getNeighbor(last.Data) != null) { string relationship_neighbor_en = last.getRelationshipNeighbor(first.Data); string relationship_neighbor_cn = last.getRelationshipNeighbor(first.Data); string relationship_parent_en = last.getRelationshipParent(first.Data); string relationship_parent_cn = last.getRelationshipParent(first.Data); Console.WriteLine("In LeadingTopic, relationship_neighbor_en " + relationship_neighbor_en + " relationship_neighbor_cn " + relationship_neighbor_cn); if (relationship_neighbor_en.Contains("##")) { relationship_neighbor_en = relationship_neighbor_en.Split(new string[] { "##" }, StringSplitOptions.None)[0]; relationship_neighbor_cn = relationship_neighbor_cn.Split(new string[] { "##" }, StringSplitOptions.None)[1]; } if (relationship_parent_en.Contains("##")) { relationship_parent_en = relationship_parent_en.Split(new string[] { "##" }, StringSplitOptions.None)[0]; relationship_parent_cn = relationship_parent_cn.Split(new string[] { "##" }, StringSplitOptions.None)[1]; }//end if // Check if last has first as its neighbor if (!last.getRelationshipNeighbor (first.Data).Equals("") && !(last.getRelationshipNeighbor (first.Data) == null)) { return_message = "{" + last_data_en + " " + relationship_neighbor_en + " " + first_data_en + ".} " + "##" + "{" + last_data_cn + " " + relationship_neighbor_cn + " " + first_data_cn + ".} " + "##"; return return_message; }//end if // If last is a child node of first (first is a parent of last) else if (!last.getRelationshipParent (first.Data).Equals("") && !(last.getRelationshipParent(first.Data) == null)) { return_message = "{" + last_data_en + " " + relationship_parent_en + " " + first_data_en + ".} " + "##" + "{" + last_data_cn + " " + relationship_parent_cn + " " + first_data_cn + ".} " + "##"; return return_message; }//end else if }//end if // Neither neighbor or parent/child. //If this is for additional info, return blank string; the two nodes //are not neighbors or have a blank relationship. if (for_additional_info) return ""; // NEED TO consider novelty value (low) //else if (last.getNeighbor(first.Data) == null || first.getNeighbor(last.Data) == null) //If the novelty is high enough, always include a novel topic lead-in statement. if (noveltyValue >= 0.6) return_message += novel_lead_in_statements[rand.Next(novel_lead_in_statements.Count)]; //Otherwise, include a non-novel topic lead-in statement. else { return_message += non_novel_lead_in_statements[rand.Next(non_novel_lead_in_statements.Count)]; }//end if //!FindSpeak(first).Contains<string>(first.Data) return return_message; }