public WordsList GetRandomWord(string GameType)
        {
            int       recmaxcount = 100; // this need to assign from database.
            WordsList word        = new WordsList();
            Random    rand        = new Random();
            int       toSkip      = rand.Next(0, recmaxcount);

            using (SIMSGamesEntities context = new SIMSGamesEntities())
            {
                context.Configuration.LazyLoadingEnabled   = false;
                context.Configuration.ProxyCreationEnabled = false;
                word = (from u in context.WordsLists
                        select u).OrderBy(x => x.WordString).Skip(toSkip).Take(1).FirstOrDefault();
            }

            //If the words list is empty then it will return null object.
            if (word == null)
            {
                return(null);
            }

            if (GameType == "J") // for getting Jambuled word.
            {
                word.WordStringChar = JumbleWord(word.WordString);
            }
            else if (GameType == "M") // it will return the word with Missing letters.
            {
                word.WordStringChar = MissingLetters(word.WordString);
            }

            word.WordString     = word.WordString.ToUpper();
            word.WordStringChar = word.WordStringChar.ToUpper();

            return(word);
        }
        public void Load()
        {
            string[] lines = File.ReadAllLines(PathToWordsFile);
            if (lines.Length == 0)
            {
                throw new IOException("Empty file");
            }
            int currentLineNumber = 1;

            try
            {
                foreach (string line in lines)
                {
                    string[] columns        = line.Split(',');
                    string   original       = columns[0];
                    string   translation    = columns[1];
                    string   note           = columns.Length > 2 ? columns[2] : "";
                    uint     correctCount   = columns.Length > 3 ? uint.Parse(columns[3]) : 0;
                    uint     incorrectCount = columns.Length > 4 ? uint.Parse(columns[4]) : 0;
                    WordsList.Add(new Word(original, translation, note, correctCount, incorrectCount));
                    currentLineNumber++;
                }
            }
            catch (Exception)
            {
                throw new FormatException("Bad input file format on line " + currentLineNumber);
            }
        }
        public Word GetNext()
        {
            Word word;

            if (WordsList.Count > 1)
            {
                do
                {
                    double chance = new Random().NextDouble();
                    if (chance < .1)
                    {
                        word = GetRandomWord(WordsList.ToArray());
                    }
                    else if (chance < .2)
                    {
                        word = GetRandomWord(GetLeastShowedWords());
                    }
                    else
                    {
                        word = GetRandomWord(GetLeastAnsweredCorrectlyWords(.7));
                    }
                } while (LastShowedWord == word);
            }
            else
            {
                word = WordsList[0];
            }
            LastShowedWord = word;
            return(word);
        }
        private void OnSelectedIndexChanged()
        {
            if (SelectedItem == null)
            {
                return;
            }

            var wordsRead = (SelectedIndex * _settingsService.WordsAtATime);

            SelectedItem.WordsRead = wordsRead + _settingsService.WordsAtATime;
            if (!WordsList.IsNullOrEmpty())
            {
                DisplayWords = WordsList[SelectedIndex];

                if (SelectedIndex == WordsList.Count - 1)
                {
                    IsPaused = true;
                    StartStopTimer();
                    Done();
                    return;
                }

                ShowFinishedScreen = false;
            }
        }
Beispiel #5
0
    private void HandleGetCustomWords(WordsList wordList, string customData)
    {
        if (!string.IsNullOrEmpty(customData))
        {
            Log.Debug("ExampleSpeechToText", "custom data: {0}", customData);
        }

        if (wordList != null)
        {
            if (wordList.words != null && wordList.words.Length > 0)
            {
                foreach (WordData word in wordList.words)
                {
                    Log.Debug("ExampleSpeechToText", "WordData - word: {0} | sounds like: {1} | display as: {2}", word.word, word.sounds_like, word.display_as);
                }
            }
            else
            {
                Log.Debug("ExampleSpeechToText", "No custom words found!");
            }
        }
        else
        {
            Log.Debug("ExampleSpeechToText", "Failed to get custom words!");
        }
    }
Beispiel #6
0
    void LoadWordsData()     //needs to be checked on each platform
    {
        string filePath = "";

                #if UNITY_EDITOR || UNITY_STANDALONE_WIN
        filePath = Path.Combine(Application.streamingAssetsPath, dataFileName);
                #elif UNITY_ANDROID
        filePath = Path.Combine("jar:file://" + Application.dataPath + "!/assets/", dataFileName);
        WWW www = new WWW(filePath);
        while (!www.isDone)
        {
        }
        wordsList = JsonUtility.FromJson <WordsList>(www.text);
        return;
                #elif Unity_IOS
        filePath Path.Combine(Application.dataPath + "/Raw", dataFileName);
                #endif


        if (File.Exists(filePath))
        {
            string dataAsJSON = File.ReadAllText(filePath);
            wordsList = JsonUtility.FromJson <WordsList>(dataAsJSON);
        }
        else
        {
            Debug.Log("Can't find file with words");
        }
    }
Beispiel #7
0
        //词组个数
        private static Dictionary <string, int> PhraseFre(string path, int n)
        {
            List <string> list = new List <string>();

            //list是符合单词要求单词的集合
            list = WordsList.Judge(path);
            Dictionary <string, int> frequencies = new Dictionary <string, int>(StringComparer.OrdinalIgnoreCase); string s = "";

            //将长度为n的词组当成一个字符串
            for (int i = 0; i <= list.Count - n; i++)
            {
                int j;
                for (s = list[i], j = 0; j < n - 1; j++)
                {
                    s += " " + list[i + j + 1];
                }
                if (frequencies.ContainsKey(s))
                {
                    frequencies[s]++;
                }
                else
                {
                    frequencies[s] = 1;
                }
            }
            return(frequencies);
        }
Beispiel #8
0
    public static void SavedToFile(string FilePath)
    {
        string NewFilePath = Application.dataPath + FilePath;

        if (File.Exists(NewFilePath))
        {
            string        DataAsJson     = File.ReadAllText(NewFilePath);
            WordsList     LoadedWordList = JsonUtility.FromJson <WordsList>(DataAsJson);
            string[]      WordArr        = LoadedWordList.wordlist;
            List <string> NewIsogramList = new List <string>();
            BullsCowsGame BCGame         = new BullsCowsGame();

            for (int LetterIndex = 0; LetterIndex < WordArr.Length; LetterIndex++)
            {
                string CurrentWord = WordArr[LetterIndex];
                if (BCGame.IsIsogram(CurrentWord))
                {
                    NewIsogramList.Add(CurrentWord);
                }
            }

            // after loading and sorting json file, save it into a binary file for future load
            IsogramList SaveFile = new IsogramList();
            SaveFile.IsogramWords = NewIsogramList;
            SaveData.SavingData(SaveFile, "/isogramwordlist.dat");
        }
        else
        {
            Debug.Log("FilePath is Null");
        }
    }
Beispiel #9
0
        public void TestCountWord()
        {
            string        str  = null;
            List <string> list = new List <string>();

            list = WordsList.Judge(str);
            Assert.IsNull(list);
        }
Beispiel #10
0
 public void Add(params string[] translations)
 {
     if (WordsList != null)
     {
         var word = new Word(translations);
         WordsList.Add(word);
     }
 }
Beispiel #11
0
 public static WordsListDTO EntityToDto(this WordsList wordsList)
 {
     return(new WordsListDTO
     {
         Id = wordsList.Id,
         Name = wordsList.Name,
         QuantityWords = wordsList.QuantityWords
     });
 }
Beispiel #12
0
    void Start()
    {
        WordsList list = new WordsList();

        list.Load("words");
        book = new Book(list);

        screenMenu.GetComponent <ScreenMenu>().Show();
    }
Beispiel #13
0
        public void TestCountChar()
        {
            string str   = "Abcd aa!";
            int    count = str.Length;

            Assert.AreEqual(WordsList.CountChar(str), count);
            string str1 = "";

            Assert.AreEqual(WordsList.CountChar(str1), str1.Length);
        }
Beispiel #14
0
        /// <summary>
        ///     Remove the item at selected index.
        /// </summary>
        /// <param name="index">The index of the item to be removed.</param>
        /// <returns>True if item is removed else false.</returns>
        /// <created>art2m,5/19/2019</created>
        /// <changed>art2m,5/19/2019</changed>
        public static bool RemoveItemAt(int index)
        {
            // Get item to be removed for check that it is gone.
            var item = GetItemAt(index);

            WordsList.RemoveAt(index);

            // Check to see if item is no longer in collection
            return(!ContainsItem(item));
        }
Beispiel #15
0
 public static void CreateNewPlayer()
 {
     X    = 0;
     Y    = 0;
     PreX = 0;
     PreY = 0;
     CoordStory.Clear();
     WordNow = string.Empty;
     WordsList.Clear();
     Score = 0;
 }
Beispiel #16
0
        public WordsList ListCustomWords(string customizationId, WordType?wordType, Sort?sort)
        {
            if (string.IsNullOrEmpty(customizationId))
            {
                throw new ArgumentNullException($"{nameof(customizationId)}");
            }

            WordsList result = null;

            try
            {
                var request =
                    this.Client.WithAuthentication(this.UserName, this.Password)
                    .GetAsync($"{this.Endpoint}{PATH_CUSTOM_MODEL}/{customizationId}/words");

                if (wordType.HasValue)
                {
                    request.WithArgument("word_type", wordType.Value.ToString().ToLower());
                }

                if (sort.HasValue)
                {
                    switch (sort.Value)
                    {
                    case Sort.AscendingAlphabetical:
                        request.WithArgument("sort", "+alphabetical");
                        break;

                    case Sort.DescendingAlphabetical:
                        request.WithArgument("sort", "-alphabetical");
                        break;

                    case Sort.AscendingCount:
                        request.WithArgument("sort", "+count");
                        break;

                    case Sort.DescendingCount:
                        request.WithArgument("sort", "-count");
                        break;
                    }
                }

                result =
                    request.As <WordsList>()
                    .Result;
            }
            catch (AggregateException ae)
            {
                throw ae.InnerException as ServiceResponseException;
            }

            return(result);
        }
        public MainWindowViewModel()
        {
            AddLetterCommand = new RelayCommand(AddLetter, CanAdd);
            BestWordCommand  = new RelayCommand(ChoseBestWord);
            ExitCommand      = new RelayCommand(Exit);

            var strExeFilePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
            var path           = System.IO.Path.GetDirectoryName(strExeFilePath) + "\\words.txt";

            _wordsList       = new WordsList(path);
            _selectedLetters = new List <string>();
            LettersMenagment.ClearAndSetEmptyBestWords(ref _bestWords);
        }
Beispiel #18
0
        //

        private async void Main()
        {
            var changed = false;
            var waited  = 0;

            // Only have the possibility to change 'changed' from false to true, never true to false
            PropertyChanged += (sender, args) => changed = args.PropertyName.Equals(nameof(Words));

            while (true)
            {
                switch (_state)
                {
                // On application launch
                case State.Initial:
                    Words  = "";
                    _state = State.Reset;
                    break;

                // Changing from one word to the next
                case State.Switching:
                    Index  = Index + 1 >= WordsList.Count ? 0 : Index + 1;
                    Word   = WordsList.Skip(Index).FirstOrDefault();
                    _state = State.Waiting;
                    break;

                // Waiting for the duration of the delay or for a text change
                case State.Waiting:
                    await Task.Delay(100);

                    waited += 100;

                    if (waited >= SettingsRepository.SecondsDelay * 1000 || changed)
                    {
                        _state = changed ? State.Reset : State.Switching;
                        waited = 0;
                    }

                    break;

                // Reset the state
                case State.Reset:
                    Index     = -1;
                    WordsList = new ObservableCollection <string>(Words.Split(new[] { ", " }, StringSplitOptions.RemoveEmptyEntries));
                    _state    = State.Switching;
                    break;
                }
            }
        }
Beispiel #19
0
        public void Tests()
        {
            var list = new WordsList(new[] {"Pie", "tomato"});
            list.Add("Pieapple");

            var linkedList = new WordsLinkedList(new[] {"Pie", "Tomato"});
            linkedList.AddLast("Pieapple");

            var search1 = new LikeSearcher("Pie");
            list.Browse(search1);
            CollectionAssert.AreEqual(new[] {"Pie", "Pieapple"}, search1.Matches.ToArray());

            var search2 = new LikeSearcher("Pie");
            linkedList.Browse(search2);
            CollectionAssert.AreEqual(new[] { "Pie", "Pieapple" }, search2.Matches.ToArray());
        }
Beispiel #20
0
        //输出前n多的单词数量与其词频
        public static Dictionary <string, int> PutNwords(string path)
        {
            List <string> list = new List <string>();

            list = WordsList.Judge(path);
            Dictionary <string, int> frequencies = new Dictionary <string, int>(StringComparer.OrdinalIgnoreCase);

            foreach (string word in list)
            {
                if (frequencies.ContainsKey(word))
                {
                    frequencies[word]++;
                }
                else
                {
                    frequencies[word] = 1;
                }
            }
            return(frequencies);
        }
Beispiel #21
0
        public void Tests()
        {
            var list = new WordsList(new[] { "Pie", "tomato" });

            list.Add("Pieapple");

            var linkedList = new WordsLinkedList(new[] { "Pie", "Tomato" });

            linkedList.AddLast("Pieapple");

            var search1 = new LikeSearcher("Pie");

            list.Browse(search1);
            CollectionAssert.AreEqual(new[] { "Pie", "Pieapple" }, search1.Matches.ToArray());

            var search2 = new LikeSearcher("Pie");

            linkedList.Browse(search2);
            CollectionAssert.AreEqual(new[] { "Pie", "Pieapple" }, search2.Matches.ToArray());
        }
 public void FillWordLists()
 {
     WordsList.Clear();
     TranslationList.Clear();
     for (; count <= selectedWordsList.Count; count++)
     {
         WordsList.Add(selectedWordsList[count - 1].Word);
         TranslationList.Add(selectedWordsList[count - 1].Translation);
         if (count == edge)
         {
             partOfGame = PartOfGame.TypeWords;
             count++;
             break;
         }
         if (count % 5 == 0 && count != 0 && partOfGame == PartOfGame.MatchWords)
         {
             count++;
             break;
         }
     }
 }
        void HandleSuccessCallback(WordsList response, System.Collections.Generic.Dictionary <string, object> customData)
        {
            if (response != null)
            {
                workspace.CustomWords.Clear();
                foreach (WordData wordData in response.words)
                {
                    LexiconCustomWord customWord = new LexiconCustomWord();
                    customWord.Word           = wordData.word;
                    customWord.DisplayAs      = wordData.display_as;
                    customWord.Pronunciations = string.Join(", ", wordData.sounds_like);

                    workspace.CustomWords.Add(customWord);
                }

                EditorUtility.SetDirty(workspace);
                AssetDatabase.SaveAssets();
            }

            succeeded = true;
            isDone    = true;
        }
Beispiel #24
0
        private void frenchLetters_PressLetterEvent(object sender, FrenchLetters.PressLetterEventArgs letter)
        {
            if (_currentControl == null || string.IsNullOrEmpty(_currentControl.Name))
            {
                bool isNewColumn = WordsList.SelectedCells[0].RowIndex != _rowIndex || WordsList.SelectedCells[0].ColumnIndex != _columnIndex;

                WordsList.BeginEdit(false);

                if (isNewColumn)
                {
                    _cursorPosition      = 0;
                    _currentControl.Text = string.Empty;
                }
            }

            string newText = _currentControl.Text.Substring(0, _cursorPosition) + letter.Text + _currentControl.Text.Substring(_cursorPosition);

            _currentControl.Text = newText;
            _currentControl.Focus();
            ((TextBox)_currentControl).SelectionStart  = _cursorPosition + 1;
            ((TextBox)_currentControl).SelectionLength = 0;
        }
Beispiel #25
0
        public async Task <WordsList> Create(WordCardListInputModel input, UserInfo userInfo)
        {
            if (userInfo == null)
            {
                throw new NotAuthException();
            }

            if (input == null)
            {
                throw new SomeCustomException(ErrorConsts.NotFound);//TODO
            }

            var forAdd = new WordsList()
            {
                Title  = input.Title,
                UserId = userInfo.UserId,
            };

            return(await _wordsListRepository.Add(forAdd));

            //throw new System.NotImplementedException();
        }
 private void HandleGetCustomWords(WordsList wordList, Dictionary <string, object> customData)
 {
     Log.Debug("ExampleSpeechToText.HandleGetCustomWords()", "{0}", customData["json"].ToString());
     _getCustomWordsTested = true;
 }
 /// <summary>
 ///     Remove the specified word.
 /// </summary>
 /// <param name="word"></param>
 /// <returns>true if removed else false.</returns>
 /// <created>art2m,5/19/2019</created>
 /// <changed>art2m,5/19/2019</changed>
 public static bool RemoveItem(string word)
 {
     return(WordsList.Remove(word));
 }
Beispiel #28
0
        static void Main(string[] args)
        {
            int    countLine  = 0;
            string str        = "";
            string path       = "";
            int    phraseNum  = 0;
            int    wordFreNum = 0;

            // 判断输入参数
            for (int i = 0; i < args.Length; i += 2)
            {
                switch (args[i])
                {
                /* -i 参数设定读入文件的路径*/
                case "-i":
                    path = args[i + 1];
                    break;

                /* -m 参数设定的词组长度*/
                case "-m":
                    phraseNum = int.Parse(args[i + 1]);
                    break;

                /* -n 参数设定输出单词数量*/
                case "-n":
                    wordFreNum = int.Parse(args[i + 1]);
                    break;

                /* -o 参数设定生成文件的存储路径*/
                case "-o":
                    break;
                }
            }
            //当文件路径存在时
            if (File.Exists(path))
            {
                StreamReader sr = new StreamReader(path, Encoding.Default);
                string       line;
                while ((line = sr.ReadLine()) != null)
                {
                    countLine++;
                    str += line + "\n";
                }
                sr.Close();
                str = str.Trim();
                //如果含有-o参数 将显示内容输出到文件中
                for (int i = 0; i < args.Length; i++)
                {
                    if (args[i] == "-o")
                    {
                        FileStream   fs = new FileStream(args[i + 1], FileMode.Create);
                        StreamWriter sw = new StreamWriter(fs);
                        sw.WriteLine("Characters:" + WordsList.CountChar(str));
                        sw.WriteLine("Lines: " + countLine);
                        sw.WriteLine("Words:" + WordsList.CountWords(str));
                        //如果有-n参数且有大于零的输入,调用PutNwords函数
                        if (wordFreNum > 0)
                        {
                            sw.WriteLine("输出频率前" + wordFreNum + "的词组:");
                            Dictionary <string, int> item = PutNwords(str).OrderByDescending(r => r.Value).ThenBy(r => r.Key).ToDictionary(r => r.Key, r => r.Value);
                            int size = 0;
                            foreach (KeyValuePair <string, int> entry in item)
                            {
                                string word      = entry.Key;
                                int    frequency = entry.Value;
                                size++;
                                if (size > wordFreNum)
                                {
                                    break;
                                }
                                sw.WriteLine(word + ":" + frequency);
                            }
                        }
                        //如果有-n参数且大于零的输入,则调用phraseNum函数
                        if (phraseNum > 0)
                        {
                            sw.WriteLine("输出长度为" + phraseNum + "的词组:");
                            Dictionary <string, int> item = PhraseFre(str, phraseNum).OrderByDescending(r => r.Value).ThenBy(r => r.Key).ToDictionary(r => r.Key, r => r.Value);
                            foreach (KeyValuePair <string, int> entry in item)
                            {
                                string word      = entry.Key;
                                int    frequency = entry.Value;
                                sw.WriteLine(word + ":" + frequency);
                            }
                        }
                        sw.Flush();//关闭流
                        sw.Close();
                        Console.WriteLine("文件已创建在:" + args[i + 1]);
                    }
                }
            }
            else
            {
                Console.WriteLine("没有文件路径或文件不存在!");
            }
        }
Beispiel #29
0
 /// <summary>
 ///     Get the index of this  item.
 /// </summary>
 /// <param name="word">The item to get the index of.</param>
 /// <returns>the index or else -1.</returns>
 /// <created>art2m,5/19/2019</created>
 /// <changed>art2m,5/19/2019</changed>
 public static int GetItemIndex(string word)
 {
     return(WordsList.IndexOf(word));
 }
Beispiel #30
0
 /// <summary>
 ///     Sort the collection.
 /// </summary>
 /// <created>art2m,5/19/2019</created>
 /// <changed>art2m,5/19/2019</changed>
 public static void SortCollection()
 {
     WordsList.Sort();
 }
Beispiel #31
0
        public void TestJudgeWords()
        {
            string str = null;

            Assert.IsNull(WordsList.Judge(str));
        }