ContentEntry.cs 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Fire.Serialize.Annotations;
  5. namespace Leah.Speech.text {
  6. public class ContentEntry {
  7. public eMood Mood;
  8. public string Text;
  9. public List<ushort> _tags;
  10. public List<ushort> _optionalTags;
  11. public float Score; // TODO: Scoring einbauen
  12. #region Constructor
  13. public ContentEntry() {
  14. this.Text = "";
  15. this.Mood = eMood.All;
  16. this._tags = new List<ushort>();
  17. this._optionalTags = new List<ushort>();
  18. this.Score = 0.0f;
  19. }
  20. public ContentEntry(string Text) {
  21. this.Text = Text;
  22. this.Mood = eMood.All;
  23. this._tags = new List<ushort>();
  24. this._optionalTags = new List<ushort>();
  25. this.Score = 0.0f;
  26. }
  27. public ContentEntry(string Text, eMood Mood) {
  28. this.Text = Text;
  29. this.Mood = Mood;
  30. this._tags = new List<ushort>();
  31. this._optionalTags = new List<ushort>();
  32. this.Score = 0.0f;
  33. }
  34. public ContentEntry(string Text, eMood Mood, ushort[] Tags) {
  35. this.Text = Text;
  36. this.Mood = Mood;
  37. this._tags = new List<ushort>(Tags);
  38. this._optionalTags = new List<ushort>();
  39. this.Score = 0.0f;
  40. }
  41. public ContentEntry(string Text, float score) {
  42. this.Text = Text;
  43. this.Mood = eMood.All;
  44. this._tags = new List<ushort>();
  45. this._optionalTags = new List<ushort>();
  46. this.Score = score;
  47. }
  48. public ContentEntry(string Text, eMood Mood, float score) {
  49. this.Text = Text;
  50. this.Mood = Mood;
  51. this._tags = new List<ushort>();
  52. this._optionalTags = new List<ushort>();
  53. this.Score = score;
  54. }
  55. public ContentEntry(string Text, eMood Mood, ushort[] Tags, float score) {
  56. this.Text = Text;
  57. this.Mood = Mood;
  58. this._tags = new List<ushort>(Tags);
  59. this._optionalTags = new List<ushort>();
  60. this.Score = score;
  61. }
  62. #endregion
  63. #region Tag
  64. public void Tag_Add(ushort s) {
  65. if (!this._tags.Contains(s)) {
  66. this._tags.Add(s);
  67. }
  68. }
  69. public void Tag_Add(ushort[] s) {
  70. foreach (ushort t in s)
  71. this.Tag_Add(t);
  72. }
  73. public void Tag_Add(string tagString) {
  74. string[] itms = tagString.Split(new char[] { ',',';','|'});
  75. foreach(string itm in itms)
  76. if(itm.Length>0 && itm.Length<=5) {
  77. ushort f;
  78. if (ushort.TryParse(itm.Trim(), out f))
  79. this.Tag_Add(f);
  80. }
  81. }
  82. public void Tag_Remove(ushort tag) {
  83. this._tags.Remove(tag);
  84. }
  85. public void Tag_RemoveAt(ushort pos) {
  86. this._tags.RemoveAt(pos);
  87. }
  88. public void Tag_Clear() {
  89. this._tags.Clear();
  90. }
  91. [SerializeIgnore]
  92. public int Tag_Count {
  93. get {
  94. return this._tags.Count;
  95. }
  96. }
  97. public ushort[] Tags {
  98. get {
  99. return this._tags.ToArray();
  100. }
  101. set {
  102. this._tags = new List<ushort>(value);
  103. }
  104. }
  105. public bool Tag_Has(ushort tag) {
  106. return this._tags.Contains(tag);
  107. }
  108. public bool Tag_Has(ushort[] tags) {
  109. foreach (ushort t in tags)
  110. if (!this._tags.Contains(t))
  111. return false;
  112. return true;
  113. }
  114. #endregion
  115. #region OptionalTag
  116. public void OptionalTag_Add(ushort s) {
  117. if (!this._optionalTags.Contains(s)) {
  118. this._optionalTags.Add(s);
  119. }
  120. }
  121. public void OptionalTag_Add(ushort[] s) {
  122. foreach (ushort t in s)
  123. this.OptionalTag_Add(t);
  124. }
  125. public void OptionalTag_Add(string tagString) {
  126. string[] itms = tagString.Split(new char[] { ',', ';', '|' });
  127. foreach (string itm in itms)
  128. if (itm.Length > 0 && itm.Length <= 5) {
  129. ushort f;
  130. if (ushort.TryParse(itm.Trim(), out f))
  131. this.OptionalTag_Add(f);
  132. }
  133. }
  134. public void OptionalTag_Remove(ushort tag) {
  135. this._optionalTags.Remove(tag);
  136. }
  137. public void OptionalTag_RemoveAt(ushort pos) {
  138. this._optionalTags.RemoveAt(pos);
  139. }
  140. public void OptionalTag_Clear() {
  141. this._optionalTags.Clear();
  142. }
  143. [SerializeIgnore]
  144. public int OptionalTag_Count {
  145. get {
  146. return this._optionalTags.Count;
  147. }
  148. }
  149. public ushort[] OptionalTags {
  150. get {
  151. return this._optionalTags.ToArray();
  152. }
  153. set {
  154. this._optionalTags = new List<ushort>(value);
  155. }
  156. }
  157. public bool OptionalTag_Has(ushort tag) {
  158. return this._optionalTags.Contains(tag);
  159. }
  160. public bool OptionalTag_Has(ushort[] tags) {
  161. foreach (ushort t in tags)
  162. if (!this._optionalTags.Contains(t))
  163. return false;
  164. return true;
  165. }
  166. #endregion
  167. /*public string Text {
  168. get {
  169. return this._text;
  170. }
  171. set {
  172. this._text = value;
  173. }
  174. }*/
  175. /*public eMood Mood {
  176. get {
  177. return this._mood;
  178. }
  179. set {
  180. this._mood = value;
  181. }
  182. }*/
  183. /*public float Score {
  184. get {
  185. return this._score;
  186. }
  187. set {
  188. this._score = value;
  189. }
  190. }*/
  191. [SerializeIgnore]
  192. public string MoodText {
  193. get {
  194. return Contents.GetMoodString(this.Mood);
  195. }
  196. set {
  197. this.Mood = Contents.GetMood(value);
  198. }
  199. }
  200. public override string ToString() {
  201. return this.Text;
  202. }
  203. [SerializeIgnore]
  204. public string Tags_String {
  205. get {
  206. return String.Join(", ", this._tags.ToArray());
  207. }
  208. set {
  209. string s = value;
  210. string[] v = s.Split(new char[] { ',', ';', '|' });
  211. List<ushort> res = new List<ushort>();
  212. for (int i = 0, c = v.Length; i < c; i++) {
  213. v[i] = v[i].Trim();
  214. ushort j;
  215. if(ushort.TryParse(v[i],out j)) {
  216. res.Add(j);
  217. }
  218. }
  219. this._tags = res;
  220. }
  221. }
  222. [SerializeIgnore]
  223. public string OptionalTags_String {
  224. get {
  225. return String.Join(", ", this._optionalTags.ToArray());
  226. }
  227. set {
  228. string s = value;
  229. string[] v = s.Split(new char[] { ',', ';', '|' });
  230. List<ushort> res = new List<ushort>();
  231. for (int i = 0, c = v.Length; i < c; i++) {
  232. v[i] = v[i].Trim();
  233. ushort j;
  234. if (ushort.TryParse(v[i], out j)) {
  235. res.Add(j);
  236. }
  237. }
  238. this._optionalTags = res;
  239. }
  240. }
  241. }
  242. }