Contents.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. namespace Speech.text {
  5. [Flags]
  6. public enum eMood : Int32 {
  7. None = 0,
  8. angry = 1,
  9. aroused = 2,
  10. hungry = 4,
  11. happyness = 8,
  12. funny = 16,
  13. annoyed = 32,
  14. irritated = 64,
  15. bored = 128,
  16. intelligent = 256,
  17. sleepy = 512,
  18. energy = 1024,
  19. exhausted = 2048,
  20. depressive = 4096,
  21. sad = 8192,
  22. useless = 16384,
  23. usefull = 32768,
  24. compfortable = 65536,
  25. temperate = 131072,
  26. shy = 262144,
  27. excited = 524288,
  28. toLoud = 1048576,
  29. toQuiet = 2097152,
  30. playful = 4194304,
  31. naiv = 8388608,
  32. freezy = 16777216,
  33. hot = 33554432,
  34. humanity = 67108864,
  35. lonely = 134217728,
  36. soziality = 268435456,
  37. // Groups
  38. All = 2147483647
  39. }
  40. public class Contents {
  41. private List<ContentEntry> _entries = new List<ContentEntry>();
  42. private Random rnd = new Random();
  43. private List<string> _tags = new List<string>();
  44. public List<ContentEntry> Entries {
  45. get {
  46. return this._entries;
  47. }
  48. set {
  49. if(value!=null)
  50. this._entries = value;
  51. }
  52. }
  53. public int Count {
  54. get => this._entries.Count;
  55. }
  56. public string getText(eMood CategoryId) {
  57. List<ContentEntry> ress = new List<ContentEntry>();
  58. if (CategoryId == eMood.None) {
  59. return this._entries[rnd.Next(0, this._entries.Count-1)].Text;
  60. } else {
  61. foreach (ContentEntry ce in this._entries)
  62. if ((ce.Mood & CategoryId) > 0)
  63. ress.Add(ce);
  64. if (ress.Count == 0) {
  65. return ress[rnd.Next(0, ress.Count - 1)].Text;
  66. } else {
  67. return "";
  68. }
  69. }
  70. }
  71. public string getText(eMood CategoryId, ushort Tag) {
  72. List<ContentEntry> ress = new List<ContentEntry>();
  73. if (CategoryId == eMood.None) {
  74. return this._entries[rnd.Next(0, this._entries.Count - 1)].Text;
  75. } else {
  76. foreach (ContentEntry ce in this._entries)
  77. if ((ce.Mood & CategoryId) > 0 && ce.HasTags(Tag))
  78. ress.Add(ce);
  79. if (ress.Count == 0) {
  80. return ress[rnd.Next(0, ress.Count - 1)].Text;
  81. } else {
  82. return "";
  83. }
  84. }
  85. }
  86. public string getText(eMood CategoryId, ushort[] Tag) {
  87. List<ContentEntry> ress = new List<ContentEntry>();
  88. if (CategoryId == eMood.None) {
  89. return this._entries[rnd.Next(0, this._entries.Count - 1)].Text;
  90. } else {
  91. foreach (ContentEntry ce in this._entries)
  92. if ((ce.Mood & CategoryId) > 0 && ce.HasTags(Tag))
  93. ress.Add(ce);
  94. if (ress.Count == 0) {
  95. return ress[rnd.Next(0, ress.Count - 1)].Text;
  96. } else {
  97. return "";
  98. }
  99. }
  100. }
  101. public string getText(eMood CategoryId, string Tags) {
  102. if (Tags == "")
  103. return this.getText(CategoryId);
  104. List<ushort> tl = new List<ushort>();
  105. string[] ts = Tags.Split('|', StringSplitOptions.RemoveEmptyEntries);
  106. foreach (string t in ts) {
  107. string t2 = t.ToLower().Trim();
  108. if (t2 != "" && this._tags.Contains(t2))
  109. tl.Add((ushort)this._tags.IndexOf(t2));
  110. }
  111. if(tl.Count>0)
  112. return this.getText(CategoryId, tl.ToArray());
  113. return this.getText(CategoryId);
  114. }
  115. public string getText(string Category, string Tags) {
  116. if (Tags == "")
  117. return this.getText(Category);
  118. List<ushort> tl = new List<ushort>();
  119. string[] ts = Tags.Split('|', StringSplitOptions.RemoveEmptyEntries);
  120. foreach (string t in ts) {
  121. string t2 = t.ToLower().Trim();
  122. if (t2 != "" && this._tags.Contains(t2))
  123. tl.Add((ushort)this._tags.IndexOf(t2));
  124. }
  125. if (tl.Count > 0)
  126. return this.getText(Category, tl.ToArray());
  127. return this.getText(Category);
  128. }
  129. public string getText(string Category) {
  130. return this.getText(this.GetMood(Category));
  131. }
  132. public string getText(string Category, ushort tag) {
  133. return this.getText(this.GetMood(Category), tag);
  134. }
  135. public string getText(string Category, ushort[] tags) {
  136. return this.getText(this.GetMood(Category), tags);
  137. }
  138. protected eMood GetMood(string Category) {
  139. eMood m = eMood.None;
  140. string[] x = Category.Split('|');
  141. foreach (string y in x) {
  142. switch (Category.ToLower().Trim()) {
  143. case "angry":
  144. case "mad":
  145. m |= eMood.angry;
  146. break;
  147. case "annoyed":
  148. m |= eMood.annoyed;
  149. break;
  150. case "aroused":
  151. m |= eMood.aroused;
  152. break;
  153. case "bored":
  154. m |= eMood.bored;
  155. break;
  156. case "compfortable":
  157. m |= eMood.compfortable;
  158. break;
  159. case "depressive":
  160. m |= eMood.depressive;
  161. break;
  162. case "energy":
  163. m |= eMood.energy;
  164. break;
  165. case "excited":
  166. m |= eMood.excited;
  167. break;
  168. case "exhausted":
  169. m |= eMood.exhausted;
  170. break;
  171. case "freezy":
  172. m |= eMood.freezy;
  173. break;
  174. case "funny":
  175. m |= eMood.funny;
  176. break;
  177. case "happyness":
  178. m |= eMood.happyness;
  179. break;
  180. case "hot":
  181. m |= eMood.hot;
  182. break;
  183. case "humanity":
  184. m |= eMood.humanity;
  185. break;
  186. case "hungry":
  187. m |= eMood.hungry;
  188. break;
  189. case "intelligent":
  190. m |= eMood.intelligent;
  191. break;
  192. case "irritated":
  193. m |= eMood.irritated;
  194. break;
  195. case "lonely":
  196. m |= eMood.lonely;
  197. break;
  198. case "naiv":
  199. m |= eMood.naiv;
  200. break;
  201. case "playful":
  202. m |= eMood.playful;
  203. break;
  204. case "sad":
  205. m |= eMood.sad;
  206. break;
  207. case "shy":
  208. m |= eMood.shy;
  209. break;
  210. case "sleepy":
  211. case "sleep":
  212. m |= eMood.sleepy;
  213. break;
  214. case "soziality":
  215. case "sozial":
  216. m |= eMood.soziality;
  217. break;
  218. case "temperate":
  219. m |= eMood.temperate;
  220. break;
  221. case "toLoud":
  222. m |= eMood.toLoud;
  223. break;
  224. case "toQuiet":
  225. m |= eMood.toQuiet;
  226. break;
  227. case "usefull":
  228. m |= eMood.usefull;
  229. break;
  230. case "useless":
  231. m |= eMood.useless;
  232. break;
  233. }
  234. }
  235. return m;
  236. }
  237. public bool Add(string Text, eMood Mood, ushort[] Tags) {
  238. string lText = Text.ToLower().Trim();
  239. foreach (ContentEntry ce in this._entries) {
  240. if (ce.Text.ToLower() == lText) {
  241. ce.Mood = Mood;
  242. ce.Tags = Tags;
  243. return true;
  244. }
  245. }
  246. this._entries.Add(new ContentEntry(Text.Trim(), Mood, Tags));
  247. return true;
  248. }
  249. public bool Add(string Text, string Mood, ushort[] Tags) {
  250. string lText = Text.ToLower().Trim();
  251. foreach (ContentEntry ce in this._entries) {
  252. if (ce.Text.ToLower() == lText) {
  253. ce.Mood = this.GetMood(Mood);
  254. ce.Tags = Tags;
  255. return true;
  256. }
  257. }
  258. this._entries.Add(new ContentEntry(Text.Trim(), this.GetMood(Mood), Tags));
  259. return true;
  260. }
  261. public bool Add(string Text, eMood Mood) {
  262. string lText = Text.ToLower().Trim();
  263. foreach (ContentEntry ce in this._entries) {
  264. if (ce.Text.ToLower() == lText) {
  265. ce.Mood = Mood;
  266. return true;
  267. }
  268. }
  269. this._entries.Add(new ContentEntry(Text.Trim(), Mood));
  270. return true;
  271. }
  272. public bool Add(string Text, string Mood) {
  273. string lText = Text.ToLower().Trim();
  274. foreach (ContentEntry ce in this._entries) {
  275. if (ce.Text.ToLower() == lText) {
  276. ce.Mood = this.GetMood(Mood);
  277. return true;
  278. }
  279. }
  280. this._entries.Add(new ContentEntry(Text.Trim(), this.GetMood(Mood)));
  281. return true;
  282. }
  283. }
  284. }