| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519 |
- 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<ContentEntry> Entries = new List<ContentEntry>();
- private Random rnd = new Random();
- private List<string> _tags = new List<string>();
- private List<string> _optionalTags = new List<string>();
- /*public List<ContentEntry> 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<ContentEntry> ress = new List<ContentEntry>();
- 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<ContentEntry> ress = new List<ContentEntry>();
- 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<ContentEntry> ress = new List<ContentEntry>();
- 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<ushort> tl = new List<ushort>();
- 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<ushort> tl = new List<ushort>();
- 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<string>(value);
- }
- public string[] OptionalTags {
- get => this._optionalTags.ToArray();
- set => this._optionalTags = new List<string>(value);
- }
- [SerializeIgnore]
- public ContentUseage[] TagUseage {
- get {
- List<ContentUseage> res = new List<ContentUseage>();
- for(ushort i=0;i<this._tags.Count;i++) {
- ContentUseage cu = new ContentUseage(i, this._tags[i]);
- foreach(ContentEntry ce in this.Entries) {
- if(ce.Tag_Has(i)) {
- cu.Count++;
- }
- }
- res.Add(cu);
- }
- return res.ToArray();
- }
- }
- [SerializeIgnore]
- public ContentUseage[] OptionalTagUseage {
- get {
- List<ContentUseage> res = new List<ContentUseage>();
- 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;i<c;i++)
- if(entry.OptionalTags[i]>tag_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();
- }
- }
- }
|