コード例 #1
0
ファイル: Backer.cs プロジェクト: bazer/Modl
 public Backer(Type modlType)
 {
     ModlType    = modlType;
     Definitions = Definitions.Get(modlType);
     SetDefaultValues();
     //Id = Identity.FromTemporaryId(Guid.NewGuid(), this);
 }
コード例 #2
0
 //-----DICTIONARY-----
 private void button5_Click(object sender, EventArgs e)
 {
     comboBox3.Visible = false;                             // hides comboBox3 (used in the case if there is more than one result of a given search
     comboBox3.Items.Clear();                               // clears comboBox3's previous items
     wordId = textBox1.Text;                                // gets the word from textBox1
     wordId = SearchWord.GetCorrectWord(wordId, region);    // calls the GetCorretWord method from the class SearchWord to serach the user's word
     if (wordId != textBox1.Text)                           // checks if the returned word doesn't match textBox1
     {
         wordPrev = textBox1.Text;                          // sets word_prev to match textBox1
         return;                                            // ends the method
     }
     textBox1.Text     = wordId;                            // sets textBox1 to match word_id
     wordType          = comboBox1.Text.ToLower();          // gets the type from comboBox1 and makes it lowercase
     dictionary_Result = Definitions.Get(wordType, wordId); // calls the get method from the Definitions class to get the definition of the user's word
     richTextBox1.Text = dictionary_Result;                 // prints out the result in richTextBox1
 }
コード例 #3
0
        public string Generate(Test test)
        {
            List <string>          exercises      = new List <string>();
            List <string>          answers        = new List <string>();
            ConcurrentBag <string> bagOfAnswers   = new ConcurrentBag <string>();
            ConcurrentBag <string> bagOfExercises = new ConcurrentBag <string>(); // used when using multiple threads

            TestGeneratorForm.fr.progressBar1.Visible = true;
            TestGeneratorForm.fr.progressBar1.Value   = 0;
            TestGeneratorForm.fr.progressBar1.Maximum = TestGeneratorForm.fr.richTextBox2.Text.Split(new string[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries).Length;
            Dictionary <string, string> buffer = new Dictionary <string, string>();
            Random rndm = new Random();

            test.Result = ""; // reset the result property to prevent "stacking" of tests
            string suggestedAnswerKey = "";
            int    n = 1;

            while (n <= test.ExcerciseAmount && test.WordsAndTypes.Count > 0)
            {
                int    randomExercise = rndm.Next(0, test.WordsAndTypes.Count - 1);
                string key            = test.WordsAndTypes.ElementAt(randomExercise).Key;
                string value          = test.WordsAndTypes[key];
                KeyValuePair <string, string> pair = new KeyValuePair <string, string>(key, value);
                if (!Utility.IsValidEntry(pair, test.Type))
                {
                    test.WordsAndTypes.Remove(key);
                    continue;
                }
                buffer.Add(key, test.WordsAndTypes[key]);
                test.WordsAndTypes.Remove(key);
                n++;
            }
            test.WordsAndTypes = buffer;
            switch (TestGeneratorForm.generatingSpeed)
            {
            case "Normal":
                foreach (KeyValuePair <string, string> entry in test.WordsAndTypes)
                {
                    TestGeneratorForm.fr.progressBar1.Value++;
                    switch (test.Type)
                    {
                    case "Definitions":
                        exercises.Add(Read(Definitions.Get(entry.Value, entry.Key)));
                        answers.Add(entry.Key);
                        break;

                    case "Examples":
                        exercises.Add(Regex.Replace(Read(Examples.Get(entry.Value, entry.Key)), entry.Key, new string('_', entry.Key.Length), RegexOptions.IgnoreCase));
                        answers.Add(entry.Key);
                        break;

                    case "Words":
                        exercises.Add(entry.Key + new string('.', 50) + " (" + entry.Value.TrimEnd() + ")");
                        break;

                    case "Multi-Choices":
                        char answer = 'A';         // stores the correct answer for each exercise
                        exercises.Add(Regex.Replace(Read(Examples.Get(entry.Value, entry.Key)), entry.Key, new string('_', entry.Key.Length), RegexOptions.IgnoreCase) + "\n" + Synonyms.Request(entry.Key, out answer));
                        answers.Add(answer.ToString());
                        break;
                    }
                }
                break;

            case "Fast":
                System.Threading.Tasks.Parallel.ForEach(test.WordsAndTypes, entry =>
                {
                    switch (test.Type)
                    {
                    case "Definitions":
                        bagOfExercises.Add(Read(Definitions.Get(entry.Value, entry.Key)));
                        bagOfAnswers.Add(entry.Key);
                        break;

                    case "Examples":
                        bagOfExercises.Add(Regex.Replace(Read(Examples.Get(entry.Value, entry.Key)), entry.Key, new string('_', entry.Key.Length), RegexOptions.IgnoreCase));
                        bagOfAnswers.Add(entry.Key);
                        break;

                    case "Words":
                        bagOfExercises.Add(entry.Key + new string('.', 50) + " (" + entry.Value.TrimEnd() + ")");
                        break;

                    case "Multi-Choices":
                        char answer = 'A';         // stores the correct answer for each exercise
                        bagOfExercises.Add(Regex.Replace(Read(Examples.Get(entry.Value, entry.Key)), entry.Key, new string('_', entry.Key.Length), RegexOptions.IgnoreCase) + "\n" + Synonyms.Request(entry.Key, out answer));
                        bagOfAnswers.Add(answer.ToString());
                        break;
                    }
                });
                exercises = bagOfExercises.ToList();     // Converts the bagOfExercises variable to List and sets it to exercises variable
                answers   = bagOfAnswers.ToList();
                break;
            }
            foreach (var exercise in exercises.ToList())
            {
                if ((exercise.Contains("Couldn't find ") && (exercise.Contains("NotFound") || exercise.Contains("ERROR")) && answers.Any()) ||
                    (!(exercise.Contains("_")) && answers.Any() && (test.Type == "Examples" ||
                                                                    test.Type == "Multi-Choices"))) // remove all of the words that were not found in the Oxford Dictionary
                {
                    answers.RemoveAt(exercises.IndexOf(exercise));
                    exercises.Remove(exercise);
                }
            }
            if (exercises.Count - test.ExcerciseAmount < 0) // if there are not enough words to make a test, lower the exercise amount
            {
                test.ExcerciseAmount -= (test.ExcerciseAmount - exercises.Count);
            }
            test.Result        += "~~~~~" + test.Name + "~~~~~\n";
            suggestedAnswerKey += (answers.Any()) ? "~~~~~ Suggested Answer Key ~~~~~\n" : string.Empty;
            string answerKey = "";

            n = 1;
            while (n <= test.ExcerciseAmount)
            {
                int randomExercise = rndm.Next(0, exercises.Count);
                test.Result        += "------------------[Ex. " + n + "]------------------\n" + exercises[randomExercise] + "\n";
                suggestedAnswerKey += (answers.Any()) ? "[Ex. " + n + "] - " + answers[randomExercise] + "\n" : string.Empty;
                exercises.RemoveAt(randomExercise);
                if (answers.Any())
                {
                    if (test.Type == "Multi-Choices")
                    {
                        answerKey += n.ToString() + "-" + answers[randomExercise] + "\n";
                        AnswerSheet.Generate(test.Name, test.ExcerciseAmount, 1, 4, answerKey);
                    }
                    answers.RemoveAt(randomExercise);
                }
                n++;
            }
            test.Result += "\n" + suggestedAnswerKey;
            TestGeneratorForm.fr.progressBar1.Visible = false;
            return(test.Result);
        }
コード例 #4
0
 public PacketProcessor(string apiKey)
 {
     _definitions = Definitions.Get();
     _uploader    = new UniversalisMarketBoardUploader(this, apiKey);
 }