/// <summary> /// Gets a word and EmotionIdeal associated with it. This assumes that /// the database contains the word! /// </summary> /// <param name="word">Word to search for</param> /// <returns>WordAndEmoIdeal -- struct containing string and emotion ideal</returns> private IEnumerator GetWord(string word, WVObject <WordAndEmoIdeal> result) { Debug.Log("Getting word " + word + " from db"); //WVObject<WordAndEmoIdeal> result = new WVObject<WordAndEmoIdeal>(word); WVObjectList_WordAndEmoIdeal.Add(result); WordAndEmoIdeal wordEmoIdeal = new WordAndEmoIdeal(); using (MySqlCommand command = _connection.CreateCommand()) { command.CommandText = "SELECT " + TABLE_WORD + ", " + TABLE_EMO_IDEAL + " FROM " + TABLE_NAME + " WHERE " + TABLE_WORD + " = " + "'" + word + "'"; System.IAsyncResult asyncResult = command.BeginExecuteReader(System.Data.CommandBehavior.CloseConnection); Debug.Log("Connection before command: " + Connection.State.ToString()); while (!asyncResult.IsCompleted) { yield return(null); } try { MySqlDataReader data; using (data = command.EndExecuteReader(asyncResult)) { //Debug.LogWarning("before data.Read()"); while (data.Read()) { string w = (string)data[TABLE_WORD]; EmotionModel.EmotionIdeal emoIdeal = (EmotionModel.EmotionIdeal) System.Enum.Parse(typeof(EmotionModel.EmotionIdeal), data[TABLE_EMO_IDEAL].ToString()); wordEmoIdeal.word = w; wordEmoIdeal.emoEnum = emoIdeal; result.value = wordEmoIdeal;//at this point, since it's not null, we set it! //Debug.LogWarning("reading data"); } Debug.LogWarning("Data.isClosed = " + data.IsClosed.ToString()); //if (!data.IsClosed) data.Close(); } //Debug.LogWarning("Data.isClosed AFTER using: " + data.IsClosed.ToString()); //Debug.Log("Connection after everything: " + Connection.State.ToString()); } catch (System.InvalidOperationException e) { Debug.LogError(e.StackTrace); Debug.LogError(e.Message); Debug.Log(Connection.State); } } }
/// <summary> /// Given a word, we want to add the word and the synonyms to the dictionary (given /// that it's a valid word) and save it. Then we want to pass the word off /// to the controller that will convert it into a list of EmotionIdeals. /// </summary> /// <param name="word">The word with its synonyms. Note this word could be garbage!</param> /// <returns></returns> private static Word CallMeWhenDonePingingServer(Word word) { Debug.Log("New synonym done pinging server for word: " + word.GetWord()); string wordStr = word.GetWord(); if (word.IsGarbage()) { Debug.Log("word '" + word.GetWord() + "' thrown away, since it's garbage"); return(word); } //TO-DO: Now that we have the filled word, we need to get the EmotionIdeal it represents! List <EmotionModel.EmotionIdeal> emoIdealList = new List <EmotionModel.EmotionIdeal>(); EmotionModel.EmotionIdeal emotionIdeal = Emotions.GetEmotionIdealAssociated(word.GetWord()); if (emotionIdeal != EmotionModel.EmotionIdeal.None) { emoIdealList.Add(emotionIdeal); } foreach (string synonym in word.GetSynonyms()) { emotionIdeal = Emotions.GetEmotionIdealAssociated(synonym); if (emotionIdeal != EmotionModel.EmotionIdeal.None) { emoIdealList.Add(emotionIdeal); } } if (emoIdealList.Count > 0) { //pick a random emotion ideal in the list int randIndex = Random.Range(0, emoIdealList.Count - 1); emotionIdeal = emoIdealList[randIndex]; //And then have it affect the emotional model MySQLDictionary.AddEntry(wordStr, emotionIdeal); EmotionModel.ChangeStateByAddingEmotions(emotionIdeal); } else { Debug.Log("Word: " + word.GetWord() + " : has no associated emotion ideal"); } ////add the new word to the dictionary //SynonymDictionary.Add(word.GetWord(), word.GetSynonyms()); // ////If we should save, do it //if (Time.time - SynonymDictionary.LastSave > SynonymDictionary.MIN_TIME_BETWEEN_SAVES) //{ // SynonymDictionary.SaveSynonymDictionary(); //} return(word); }
public static void AddEntry(string word, EmotionModel.EmotionIdeal emotionIdeal) { //We create the WVObject, and pass it to the coroutine WVObject <bool?> result = new WVObject <bool?>(word); Request newRequest = new Request(); newRequest.type = RequestType.Add; newRequest.word = word; newRequest.emotionIdeal = emotionIdeal; newRequest.boolResult = result; Instance.RequestQueue.Enqueue(newRequest); }
/// <summary> /// Raw write-to function for adding a string and EmotionIdeal to the database. /// This assumes that word is not too long (> 30 chars). /// </summary> /// <param name="word">The string to enter as the word</param> /// <param name="emotionIdeal">The emotion ideal to associate with word</param> private IEnumerator AddEntryToDatabase(string word, EmotionModel.EmotionIdeal emotionIdeal, WVObject <bool?> result) { Debug.Log("Adding entry " + word + " to db"); using (MySqlCommand command = _connection.CreateCommand()) { command.CommandText = "INSERT INTO " + TABLE_NAME + "(" + TABLE_WORD + ", " + TABLE_EMO_IDEAL + ")" + " VALUES" + "('" + word + "', " + "'" + ((int)emotionIdeal).ToString() + "');"; System.IAsyncResult asyncResult = command.BeginExecuteNonQuery(); while (!asyncResult.IsCompleted) { yield return(null); } command.EndExecuteNonQuery(asyncResult); result.value = true; } }
public static EmotionModel.EmotionIdeal ProcessWordEmotionsAndAddToModel(string word) { EmotionModel.EmotionIdeal result = Emotions.GetEmotionIdealAssociated(word); return(result); }
public WordAndEmoIdeal() { word = ""; emoEnum = EmotionModel.EmotionIdeal.None; }
public WordAndEmoIdeal(string w, EmotionModel.EmotionIdeal e) { word = w; emoEnum = e; }