Contents.cs 11 KB

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