public WordTutorApplication Create() { var alpha = new VocabularyWord("alpha") .WithPhrase("The alpha dog") .WithPronunciation("alfa"); var beta = new VocabularyWord("beta") .WithPhrase("A beta release") .WithPronunciation("beta"); var gamma = new VocabularyWord("gamma") .WithPhrase("Gamma radiation") .WithPronunciation("gamma"); var delta = new VocabularyWord("delta") .WithPhrase("Change is often called delta.") .WithPronunciation("delta"); var vocabulary = VocabularySet.Empty .Add(alpha) .Add(beta) .Add(gamma) .Add(delta); var screen = new VocabularyBrowserScreen() .WithSelection(gamma); var application = new WordTutorApplication(screen) .WithVocabularySet(vocabulary); return(application); }
public void GivenNewWord_ReturnsSetContainingWord() { var word = new VocabularyWord("bumble"); var set = _empty.Add(word); set.Words.Should().Contain(word); }
private bool isVocabularyWordExistsInDB(SqlConnection con, VocabularyWord vocabularyWord) { String sqlSelect = "SELECT Id FROM Vocabulary WHERE Value = ?"; SqlCommand command = new SqlCommand(sqlSelect, con); SqlDataReader reader = command.ExecuteReader(); return(reader.HasRows); }
public SaveModifiedVocabularyWordMessage( VocabularyWord originalWord, VocabularyWord replacementWord) { OriginalWord = originalWord ?? throw new ArgumentNullException(nameof(originalWord)); ReplacementWord = replacementWord ?? throw new ArgumentNullException(nameof(replacementWord)); }
public void GivenSame_ReturnsConsistentValue() { var word = new VocabularyWord(_spelling) .WithPhrase(_phrase) .WithPronunciation(_pronunciation); word.GetHashCode().Should().Be(_word.GetHashCode()); }
public void GivenTransformation_UpdatesPropertyToReturnedValue() { var alpha = new VocabularyWord("alpha"); var set = _app.VocabularySet.Add(alpha); var app = _app.UpdateVocabularySet(_ => set); app.VocabularySet.Should().Be(set); }
public void GivenIdentical_ReturnsTrue() { var other = new VocabularyWord(_spelling) .WithPhrase(_phrase) .WithPronunciation(_pronunciation); _word.Equals(other).Should().BeTrue(); }
public WithVocabularySet() { var alpha = new VocabularyWord("alpha"); var beta = new VocabularyWord("beta"); _set = VocabularySet.Empty .Add(alpha) .Add(beta); }
public void EditWord() { VocabularyWord selected = (VocabularyWord)CurrentController.ListView.SelectedItem.Tag; using (var dialog = new EditWordDialog(CurrentBook, selected) { Owner = this }) dialog.ShowDialog(); CurrentController.ListView.SelectedItem.EnsureVisible(); BtnAddWord.Focus(); }
public void GivenConflictingWord_ThrowsException() { var first = new VocabularyWord("bumble"); var second = new VocabularyWord("bumble").WithPronunciation("boomble"); var set = _empty.Add(first); var exception = Assert.Throws <ArgumentException>( () => set.Add(second)); exception.ParamName.Should().Be("word"); exception.Message.Should().Contain("already exists"); }
public override bool Equals(object obj) { if (!(obj is VocabularyWord)) { return(false); } VocabularyWord that = obj as VocabularyWord; return(this.Word.Equals(that.Word)); }
public EditWordDialog(VocabularyBook book, VocabularyWord word) : base(book) { this.word = word; Icon = Icon.FromHandle(Icons.Edit.GetHicon()); Text = Words.EditWord; GroupOptions.Enabled = true; BtnContinue.Text = Words.Ok; TbMotherTongue.Text = word.MotherTongue; TbForeignLang.Text = word.ForeignLang; TbForeignLangSynonym.Text = word.ForeignLangSynonym ?? ""; }
protected bool BookContainsInput(VocabularyWord exclude) { foreach (VocabularyWord word in book.Words) { if (!ReferenceEquals(word, exclude) && word.MotherTongue == TbMotherTongue.Text && word.ForeignLang == TbForeignLang.Text && (word.ForeignLangSynonym == TbForeignLangSynonym.Text || word.ForeignLangSynonym == null && TbForeignLangSynonym.Text == "")) { return(true); } } return(false); }
public PracticeDialog(VocabularyBook book, List <VocabularyWordPractice> practiceList) { InitializeComponent(); Icon = Icon.FromHandle(Icons.LightningBolt.GetHicon()); evaluator = new Evaluator { OptionalExpressions = Settings.Default.EvaluateOptionalExpressions, TolerateArticle = Settings.Default.EvaluateTolerateArticle, TolerateNoSynonym = Settings.Default.EvaluateTolerateNoSynonym, ToleratePunctuationMark = Settings.Default.EvaluateToleratePunctuationMark, TolerateSpecialChar = Settings.Default.EvaluateTolerateSpecialChar, TolerateWhiteSpace = Settings.Default.EvaluateTolerateWhiteSpace }; player = new SoundPlayer(); this.book = book; this.practiceList = practiceList; index = 0; currentPractice = practiceList[0]; currentWord = currentPractice.VocabularyWord; specialCharDialog = new SpecialCharKeyboard(); specialCharDialog.Initialize(this, BtnSpecialChar); if (Settings.Default.UserEvaluates) { MinimumSize = new Size(MinimumSize.Width, LogicalToDeviceUnits(380)); // All other controls are adjusted by anchor } LbMotherTongue.Text = book.MotherTongue; LbForeignLang.Text = book.ForeignLang; if (book.PracticeMode == PracticeMode.AskForForeignLang) { GroupPractice.Text = string.Format(Words.TranslateFromTo, book.MotherTongue, book.ForeignLang); } else { GroupPractice.Text = string.Format(Words.TranslateFromTo, book.ForeignLang, book.MotherTongue); } }
private void Form_Load(object sender, EventArgs e) { motherTongueColumn.Text = book.MotherTongue; foreignLangColumn.Text = book.ForeignLang; if (practiceList.Count == 1) { GroupStatistics.Text = Words.OverallOneWord + ":"; } else { GroupStatistics.Text = string.Format(Words.OverallXWords, practiceList.Count) + ":"; } ListView.BeginUpdate(); ListView.GridLines = Settings.Default.GridLines; foreach (VocabularyWordPractice practice in practiceList) { VocabularyWord word = practice.VocabularyWord; ListView.Items.Add(new ListViewItem(new[] { "", word.MotherTongue, word.ForeignLangText, practice.WrongInput }, (int)practice.PracticeResult)); } ListView.EndUpdate(); ListView.Enabled = true; //Zahlen aktualiseren IEnumerable <PracticeResult> results = practiceList.Select(x => x.PracticeResult); notPracticed = results.Where(x => x == PracticeResult.NotPracticed).Count(); wrong = results.Where(x => x == PracticeResult.Wrong).Count(); partlyCorrect = results.Where(x => x == PracticeResult.PartlyCorrect).Count(); correct = results.Where(x => x == PracticeResult.Correct).Count(); TbNotPracticedCount.Text = notPracticed.ToString(); TbWrongCount.Text = wrong.ToString(); TbPartlyCorrectCount.Text = partlyCorrect.ToString(); TbCorrectCount.Text = correct.ToString(); CalculateGrade(); }
private void DeleteWord() { int index = CurrentController.ListView.SelectedItem.Index; VocabularyWord selected = (VocabularyWord)CurrentController.ListView.SelectedItem.Tag; CurrentBook.Words.Remove(selected); // Limit index of the deleted word to the highest possible index index = Math.Min(index, CurrentBook.Words.Count - 1); foreach (ListViewItem item in CurrentController.ListView.Items) { if (item.Index == index) { item.Selected = true; } } BtnAddWord.Focus(); }
private double[] getTextAsVectorOfWords(Verse verse) { double[] vector = new double[inputLayerSize]; // convert text to nGramStrategy ISet <String> uniqueValues = nGramStrategy.getNGram(verse.getText()); // create vector // foreach (String word in uniqueValues) { VocabularyWord vw = findWordInVocabulary(word); if (vw != null) { // word found in vocabulary vector[vw.getId() - 1] = 1; } } return(vector); }
private void CopyWord(VocabularyWord word, VocabularyBook target) { VocabularyWord cloned = word.Clone(CbKeepResults.Checked); for (int i = 0; i < target.Words.Count; i++) { VocabularyWord comp = target.Words[i]; if (cloned.MotherTongue == comp.MotherTongue && cloned.ForeignLang == comp.ForeignLang && cloned.ForeignLangSynonym == comp.ForeignLangSynonym) { if (cloned.PracticeDate > comp.PracticeDate) { target.Words[i] = cloned; } return; } } target.Words.Add(cloned); }
public bool Read(VocabularyBook book) { if (string.IsNullOrWhiteSpace(book.VhrCode)) { return(false); } FileInfo vhrInfo = new FileInfo(Path.Combine(Settings.Default.VhrPath, book.VhrCode + ".vhr")); if (!vhrInfo.Exists) { return(false); } string plaintext; try { plaintext = ReadFile(vhrInfo.FullName); } catch (FormatException) { DeleteInvalidFile(vhrInfo); return(false); } catch (System.Security.Cryptography.CryptographicException) { DeleteInvalidFile(vhrInfo); return(false); } using (StringReader reader = new StringReader(plaintext)) { string path = reader.ReadLine(); string mode = reader.ReadLine(); if (string.IsNullOrWhiteSpace(path) || string.IsNullOrWhiteSpace(mode) || !int.TryParse(mode, out int imode) || !((PracticeMode)imode).IsValid()) { DeleteInvalidFile(vhrInfo); return(false); } List <(int stateNumber, DateTime date)> results = new List <(int stateNumber, DateTime date)>(); while (true) { string line = reader.ReadLine(); if (line == null) { break; } string[] columns = line.Split('#'); if (columns.Length != 2 || !int.TryParse(columns[0], out int state) || !PracticeStateHelper.Parse(state).IsValid()) { DeleteInvalidFile(vhrInfo); return(false); } DateTime time = DateTime.MinValue; if (!string.IsNullOrWhiteSpace(columns[1]) && !DateTime.TryParseExact(columns[1], "dd.MM.yyyy HH:mm", CultureInfo.InvariantCulture, DateTimeStyles.None, out time)) { DeleteInvalidFile(vhrInfo); return(false); } results.Add((state, time)); } bool countMatch = book.Words.Count == results.Count; FileInfo vhfInfo = new FileInfo(book.FilePath); FileInfo pathInfo = new FileInfo(path); if (vhfInfo.FullName.Equals(pathInfo.FullName, StringComparison.OrdinalIgnoreCase)) { if (!countMatch) { MessageBox.Show(Messages.VhrInvalidRowCount, Messages.VhrCorruptFileT, MessageBoxButtons.OK, MessageBoxIcon.Warning); try { vhrInfo.Delete(); } catch { } return(false); } } else { if (!countMatch) { MessageBox.Show(Messages.VhrInvalidRowCountAndOtherFile, Messages.VhrCorruptFileT, MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } if (pathInfo.Exists) { book.GenerateVhrCode(); // Save new results file if the old one is in use by another file } book.UnsavedChanges = true; } book.PracticeMode = (PracticeMode)imode; for (int i = 0; i < book.Words.Count; i++) { VocabularyWord word = book.Words[i]; (word.PracticeStateNumber, word.PracticeDate) = results[i]; } } return(true); }
public VocabularyWordTests() { _word = new VocabularyWord(_spelling) .WithPhrase(_phrase) .WithPronunciation(_pronunciation); }
public OpenScreenForModifyingWordMessage(VocabularyWord word) { Word = word; }
public void SetsPronunciationToEmptyString() { var word = new VocabularyWord(_spelling); word.Pronunciation.Should().BeEmpty(); }
public void WithWord_SetsSpellingProperty() { var word = new VocabularyWord(_spelling); word.Spelling.Should().Be(_spelling); }
public void SetsPhraseToEmptyString() { var word = new VocabularyWord(_spelling); word.Phrase.Should().BeEmpty(); }
public SaveNewVocabularyWordMessage(VocabularyWord word) { Word = word ?? throw new ArgumentNullException(nameof(word)); }
public static SaveNewVocabularyWordMessage SaveNewVocabularyWord(VocabularyWord word) => new SaveNewVocabularyWordMessage(word);
public bool Read(string path, VocabularyBook book) { string plaintext; try { plaintext = ReadFile(path); } catch (NotSupportedException) { MessageBox.Show(Messages.VhfMustUpdate, Messages.VhfMustUpdateT, MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } catch (FormatException) { MessageBox.Show(Messages.VhfCorruptFile, Messages.VhfCorruptFileT, MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } catch (System.Security.Cryptography.CryptographicException) { MessageBox.Show(Messages.VhfCorruptFile, Messages.VhfCorruptFileT, MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } using (StringReader reader = new StringReader(plaintext)) { string version = reader.ReadLine(); string vhrCode = reader.ReadLine(); string motherTongue = reader.ReadLine(); string foreignLang = reader.ReadLine(); if (string.IsNullOrWhiteSpace(version) || !Version.TryParse(version, out Version versionObj)) { MessageBox.Show(Messages.VhfInvalidVersion, Messages.VhfCorruptFileT, MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } else if (versionObj.CompareTo(Util.AppInfo.FileVersion) == 1) { MessageBox.Show(Messages.VhfMustUpdate, Messages.VhfMustUpdateT, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(false); } if (vhrCode == null) { MessageBox.Show(Messages.VhfInvalidVhrCode, Messages.VhfCorruptFileT, MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } book.VhrCode = vhrCode; book.FilePath = path; if (string.IsNullOrWhiteSpace(motherTongue) || string.IsNullOrWhiteSpace(foreignLang) || motherTongue == foreignLang) { MessageBox.Show(Messages.VhfInvalidLanguages, Messages.VhfCorruptFileT, MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } book.MotherTongue = motherTongue; book.ForeignLang = foreignLang; while (true) { string line = reader.ReadLine(); if (line == null) { break; } string[] columns = line.Split('#'); if (columns.Length != 3) { MessageBox.Show(Messages.VhfInvalidRow, Messages.VhfCorruptFileT, MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } VocabularyWord word = new VocabularyWord() { Owner = book, MotherTongue = columns[0], ForeignLang = columns[1], ForeignLangSynonym = columns[2] }; book.Words.Add(word); } } return(true); }
private void PrintList_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { Graphics g = e.Graphics; g.PageUnit = GraphicsUnit.Display; int hoffset = 0; int sitePrintedWords = 0; int tableBegin = 0; int sideOffset = 2; int lineOffset = 2; int lineThickness = 1; int textMinHeight = 17; using (Font siteFont = new Font("Arial", 11)) using (StringFormat centerFormat = new StringFormat() { Alignment = StringAlignment.Center }) { g.DrawString($"{Words.Site} {pageNumber}", siteFont, Brushes.Black, e.MarginBounds.SetHeight(20).Move(0, -20), centerFormat); } using (Font titleFont = new Font("Arial", 12, FontStyle.Bold)) using (StringFormat centerFormat = new StringFormat() { Alignment = StringAlignment.Center }) { string name = string.IsNullOrWhiteSpace(book.Name) ? "" : book.Name + ": "; string left = invertSides ? book.ForeignLang : book.MotherTongue; string right = invertSides ? book.MotherTongue : book.ForeignLang; string title = $"{name}{left} - {right}"; g.DrawString(title, titleFont, Brushes.Black, e.MarginBounds.MarginTop(hoffset).SetHeight(25), centerFormat); hoffset += 25; tableBegin = hoffset; } using (Font font = new Font("Arial", 10)) using (StringFormat nearFormat = new StringFormat() { Alignment = StringAlignment.Near }) using (Pen pen = new Pen(Brushes.Black, lineThickness)) { for (; ; wordNumber++, sitePrintedWords++) // loop through printList { Rectangle rect = e.MarginBounds.MarginTop(hoffset += lineOffset); g.DrawLine(pen, rect.Left, rect.Top, rect.Right, rect.Top); // Draw horizontal lines hoffset += (int)pen.Width + lineOffset; if (wordNumber >= printList.Count) { break; } rect = e.MarginBounds.MarginTop(hoffset); VocabularyWord word = printList[wordNumber]; Rectangle left = new Rectangle(rect.X, rect.Y, rect.Width / 2, rect.Height).MarginSide(sideOffset); Rectangle right = new Rectangle(left.Right, rect.Y, rect.Width / 2, rect.Height).MarginSide(sideOffset) .MarginLeft(lineThickness); // right column is smaller than the left one because of the line string leftText = invertSides ? word.ForeignLangText : word.MotherTongue; string rightText = invertSides ? word.MotherTongue : word.ForeignLangText; SizeF leftSize = g.MeasureString(leftText, font, left.Size, nearFormat, out int leftChars, out int leftLines); SizeF rightSize = g.MeasureString(rightText, font, right.Size, nearFormat, out int rightChars, out int rightLines); bool missingChars = leftChars < leftText.Length || rightChars < rightText.Length; int textHeight = (int)Math.Max(textMinHeight, Math.Max(leftSize.Height, rightSize.Height)); if (sitePrintedWords > 0 && (missingChars || textHeight > rect.Height)) { e.HasMorePages = true; break; } g.DrawString(leftText, font, Brushes.Black, left, nearFormat); g.DrawString(rightText, font, Brushes.Black, right, nearFormat); hoffset += textHeight; } } using (Pen pen = new Pen(Brushes.Black, lineThickness)) // Draw vertical lines { Rectangle table = e.MarginBounds.MarginTop(tableBegin + lineOffset) .SetHeight(hoffset - tableBegin - lineThickness - 2 * lineOffset); g.DrawLine(pen, table.Left, table.Top, table.Left, table.Bottom); g.DrawLine(pen, table.Right, table.Top, table.Right, table.Bottom); int middleX = table.Left + table.Width / 2; g.DrawLine(pen, middleX, table.Top, middleX, table.Bottom); } pageNumber++; }
private void EvaluateWord() { TbForeignLang.ReadOnly = true; TbMotherTongue.ReadOnly = true; TbForeignLangSynonym.ReadOnly = true; GroupUserEvaluation.Enabled = true; currentPractice.PracticeResult = EvaluateInput(); currentWord.PracticeDate = DateTime.Now; Stream sound = null; //Ergebnis bekannt geben if (currentPractice.PracticeResult == PracticeResult.Correct) { //Ergebnisse speichern if (currentWord.PracticeStateNumber == 0) { currentWord.PracticeStateNumber = 2; } else { currentWord.PracticeStateNumber++; } if (!Settings.Default.UserEvaluates) { TbCorrectAnswer.Text = Words.Correct + "!"; TbCorrectAnswer.BackColor = Color.FromArgb(144, 238, 144); sound = Sounds.sound_correct; } } else if (currentPractice.PracticeResult == PracticeResult.PartlyCorrect) { currentPractice.WrongInput = GetWrongInput(); // Do not change practice state number in this case if (!Settings.Default.UserEvaluates) { TbCorrectAnswer.Text = $"{Words.PartlyCorrect}! ({GetEvaluationAnswer()})"; TbCorrectAnswer.BackColor = Color.FromArgb(255, 215, 0); sound = Sounds.sound_correct; } } else // if (currentPractice.PracticeResult == PracticeResult.Wrong) { currentPractice.WrongInput = GetWrongInput(); currentWord.PracticeStateNumber = 1; if (!Settings.Default.UserEvaluates) { TbCorrectAnswer.Text = $"{Words.Wrong}! ({GetEvaluationAnswer()}"; TbCorrectAnswer.BackColor = Color.FromArgb(255, 192, 203); sound = Sounds.sound_wrong; } } // Sound playback player.Stop(); if (Settings.Default.PracticeSoundFeedback && sound != null) { player.Stream = sound; player.Play(); } //Nächste Vokabel vorbereiten index++; if (index < practiceList.Count) { currentPractice = practiceList[index]; currentWord = currentPractice.VocabularyWord; } //Zahlen aktualisieren RefreshStatistics(); check = false; solution = false; if (index == practiceList.Count) { BtnContinue.Text = Words.Finish; } }
private bool IsVocabularyWordExistsInDb(VocabularyWord vocabularyWord) { var vocub = (from v in Db.VocabularyWords where v.Value == vocabularyWord.Value select v).FirstOrDefault(); return(vocub != null); }