| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326 |
- using System;
- using System.Collections.Generic;
- using System.Text;
- 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>();
-
- /*[System.Fire.Serialize.Annotations.SerializeIgnore()]
- public int Count {
- get => this._entries.Count;
- }*/
- 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.HasTags(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.HasTags(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('|', 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('|', 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(this.GetMood(Category));
- }
- public string getText(string Category, ushort tag) {
- return this.getText(this.GetMood(Category), tag);
- }
- public string getText(string Category, ushort[] tags) {
- return this.getText(this.GetMood(Category), tags);
- }
-
- protected eMood GetMood(string Category) {
- eMood m = eMood.None;
- string[] x = Category.Split('|');
- foreach (string y in x) {
- switch (Category.ToLower().Trim()) {
- 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 "compfortable":
- m |= eMood.compfortable;
- break;
- case "depressive":
- m |= eMood.depressive;
- break;
- case "energy":
- m |= eMood.energy;
- break;
- case "excited":
- m |= eMood.excited;
- break;
- case "exhausted":
- m |= eMood.exhausted;
- break;
- case "freezy":
- m |= eMood.freezy;
- break;
- case "funny":
- m |= eMood.funny;
- break;
- case "happyness":
- m |= eMood.happyness;
- break;
- case "hot":
- m |= eMood.hot;
- break;
- case "humanity":
- m |= eMood.humanity;
- break;
- case "hungry":
- m |= eMood.hungry;
- break;
- case "intelligent":
- m |= eMood.intelligent;
- break;
- case "irritated":
- m |= eMood.irritated;
- break;
- case "lonely":
- m |= eMood.lonely;
- break;
- case "naiv":
- m |= eMood.naiv;
- break;
- case "playful":
- m |= eMood.playful;
- break;
- case "sad":
- m |= eMood.sad;
- break;
- case "shy":
- m |= eMood.shy;
- break;
- case "sleepy":
- case "sleep":
- m |= eMood.sleepy;
- break;
- case "soziality":
- case "sozial":
- m |= eMood.soziality;
- break;
- case "temperate":
- m |= eMood.temperate;
- break;
- case "toLoud":
- m |= eMood.toLoud;
- break;
- case "toQuiet":
- m |= eMood.toQuiet;
- break;
- case "usefull":
- m |= eMood.usefull;
- break;
- 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(string Text, string Mood, ushort[] Tags) {
- string lText = Text.ToLower().Trim();
- foreach (ContentEntry ce in this.Entries) {
- if (ce.Text.ToLower() == lText) {
- ce.Mood = this.GetMood(Mood);
- ce.Tags = Tags;
- return true;
- }
- }
- this.Entries.Add(new ContentEntry(Text.Trim(), this.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 = this.GetMood(Mood);
- return true;
- }
- }
- this.Entries.Add(new ContentEntry(Text.Trim(), this.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);
- }
- /*public List<ContentEntry> Entries {
- get {
- return this._entries;
- }
- set {
- if (value != null)
- this._entries = value;
- }
- }*/
- }
- }
|