/// <summary> /// Inicializa o WordManager, escolhendo uma nova palavra e instanciando as letras na interface /// </summary> public void Initialize() { Word = WordLoader.GetRandomWord(); Debug.Log("A palavra selecionada foi " + Word); if (letters == null) { letters = new List <Letter>(); } else { letters.Clear(); } if (wordHolder.childCount > 0) { foreach (Transform child in wordHolder) { Destroy(child.gameObject); } } for (int i = 0; i < Word.Length; i++) { Letter letter = GetLetter(Word[i]); GameObject letterGO = Instantiate(letterPrefab, wordHolder) as GameObject; TextMeshProUGUI letterText = letterGO.GetComponent <TextMeshProUGUI>(); letter.AddPosition(letterText); } }
protected async Task ProcessRecordAsync() { try { List <Word> wordList = new List <Word>(); IEnumerable <string> sourceWords; IWordLoader wordLoader = new WordLoader(); IWordTranslator wordTranslator = new WordTranslator(); // Load word list from file WriteObject("Load word from the word file."); string fileType = _path.Substring(_path.LastIndexOf('.') + 1); if (fileType == "txt") { sourceWords = await wordLoader.LoadWordFromFileAsync(_path); } else if (fileType == "xlsx") { sourceWords = wordLoader.LoadWordFromExcelAsync(_path); } else { throw new Exception($"{_path} is type invalid), Supported type includes xlsx, txt."); } var sortedSourceWord = from word in sourceWords orderby word ascending select word; // Translate word WriteObject("Translate word..."); foreach (string word in sortedSourceWord) { wordList.Add(await wordTranslator.TranslateAsync(word)); } wordList.ForEach(item => item.LocalAudio = _storageFolder + $"\\audio\\" + item.EnglishLanguage + ".mp3"); // Storage translated result to file. await wordLoader.StorageTranslatedWordAsync(wordList, Split, _storageFolder, Name); // Storage transfated result to excel file. if (IsExcel) { await wordLoader.StorageTranslatedWordToExcelAsync(wordList, Split, _storageFolder + $@"\{Name}.xlsx", Name); } // Get andt storge mp3 file. if (IsAudio) { WriteObject("Download mp3 file from web site."); foreach (var item in wordList) { await wordLoader.GetWordMp3FileAsync(item); } } WriteObject("Translated end"); } catch { throw; } }
public void Load_MixOfWords_FindsOnlyValidWordItemsSeparateByWhitespace() { List <string> words = new List <string>(); WordLoader.Load(" a bc def ghij abcdefghijklmnopqr klmno\tpqrstu\rvwxy\nz ", w => words.Add(w.ToString())); Assert.Equal(new string[] { "A", "BC", "DEF", "GHIJ", "KLMNO", "PQRSTU", "VWXY", "Z" }, words.ToArray()); }
public void Load_TooLong_DoesNothing() { int count = 0; WordLoader.Load("abcdefghijklmnoqrstuvwxyz", w => ++ count); Assert.Equal(0, count); }
public void Load_EmptyString_DoesNothing() { int count = 0; WordLoader.Load(string.Empty, w => ++ count); Assert.Equal(0, count); }
private void Awake() { _wordLoader = GetComponent <WordLoader>(); GlobalVariables.EnemyManager = this; Assert.IsNotNull(_wordLoader); }
public void GetWords_InvalidUrl_ReturnsEmptyList() { var url = @"http://fakesite.com/wordlist.txt"; IWordLoader loader = new WordLoader(url); var words = loader.GetWordsFromUrl(); Assert.That(words, Is.Empty); }
public void GetWords_ReturnsWordsFromUrl() { var url = @"http://dl.dropboxusercontent.com/u/7543760/wordlist.txt"; IWordLoader loader = new WordLoader(url); var words = loader.GetWordsFromUrl(); Assert.That(words, Is.Not.Empty); Assert.That(words.Contains("bor")); Assert.That(words.Contains("walla's")); }
private void Awake() { enemyManager = GetComponentInParent <EnemyManager>(); wordLoader = GetComponentInParent <WordLoader>(); _audioManager = GetComponentInParent <AudioManager>(); _enemyMovement = GetComponent <EnemyMovement>(); text = canvasPanel.GetComponentInChildren <TextMeshProUGUI>(); Assert.IsNotNull(_audioManager, "The Enemy don't seem to have a AudioManager"); Assert.IsNotNull(healthBar, "The Enemy don't seem to have a HealthBar"); Assert.IsNotNull(canvasPanel, "The Enemy must have a Canvas Panel reference"); Assert.IsNotNull(text, "The Enemy must have a Canvas Text reference"); Assert.IsNotNull(enemyManager, "The Enemy must have an EnemyManager reference"); Assert.IsNotNull(wordLoader, "The Enemy must have an WordLoader reference"); }
static async Task Main(string[] args) { //string subFolder = "level4-05"; IWordLoader wordLoader = new WordLoader(); IWordTranslator wordTranslator = new WordTranslator(); List <Word> wordList = new List <Word>(); string storageFolder = @"D:\Lucas\EnglishVocabulary\level4"; IEnumerable <string> engWordTemplate = wordLoader.LoadWordFromExcelAsync(@"C:\Users\v-diya\Desktop\EnglishLevel4.xlsx");//(await wordLoader.LoadWordFromFileAsync(@$"D:\Lucas\git\EnglishVocabulary\resources\Level4Vocabulary\{subFolder}.txt")).ToList(); var engWord = from word in engWordTemplate orderby word ascending select word; //int skipDebug = 0; foreach (string word in engWord) { //if (skipDebug > 57) break; wordList.Add(await wordTranslator.TranslateAsync(word)); //skipDebug++; } wordList.ForEach(item => item.LocalAudio = storageFolder + $"\\audio\\" + item.EnglishLanguage + ".mp3"); await wordLoader.StorageTranslatedWordAsync(wordList, 100, storageFolder, "level4"); await wordLoader.StorageTranslatedWordToExcelAsync(wordList, 100, storageFolder + @"\level4.xlsx", "level4"); try { foreach (var item in wordList) { await wordLoader.GetWordMp3FileAsync(item); } } catch (HttpRequestException ex) { Console.WriteLine(ex.Message); } Console.ReadKey(); }
public override List <ProbableMove> Probables() { var Moves = new List <ProbableMove>(); if (!new FileInfo(file).Exists) { return(Moves); } if (CharSet == null || cells == null || weights == null || string.IsNullOrEmpty(file) || (string.IsNullOrEmpty(vowels) && string.IsNullOrEmpty(conso) && string.IsNullOrEmpty(special))) { return(Moves); } if (cells.Length != size * size || weights.Length != size * size) { return(Moves); } string[] All = new string[] { }; string AllPattern = ""; string Movables = (vowels + " " + conso + " " + special); var MovableList = Movables.Replace("(", " ").Replace(")", " ").Replace(",", "").Split(' ').ToList(); MovableList.RemoveAll(x => x.Length == 0); var SpecialList = DistinctList(special.Replace("(", " ").Replace(")", " ").Replace(",", ""), ' '); var SpeicalDict = GetSpecialDict(SpecialList); List <string> EverySyllableOnBoard = GetSyllableList(cells, size, true, false, true); // All = (GetFlatList(EverySyllableOnBoard, ',') + " " + Movables).Replace("(", " ").Replace(")", " ").Replace(",", " ").Replace("|", " ").Split(' '); AllPattern = string.Format("^(?<All>[{0},])*$", GetFlatList2(All)); Dictionary <string, int> AllDict = GetCountDict(All); var WordsDictionary = WordLoader.Load(file); //Large Set of Words var ContextualList = new List <int>() { }; if (CL) { ContextualList = ShortList(WordsDictionary, AllPattern, AllDict); // Probables if (ContextualList.Count > WordsDictionary.Count * Threshlod) { CL = false; } } if (EverySyllableOnBoard.Count > 0) { { var NonCornerSyllables = GetSyllableList(cells, size, false, true, false); var NonCornerPattern = ""; var NonCornerTiles = new string[] { }; var NonCornerDict = new Dictionary <string, int>(); // NonCornerTiles = (GetFlatList2(NonCornerSyllables.ToArray()) + " " + Movables).Replace("(", " ").Replace(")", " ").Replace(",", " ").Replace("|", " ").Split(' '); NonCornerPattern = string.Format("^(?<All>[{0},])*$", GetFlatList2(NonCornerTiles)); NonCornerDict = GetCountDict(NonCornerTiles); // var NonCornerProbables = new List <int>() { }; if (CL) { NonCornerProbables = ShortList(WordsDictionary, ContextualList, NonCornerPattern, NonCornerDict); //Non Corner Probables } else { NonCornerProbables = this.ShortList(WordsDictionary, NonCornerPattern, NonCornerDict); } Moves.AddRange(SyllableExtensions(cells, size, CharSet, id, WordsDictionary, NonCornerProbables, MovableList, SpeicalDict)); } { var CornerSyllables = GetSyllableList(cells, size, false, true, false); var CornerPattern = ""; var CornerTiles = new string[] { }; var CornerDict = new Dictionary <string, int>(); // CornerTiles = (GetFlatList2(CornerSyllables.ToArray()) + " " + Movables).Replace("(", " ").Replace(")", " ").Replace(",", " ").Replace("|", " ").Split(' '); CornerPattern = string.Format("^(?<All>[{0},])*$", GetFlatList2(CornerTiles)); CornerDict = GetCountDict(CornerTiles); // var CornerProbables = new List <int>() { }; if (CL) { CornerProbables = ShortList(WordsDictionary, ContextualList, CornerPattern, CornerDict); //Corner Probables } else { CornerProbables = this.ShortList(WordsDictionary, CornerPattern, CornerDict); } Moves.AddRange(WordExtensions(cells, size, CharSet, id, WordsDictionary, CornerProbables, MovableList, SpeicalDict)); } } else { Moves.AddRange(EmptyExtensions(cells, size, CharSet, star, id, WordsDictionary, ContextualList, MovableList, SpeicalDict)); } WordsDictionary = null; WordsDictionary = null; RefreshScores(Moves, weights, tileWeights, size); return(Moves); }