public static FreqWord[] GetArrayCut(FreqWord[] originalArray, int cutSize) { FreqWord[] arrayCut = new FreqWord[cutSize]; for (int i = 0; i < cutSize; i++) { arrayCut[i] = originalArray[i]; } return(arrayCut); }
// public List <string>[] GetInWordWithLetterFormat(List <WordLine>[] listsForLevels) { List <string>[] wordLists = new List <string> [maxLevels]; // Tantas listas como niveles for (int i = 0; i < listsForLevels.Length; i++) { // Tantas palabras como toquen por nivel wordLists[i] = new List <string>(wordsPerLevel); for (int j = 0; j < wordsPerLevel; j++) { WordLine nextWord = listsForLevels[i][j]; FreqWord newFreqWord = new FreqWord(nextWord.Word, nextWord.charLetter); wordLists[i].Add(nextWord.Word + nextWord.charLetter); } } return(wordLists); }
public static FreqWord[] GetWordsWithFreqJson(string jsonName, int maxWords = 0) { FreqWord[] textToReturn = new FreqWord[1]; string text = System.IO.File.ReadAllText("Assets/Resources/" + jsonName + ".json"); FreqWordsObject freqWordsObject = JsonUtility.FromJson <FreqWordsObject>(text); //textToReturn = JsonUtility.FromJson<string[]>(text); textToReturn = freqWordsObject.entries; Debug.Log(freqWordsObject); if (maxWords > 0) { FreqWord[] textToReturnAdjusted = new FreqWord[maxWords]; for (int i = 0; i < maxWords; i++) { textToReturnAdjusted[i] = new FreqWord(); textToReturnAdjusted[i] = textToReturn[i]; } textToReturn = textToReturnAdjusted; } return(textToReturn); }
// TODO: Revisar importación de eÑes public static FreqWord[] GetWordsAndFreqsJson(int maxWords = 0, string lettersToUse = "") { // FreqWord[] wordObjectsToReturn = new FreqWord[1]; int mainListIndex = 0; // string words = System.IO.File.ReadAllText("Assets/Resources/palabras.json"); TextObject wordsObject = JsonUtility.FromJson <TextObject>(words); // string freqs = System.IO.File.ReadAllText("Assets/Resources/frecuencias.json"); TextObject freqsObject = JsonUtility.FromJson <TextObject>(freqs); // if (maxWords > 0) { wordObjectsToReturn = new FreqWord[maxWords]; } else { wordObjectsToReturn = new FreqWord[wordsObject.entries.Length]; } // wordObjectsToReturn = new FreqWord[maxWords]; for (int i = 0; i < wordObjectsToReturn.Length; i++) { // if (!lettersToUse.Equals("")) { bool found = false; while (!found) { int j; for (j = 0; j < lettersToUse.Length; j++) { // TODO: Revisar mayus/minusculas if (wordsObject.entries[mainListIndex].Contains(lettersToUse[j].ToString()) && wordsObject.entries[mainListIndex].Length > 1) { found = true; break; } } // wordObjectsToReturn[i] = new FreqWord(); wordObjectsToReturn[i].word = wordsObject.entries[mainListIndex]; wordObjectsToReturn[i].frequency = freqsObject.entries[mainListIndex]; // REVISAR ESTO if (j < lettersToUse.Length) { wordObjectsToReturn[i].keyLetter = lettersToUse[j]; } // mainListIndex++; if (mainListIndex >= wordsObject.entries.Length) { Debug.Log("Limit reached at " + i + " words"); wordObjectsToReturn = GetArrayCut(wordObjectsToReturn, mainListIndex - 1); return(wordObjectsToReturn); } } } else { // wordObjectsToReturn[i] = new FreqWord(); wordObjectsToReturn[i].word = wordsObject.entries[i]; wordObjectsToReturn[i].frequency = freqsObject.entries[i]; } } return(wordObjectsToReturn); }