private void DeleteChildCommandBinding_Executed(object sender, ExecutedRoutedEventArgs e) { MessageBoxResult result; ChildWord target = (ChildWord)ChildListBox.SelectedItem; result = MessageBox.Show("Are you sure you want to delete this child?", "Delete child?", MessageBoxButton.YesNo, MessageBoxImage.Warning); if (result == MessageBoxResult.No) { return; } result = MessageBox.Show("Do you want to delete the associated root word?\r\n(" + target.StrippedData + ")", "Delete root word?", MessageBoxButton.YesNo, MessageBoxImage.Question); Word root = (Word)RootListBox.SelectedItem; root.Children.Remove(target); if (result == MessageBoxResult.Yes) { try { root = Context.Words.Single(x => x.Data == target.StrippedData); Context.Words.Remove(root); } catch (Exception ex) { Log("Error:\n" + ex.Message); } } }
public static string Generate(MarkovData context) { if (m_Rnd == null) { m_Rnd = new Random(); } List <Word> _starters = context.GetStarters(); List <Word> starters = new List <Word>(); foreach (Word w in _starters) { for (int i = 0; i < w.Prevalence; i++) { starters.Add(w); } } Word prev = starters[m_Rnd.Next(0, starters.Count)]; string rtn = prev.Data + " "; while (true) { ChildWord w = prev.Children[m_Rnd.Next(0, prev.Children.Count)]; rtn += w.Data; prev = context.Find(Strip(w.Data)); if (w.IsEnding) { break; } else { rtn += " "; } } return(rtn); }