Advertisement
Guest User

Untitled

a guest
Dec 19th, 2014
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.24 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11.  
  12. namespace ChatAI
  13. {
  14. public partial class Form1 : Form
  15. {
  16. int czaswyswietlajacy = 0;
  17. int przerzutnik = 0;
  18. string[] Table;
  19.  
  20.  
  21.  
  22.  
  23. public Form1()
  24. {
  25. InitializeComponent();
  26. }
  27.  
  28. public void Form1_Load(object sender, EventArgs e)
  29. {
  30.  
  31. }
  32.  
  33. private void CheckKeys(object sender, KeyPressEventArgs e)
  34. {
  35. if (e.KeyChar == (char)13)
  36. {
  37.  
  38. //START "PISANIE"
  39. przerzutnik = 0;
  40. label2.Visible = true;
  41. czaswyswietlajacy = inputBox.Text.Length / 10;
  42. timer1.Start();
  43. //KONIEC "PISANIA"
  44. inputBox.Select(0, 0);
  45. putIntoHUMAN(inputBox.Text, Color.Green, true);
  46.  
  47. }
  48.  
  49. }
  50.  
  51. private void inputBox_TextChanged(object sender, EventArgs e)
  52. {
  53. inputBox.Text = inputBox.Text.Replace(Environment.NewLine, "");
  54.  
  55.  
  56. }
  57.  
  58. /// <podsumowanie>
  59. /// Funkcje putIntoHUMAN - dodajemy wpis jako czlowiek
  60. /// analogicznie dla putIntoAI - jako maszyna/robot/puszka/program itp. :D
  61. /// w checkkeys sprawdza czy zostal nacisniety enter, a nastepnie przesyla
  62. /// wraz z odpowiednimi argumentami polecenie funkcji putIntoHuman
  63. ///
  64. /// TODO:
  65. /// pobieranie z bazy danych
  66. /// gimbusiarskie, nastoletnie formatowanie (upodobnienie tekstu wyjsciowego do tekstu typowego nastolatka)
  67. /// GOTOWE moment pisania przez bota
  68. ///
  69. /// </podsumowanie>
  70.  
  71. private void timer1_Tick(object sender, EventArgs e)
  72. {
  73. if (timer1.Enabled == true)
  74. {
  75.  
  76. if (czaswyswietlajacy > 0)
  77. {
  78. czaswyswietlajacy--;
  79. }
  80. else
  81. {
  82. label2.Visible = false;
  83. timer1.Stop();
  84.  
  85. }
  86. }
  87. }
  88.  
  89. private void button1_Click(object sender, EventArgs e)
  90. {
  91. OpenFileDialog ofd = new OpenFileDialog();
  92. if (ofd.ShowDialog() == DialogResult.OK)
  93. {
  94. label1.Text = ofd.FileName;
  95.  
  96.  
  97.  
  98. listBox1.Items.Clear();
  99.  
  100. List<string> lines = new List<string>();
  101. using (StreamReader r = new StreamReader(ofd.OpenFile()))
  102. {
  103. string line;
  104. while ((line = r.ReadLine()) != null)
  105. {
  106. listBox1.Items.Add(line);
  107.  
  108. }
  109. }
  110.  
  111. }
  112. }
  113.  
  114. public void przeszukajBaze(string zdanie)
  115. {
  116. zdanie = zdanie.Replace(",", " ");
  117. zdanie = zdanie.Replace("?", " ");
  118. zdanie = zdanie.Replace("!", " ");
  119. zdanie = zdanie.Replace(";", " ");
  120. zdanie = zdanie.Replace("-", " ");
  121. zdanie = zdanie.Replace(".", " ");
  122. zdanie = zdanie.Replace("", " ");
  123.  
  124. zdanie = zdanie.Replace(" ", " ");
  125. zdanie = zdanie.Replace(" ", " ");
  126. zdanie = zdanie.Replace(" ", " ");
  127. zdanie = zdanie.Replace(" ", " ");
  128. string[] Table = zdanie.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
  129. listBox2.Items.Clear();
  130. listBox2.Items.AddRange(Table);
  131. bool wlaczone = true;
  132. for (int i = 0; i < listBox2.Items.Count && wlaczone == true; i++)
  133. {
  134. listBox2.SelectedIndex = i;
  135. zdanie = listBox2.SelectedItem.ToString().Trim();
  136.  
  137. label7.Text = zdanie;
  138. if (zdanie != string.Empty)
  139. {
  140.  
  141. int index = listBox1.FindString(zdanie);
  142. if (index != -1)
  143. {
  144. listBox1.SetSelected(index, true);
  145. wlaczone = false;
  146. string dopodzialu = listBox1.SelectedItem.ToString();
  147.  
  148. string[] Table3 = listBox1.SelectedItem.ToString().Split(new string[] { "&&" }, StringSplitOptions.RemoveEmptyEntries);
  149.  
  150. formater(Table3[1], Convert.ToInt16(Table3[2]), Convert.ToInt16(Table3[3]));
  151. }
  152. }
  153. }
  154.  
  155.  
  156. }
  157.  
  158. public void putIntoHUMAN(string text, Color color, bool AddNewLine = false)
  159. {
  160. if (AddNewLine)
  161. {
  162. text += Environment.NewLine;
  163. }
  164.  
  165. outputBox.SelectionStart = outputBox.TextLength;
  166. outputBox.SelectionLength = 0;
  167.  
  168.  
  169. label1.Text = text;
  170. outputBox.SelectionColor = color;
  171. outputBox.AppendText("[" + DateTime.Now.ToString("HH:mm:ss") + "] >> " + text);
  172. outputBox.SelectionColor = outputBox.ForeColor;
  173. inputBox.Clear();
  174. inputBox.Select(0, 0);
  175. przeszukajBaze(text);
  176.  
  177. }
  178.  
  179. public void putintoAI(string text, Color color, bool AddNewLine = false)
  180. {
  181. if (AddNewLine)
  182. {
  183. text += Environment.NewLine;
  184. }
  185.  
  186. outputBox.SelectionStart = outputBox.TextLength;
  187. outputBox.SelectionLength = 0;
  188.  
  189. outputBox.SelectionColor = color;
  190. outputBox.AppendText("[" + DateTime.Now.ToString("HH:mm:ss") + "] << " + text);
  191. outputBox.SelectionColor = outputBox.ForeColor;
  192.  
  193. inputBox.Clear();
  194. inputBox.Select(0, 0);
  195. }
  196.  
  197. private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
  198. {
  199. }
  200.  
  201. public void formater(string tekstDoObrobki, int emocja, int licznik)
  202. {
  203. putintoAI(tekstDoObrobki, Color.Red,true);
  204. }
  205. }
  206.  
  207. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement