using System; using System.Collections.Generic; using System.Text; using System.Fire.Serialize.Annotations; namespace Leah.Speech.text { [Flags] public enum eMood : Int32 { None = 0, angry = 1, aroused = 2, hungry = 4, happyness = 8, funny = 16, annoyed = 32, irritated = 64, bored = 128, intelligent = 256, sleepy = 512, energy = 1024, exhausted = 2048, depressive = 4096, sad = 8192, useless = 16384, usefull = 32768, compfortable = 65536, temperate = 131072, shy = 262144, excited = 524288, toLoud = 1048576, toQuiet = 2097152, playful = 4194304, naiv = 8388608, freezy = 16777216, hot = 33554432, humanity = 67108864, lonely = 134217728, soziality = 268435456, // Groups All = 2147483647 } public class Contents { public List Entries = new List(); private Random rnd = new Random(); private List _tags = new List(); private List _optionalTags = new List(); /*public List Entries { get { return this._entries; } set { if (value != null) this._entries = value; } }*/ public int Count { get => this.Entries.Count; } public ContentEntry GetEntry(int index) { if (index >= this.Entries.Count) return null; return this.Entries[index]; } public void RemoveAt(int id) { this.Entries.RemoveAt(id); } public string getText(eMood CategoryId) { List ress = new List(); if (CategoryId == eMood.None) { return this.Entries[rnd.Next(0, this.Entries.Count - 1)].Text; } else { foreach (ContentEntry ce in this.Entries) if ((ce.Mood & CategoryId) > 0) ress.Add(ce); if (ress.Count == 0) { return ress[rnd.Next(0, ress.Count - 1)].Text; } else { return ""; } } } public string getText(eMood CategoryId, ushort Tag) { List ress = new List(); if (CategoryId == eMood.None) { return this.Entries[rnd.Next(0, this.Entries.Count - 1)].Text; } else { foreach (ContentEntry ce in this.Entries) if ((ce.Mood & CategoryId) > 0 && ce.Tag_Has(Tag)) ress.Add(ce); if (ress.Count == 0) { return ress[rnd.Next(0, ress.Count - 1)].Text; } else { return ""; } } } public string getText(eMood CategoryId, ushort[] Tag) { List ress = new List(); if (CategoryId == eMood.None) { return this.Entries[rnd.Next(0, this.Entries.Count - 1)].Text; } else { foreach (ContentEntry ce in this.Entries) if ((ce.Mood & CategoryId) > 0 && ce.Tag_Has(Tag)) ress.Add(ce); if (ress.Count == 0) { return ress[rnd.Next(0, ress.Count - 1)].Text; } else { return ""; } } } public string getText(eMood CategoryId, string Tags) { if (Tags == "") return this.getText(CategoryId); List tl = new List(); string[] ts = Tags.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); foreach (string t in ts) { string t2 = t.ToLower().Trim(); if (t2 != "" && this._tags.Contains(t2)) tl.Add((ushort)this._tags.IndexOf(t2)); } if (tl.Count > 0) return this.getText(CategoryId, tl.ToArray()); return this.getText(CategoryId); } public string getText(string Category, string Tags) { if (Tags == "") return this.getText(Category); List tl = new List(); string[] ts = Tags.Split(new char[]{ '|'}, StringSplitOptions.RemoveEmptyEntries); foreach (string t in ts) { string t2 = t.ToLower().Trim(); if (t2 != "" && this._tags.Contains(t2)) tl.Add((ushort)this._tags.IndexOf(t2)); } if (tl.Count > 0) return this.getText(Category, tl.ToArray()); return this.getText(Category); } public string getText(string Category) { return this.getText(GetMood(Category)); } public string getText(string Category, ushort tag) { return this.getText(GetMood(Category), tag); } public string getText(string Category, ushort[] tags) { return this.getText(GetMood(Category), tags); } public static string GetMoodString(eMood mood) { return GetMoodString(mood,","); } public static string GetMoodString(eMood mood, string Seperator) { string res = ""; if (mood == eMood.None) return "none"; if ((mood | eMood.All) == mood) return "all"; if ((mood | eMood.angry) == mood) res += (res==""?"":Seperator) + "angry"; if ((mood | eMood.annoyed) == mood) res += (res == "" ? "" : Seperator) + "annoyed"; if ((mood | eMood.aroused) == mood) res += (res == "" ? "" : Seperator) + "aroused"; if ((mood | eMood.bored) == mood) res += (res == "" ? "" : Seperator) + "bored"; if ((mood | eMood.compfortable) == mood) res += (res == "" ? "" : Seperator) + "compfortable"; if ((mood | eMood.depressive) == mood) res += (res == "" ? "" : Seperator) + "depressive"; if ((mood | eMood.energy) == mood) res += (res == "" ? "" : Seperator) + "energy"; if ((mood | eMood.excited) == mood) res += (res == "" ? "" : Seperator) + "excited"; if ((mood | eMood.exhausted) == mood) res += (res == "" ? "" : Seperator) + "exhausted"; if ((mood | eMood.freezy) == mood) res += (res == "" ? "" : Seperator) + "freezy"; if ((mood | eMood.funny) == mood) res += (res == "" ? "" : Seperator) + "funny"; if ((mood | eMood.happyness) == mood) res += (res == "" ? "" : Seperator) + "happyness"; if ((mood | eMood.hot) == mood) res += (res == "" ? "" : Seperator) + "hot"; if ((mood | eMood.humanity) == mood) res += (res == "" ? "" : Seperator) + "humanity"; if ((mood | eMood.hungry) == mood) res += (res == "" ? "" : Seperator) + "hungry"; if ((mood | eMood.intelligent) == mood) res += (res == "" ? "" : Seperator) + "intelligent"; if ((mood | eMood.irritated) == mood) res += (res == "" ? "" : Seperator) + "irritated"; if ((mood | eMood.lonely) == mood) res += (res == "" ? "" : Seperator) + "lonely"; if ((mood | eMood.naiv) == mood) res += (res == "" ? "" : Seperator) + "naiv"; if ((mood | eMood.playful) == mood) res += (res == "" ? "" : Seperator) + "playful"; if ((mood | eMood.sad) == mood) res += (res == "" ? "" : Seperator) + "sad"; if ((mood | eMood.shy) == mood) res += (res == "" ? "" : Seperator) + "shy"; if ((mood | eMood.sleepy) == mood) res += (res == "" ? "" : Seperator) + "sleepy"; if ((mood | eMood.soziality) == mood) res += (res == "" ? "" : Seperator) + "soziality"; if ((mood | eMood.temperate) == mood) res += (res == "" ? "" : Seperator) + "temperate"; if ((mood | eMood.toLoud) == mood) res += (res == "" ? "" : Seperator) + "toLoud"; if ((mood | eMood.toQuiet) == mood) res += (res == "" ? "" : Seperator) + "toQuiet"; if ((mood | eMood.usefull) == mood) res += (res == "" ? "" : Seperator) + "usefull"; if ((mood | eMood.useless) == mood) res += (res == "" ? "" : Seperator) + "useless"; return res; } public static eMood GetMood(string Category) { return GetMood(new char[] { '|',',',';','/' }, Category); //return GetMood(new char[] {',' }, Category); } public static eMood GetMood(char Seperator, string Category) { return GetMood(new char[] { Seperator }, Category); } public static eMood GetMood(char[] Seperator, string Category) { Category = Category.ToLower(); if (Category == "" || Category == "none" || Category == "null" || Category=="-") return eMood.None; if (Category == "all" || Category == "any" || Category == "+") return eMood.All; eMood m = eMood.None; string[] x = Category.Split(Seperator); foreach (string y in x) { switch (y.Trim()) { case "a": case "angry": case "mad": m |= eMood.angry; break; case "annoyed": m |= eMood.annoyed; break; case "aroused": m |= eMood.aroused; break; case "bored": m |= eMood.bored; break; case "compfort": case "compfortable": m |= eMood.compfortable; break; case "depress": case "dep": case "depressive": m |= eMood.depressive; break; case "e": case "energy": case "energie": m |= eMood.energy; break; case "excited": m |= eMood.excited; break; case "weak": case "exhausted": m |= eMood.exhausted; break; case "freez": case "cold": case "freezy": m |= eMood.freezy; break; case "fun": case "funny": m |= eMood.funny; break; case "happy": case "happyness": m |= eMood.happyness; break; case "hot": m |= eMood.hot; break; case "humanity": case "human": m |= eMood.humanity; break; case "hungry": case "food": m |= eMood.hungry; break; case "int": case "intelligent": case "i": m |= eMood.intelligent; break; case "irritated": case "irr": m |= eMood.irritated; break; case "lonely": case "single": case "alone": case "lone": m |= eMood.lonely; break; case "n": case "naiv": m |= eMood.naiv; break; case "play": case "playful": m |= eMood.playful; break; case "sad": m |= eMood.sad; break; case "shy": m |= eMood.shy; break; case "sleepy": case "sleep": case "sl": m |= eMood.sleepy; break; case "soziality": case "sozial": m |= eMood.soziality; break; case "temperate": case "temp": case "temperature": m |= eMood.temperate; break; case "toloud": case "loud": m |= eMood.toLoud; break; case "quiet": case "toquiet": m |= eMood.toQuiet; break; case "use": case "usefull": m |= eMood.usefull; break; case "nouse": case "useless": m |= eMood.useless; break; } } return m; } public bool Add(string Text, eMood Mood, ushort[] Tags) { string lText = Text.ToLower().Trim(); foreach (ContentEntry ce in this.Entries) { if (ce.Text.ToLower() == lText) { ce.Mood = Mood; ce.Tags = Tags; return true; } } this.Entries.Add(new ContentEntry(Text.Trim(), Mood, Tags)); return true; } public bool Add(ContentEntry entry) { this.Entries.Add(entry); return true; } public bool Add(string Text, string Mood, ushort[] Tags) { string lText = Text.ToLower().Trim(); foreach (ContentEntry ce in this.Entries) { if (ce.Text.ToLower() == lText) { ce.Mood = GetMood(Mood); ce.Tags = Tags; return true; } } this.Entries.Add(new ContentEntry(Text.Trim(), GetMood(Mood), Tags)); return true; } public bool Add(string Text, eMood Mood) { string lText = Text.ToLower().Trim(); foreach (ContentEntry ce in this.Entries) { if (ce.Text.ToLower() == lText) { ce.Mood = Mood; return true; } } this.Entries.Add(new ContentEntry(Text.Trim(), Mood)); return true; } public bool Add(string Text, string Mood) { string lText = Text.ToLower().Trim(); foreach (ContentEntry ce in this.Entries) { if (ce.Text.ToLower() == lText) { ce.Mood = GetMood(Mood); return true; } } this.Entries.Add(new ContentEntry(Text.Trim(), GetMood(Mood))); return true; } public string[] Tags { get => this._tags.ToArray(); set => this._tags = new List(value); } public string[] OptionalTags { get => this._optionalTags.ToArray(); set => this._optionalTags = new List(value); } [SerializeIgnore] public ContentUseage[] TagUseage { get { List res = new List(); for(ushort i=0;i res = new List(); for (ushort i = 0; i < this._optionalTags.Count; i++) { ContentUseage cu = new ContentUseage(i, this._optionalTags[i]); foreach (ContentEntry ce in this.Entries) { if (ce.Tag_Has(i)) { cu.Count++; } } res.Add(cu); } return res.ToArray(); } } public ushort Tag_Add(string tag) { if (this._tags.Contains(tag)) return (ushort)this._tags.IndexOf(tag); ushort res = (ushort)this._tags.Count; this._tags.Add(tag); return res; } public void Tag_Remove(string tag) { if (!this._tags.Contains(tag)) return; ushort tag_id = (ushort)this._tags.IndexOf(tag); this.Tag_RemoveAt(tag_id); } public void Tag_RemoveAt(ushort tag_id) { foreach (ContentEntry entry in this.Entries) entry.Tag_Remove(tag_id); foreach (ContentEntry entry in this.Entries) for (int i = 0, c = entry.Tags.Length; i < c; i++) if (entry.Tags[i] > tag_id) entry.Tags[i]--; this._tags.RemoveAt(tag_id); } public void Tag_Clear() { foreach (ContentEntry entry in this.Entries) entry.Tag_Clear(); this._tags.Clear(); } public ushort OptionalTag_Add(string tag) { if (this._tags.Contains(tag)) return (ushort)this._optionalTags.IndexOf(tag); ushort res = (ushort)this._optionalTags.Count; this._optionalTags.Add(tag); return res; } public void OptionalTag_Remove(string tag) { if (!this._optionalTags.Contains(tag)) return; ushort tag_id = (ushort)this._optionalTags.IndexOf(tag); this.OptionalTag_RemoveAt(tag_id); } public void OptionalTag_RemoveAt(ushort tag_id) { foreach (ContentEntry entry in this.Entries) entry.OptionalTag_Remove(tag_id); foreach (ContentEntry entry in this.Entries) for(int i=0,c=entry.OptionalTags.Length;itag_id) entry.OptionalTags[i]--; this._optionalTags.RemoveAt(tag_id); } public void OptionalTag_Clear() { foreach (ContentEntry entry in this.Entries) entry.OptionalTag_Clear(); this._optionalTags.Clear(); } } }