using System; using System.Collections.Generic; using System.Text; using System.Fire.Serialize.Annotations; namespace Leah.Speech.text { public class ContentEntry { public eMood Mood; public string Text; public List _tags; public List _optionalTags; public float Score; // TODO: Scoring einbauen #region Constructor public ContentEntry() { this.Text = ""; this.Mood = eMood.All; this._tags = new List(); this._optionalTags = new List(); this.Score = 0.0f; } public ContentEntry(string Text) { this.Text = Text; this.Mood = eMood.All; this._tags = new List(); this._optionalTags = new List(); this.Score = 0.0f; } public ContentEntry(string Text, eMood Mood) { this.Text = Text; this.Mood = Mood; this._tags = new List(); this._optionalTags = new List(); this.Score = 0.0f; } public ContentEntry(string Text, eMood Mood, ushort[] Tags) { this.Text = Text; this.Mood = Mood; this._tags = new List(Tags); this._optionalTags = new List(); this.Score = 0.0f; } public ContentEntry(string Text, float score) { this.Text = Text; this.Mood = eMood.All; this._tags = new List(); this._optionalTags = new List(); this.Score = score; } public ContentEntry(string Text, eMood Mood, float score) { this.Text = Text; this.Mood = Mood; this._tags = new List(); this._optionalTags = new List(); this.Score = score; } public ContentEntry(string Text, eMood Mood, ushort[] Tags, float score) { this.Text = Text; this.Mood = Mood; this._tags = new List(Tags); this._optionalTags = new List(); this.Score = score; } #endregion #region Tag public void Tag_Add(ushort s) { if (!this._tags.Contains(s)) { this._tags.Add(s); } } public void Tag_Add(ushort[] s) { foreach (ushort t in s) this.Tag_Add(t); } public void Tag_Add(string tagString) { string[] itms = tagString.Split(new char[] { ',',';','|'}); foreach(string itm in itms) if(itm.Length>0 && itm.Length<=5) { ushort f; if (ushort.TryParse(itm.Trim(), out f)) this.Tag_Add(f); } } public void Tag_Remove(ushort tag) { this._tags.Remove(tag); } public void Tag_RemoveAt(ushort pos) { this._tags.RemoveAt(pos); } public void Tag_Clear() { this._tags.Clear(); } [SerializeIgnore] public int Tag_Count { get { return this._tags.Count; } } public ushort[] Tags { get { return this._tags.ToArray(); } set { this._tags = new List(value); } } public bool Tag_Has(ushort tag) { return this._tags.Contains(tag); } public bool Tag_Has(ushort[] tags) { foreach (ushort t in tags) if (!this._tags.Contains(t)) return false; return true; } #endregion #region OptionalTag public void OptionalTag_Add(ushort s) { if (!this._optionalTags.Contains(s)) { this._optionalTags.Add(s); } } public void OptionalTag_Add(ushort[] s) { foreach (ushort t in s) this.OptionalTag_Add(t); } public void OptionalTag_Add(string tagString) { string[] itms = tagString.Split(new char[] { ',', ';', '|' }); foreach (string itm in itms) if (itm.Length > 0 && itm.Length <= 5) { ushort f; if (ushort.TryParse(itm.Trim(), out f)) this.OptionalTag_Add(f); } } public void OptionalTag_Remove(ushort tag) { this._optionalTags.Remove(tag); } public void OptionalTag_RemoveAt(ushort pos) { this._optionalTags.RemoveAt(pos); } public void OptionalTag_Clear() { this._optionalTags.Clear(); } [SerializeIgnore] public int OptionalTag_Count { get { return this._optionalTags.Count; } } public ushort[] OptionalTags { get { return this._optionalTags.ToArray(); } set { this._optionalTags = new List(value); } } public bool OptionalTag_Has(ushort tag) { return this._optionalTags.Contains(tag); } public bool OptionalTag_Has(ushort[] tags) { foreach (ushort t in tags) if (!this._optionalTags.Contains(t)) return false; return true; } #endregion /*public string Text { get { return this._text; } set { this._text = value; } }*/ /*public eMood Mood { get { return this._mood; } set { this._mood = value; } }*/ /*public float Score { get { return this._score; } set { this._score = value; } }*/ [SerializeIgnore] public string MoodText { get { return Contents.GetMoodString(this.Mood); } set { this.Mood = Contents.GetMood(value); } } public override string ToString() { return this.Text; } [SerializeIgnore] public string Tags_String { get { return String.Join(", ", this._tags.ToArray()); } set { string s = value; string[] v = s.Split(new char[] { ',', ';', '|' }); List res = new List(); for (int i = 0, c = v.Length; i < c; i++) { v[i] = v[i].Trim(); ushort j; if(ushort.TryParse(v[i],out j)) { res.Add(j); } } this._tags = res; } } [SerializeIgnore] public string OptionalTags_String { get { return String.Join(", ", this._optionalTags.ToArray()); } set { string s = value; string[] v = s.Split(new char[] { ',', ';', '|' }); List res = new List(); for (int i = 0, c = v.Length; i < c; i++) { v[i] = v[i].Trim(); ushort j; if (ushort.TryParse(v[i], out j)) { res.Add(j); } } this._optionalTags = res; } } } }