コード例 #1
0
ファイル: WordList.cs プロジェクト: yu-kopylov/cramtool
        public Word Add(string name, string description, string tags)
        {
            Contract.Assert(!wordsByName.ContainsKey(name));
            Modified = true;

            Word word = new Word();
            word.Name = name;
            word.Description = description;
            word.Tags = TagParser.ReformatTags(tags);
            word.Mark(WordEventType.Added);

            WordInfo wordInfo = WordInfo.Create(this, word);
            wordsByName.Add(name, wordInfo);

            tagIndex.Add(name, wordInfo.Tags);
            translationIndex.Add(name, wordInfo.Translations);

            UpdateTranslations(wordInfo.Translations);

            UpdateStats();

            OnContentsChanged();

            return word;
        }
コード例 #2
0
ファイル: WordEventInfo.cs プロジェクト: yu-kopylov/cramtool
 public WordEventInfo(Word word, WordEvent wordEvent, WordState wordState, DateTime lastStateChange)
 {
     this.word = word;
     this.wordEvent = wordEvent;
     this.wordState = wordState;
     this.lastStateChange = lastStateChange;
 }
コード例 #3
0
        private static FlowDocument FormatWord(Word word)
        {
            FlowDocument document = new FlowDocument();

            if (word == null)
            {
                return document;
            }

            Paragraph paragraph = FlowDocumentStyles.CreateParagraph();
            document.Blocks.Add(paragraph);

            {
                Run run = new Run(word.Name);
                paragraph.Inlines.Add(run);
                FlowDocumentStyles.FormatWord(run);
                paragraph.Inlines.Add(new LineBreak());
            }

            ArticleLexer parser = new ArticleLexer();
            List<Token> tokens = parser.Parse(word.Description);

            foreach (Token token in tokens)
            {
                string text = token.Value;
                if (token.Type == TokenType.Translation)
                {
                    text = "\u2022 " + text;
                }
                if (token.Type == TokenType.Example)
                {
                    text = "Example: " + text;
                }
                Run run = new Run(text);
                paragraph.Inlines.Add(run);
                FormatText(run, token.Type);
            }

            //todo: handle different number of new lines in the end of the artcle
            if (!string.IsNullOrEmpty(word.Tags))
            {
                Paragraph tagsParagraph = new Paragraph();
                document.Blocks.Add(tagsParagraph);
                tagsParagraph.Margin = new Thickness(0, 5, 0, 0);

                Run run = new Run("Tags: ");
                tagsParagraph.Inlines.Add(run);
                run.FontWeight = FontWeights.Bold;

                run = new Run(word.Tags);
                tagsParagraph.Inlines.Add(run);
            }

            return document;
        }
コード例 #4
0
ファイル: TestWordInfo.cs プロジェクト: yu-kopylov/cramtool
        public void Test()
        {
            DateTime dateAdded = DateTime.UtcNow.AddDays(-100);
            DateTime dateRepeated1 = dateAdded + new TimeSpan(1, 0, 0, 0);
            DateTime dateForgotten = dateAdded + new TimeSpan(2, 0, 0, 0);
            DateTime dateRepeated2 = dateAdded + new TimeSpan(2, 0, 1, 0);
            DateTime dateRepeated3 = dateAdded + new TimeSpan(3, 0, 0, 0);
            DateTime dateLearned = dateAdded + new TimeSpan(4, 0, 0, 0);
            DateTime dateVerified = dateAdded + new TimeSpan(10, 0, 0, 0);

            Word word = new Word();
            word.Name = "name";
            word.Description = "descr";
            word.Tags = "tag1, tag2";
            word.Events.Add(new WordEvent(dateAdded, WordEventType.Added));
            word.Events.Add(new WordEvent(dateRepeated1, WordEventType.Remembered));
            word.Events.Add(new WordEvent(dateForgotten, WordEventType.Forgotten));
            word.Events.Add(new WordEvent(dateRepeated2, WordEventType.Remembered));

            WordList wordList = new WordList();
            wordList.Populate(new List<Word> {word});

            WordInfo wordInfo = WordInfo.Create(wordList, word);
            Assert.That(wordInfo.LastEvent.LastStateChange, Is.EqualTo(dateForgotten));
            Assert.That(wordInfo.State, Is.EqualTo(WordState.Studied));
            Assert.That(wordInfo.IsStudied);
            Assert.That(!wordInfo.IsLearned);
            Assert.That(!wordInfo.IsVerified);

            word.Events.Add(new WordEvent(dateRepeated3, WordEventType.Remembered));
            wordInfo.Update();
            Assert.That(wordInfo.LastEvent.LastStateChange, Is.EqualTo(dateRepeated3));
            Assert.That(wordInfo.State, Is.EqualTo(WordState.Repeated));
            Assert.That(wordInfo.IsStudied);
            Assert.That(!wordInfo.IsLearned);
            Assert.That(!wordInfo.IsVerified);

            word.Events.Add(new WordEvent(dateLearned, WordEventType.Remembered));
            wordInfo.Update();
            Assert.That(wordInfo.LastEvent.LastStateChange, Is.EqualTo(dateLearned));
            Assert.That(wordInfo.State, Is.EqualTo(WordState.Learned));
            Assert.That(wordInfo.IsStudied);
            Assert.That(wordInfo.IsLearned);
            Assert.That(!wordInfo.IsVerified);

            word.Events.Add(new WordEvent(dateVerified, WordEventType.Remembered));
            wordInfo.Update();
            Assert.That(wordInfo.LastEvent.LastStateChange, Is.EqualTo(dateVerified));
            Assert.That(wordInfo.State, Is.EqualTo(WordState.Verified));
            Assert.That(wordInfo.IsStudied);
            Assert.That(wordInfo.IsLearned);
            Assert.That(wordInfo.IsVerified);
        }
コード例 #5
0
ファイル: TestWord.cs プロジェクト: yu-kopylov/cramtool
        public void TestEventOrderingWithFutureDates()
        {
            Word word = new Word();

            word.Events.Add(new WordEvent(DateTime.UtcNow.AddDays(1), WordEventType.Added));
            word.Events.Add(new WordEvent(DateTime.UtcNow.AddDays(2), WordEventType.Remembered));

            word.Mark(WordEventType.Forgotten);
            Assert.That(word.Events.Count, Is.EqualTo(2));
            Assert.That(word.Events[0].EventType, Is.EqualTo(WordEventType.Added));
            Assert.That(word.Events[1].EventType, Is.EqualTo(WordEventType.Forgotten));
            Assert.That(word.Events[0].EventDate, Is.LessThanOrEqualTo(word.Events[1].EventDate));
        }
コード例 #6
0
        private static Word ConvertToObject(WordXml wordXml)
        {
            var word = new Word();

            word.Name = wordXml.Name;
            word.Description = wordXml.Description;
            word.Tags = wordXml.Tags;

            List<WordEvent> events = ConvertToObject(wordXml.Events);

            foreach (WordEvent wordEvent in events)
            {
                word.Events.Add(wordEvent);
            }

            return word;
        }
コード例 #7
0
ファイル: TestWord.cs プロジェクト: yu-kopylov/cramtool
        public void TestEventOrdering1()
        {
            Word word = new Word();

            word.Mark(WordEventType.Added);
            Assert.That(word.Events.Count, Is.EqualTo(1));
            Assert.That(word.Events[0].EventType, Is.EqualTo(WordEventType.Added));

            word.Mark(WordEventType.Remembered);
            Assert.That(word.Events.Count, Is.EqualTo(2));
            Assert.That(word.Events[0].EventType, Is.EqualTo(WordEventType.Added));
            Assert.That(word.Events[1].EventType, Is.EqualTo(WordEventType.Remembered));
            Assert.That(word.Events[0].EventDate, Is.LessThanOrEqualTo(word.Events[1].EventDate));

            word.Mark(WordEventType.Forgotten);
            Assert.That(word.Events.Count, Is.EqualTo(2));
            Assert.That(word.Events[0].EventType, Is.EqualTo(WordEventType.Added));
            Assert.That(word.Events[1].EventType, Is.EqualTo(WordEventType.Forgotten));
            Assert.That(word.Events[0].EventDate, Is.LessThanOrEqualTo(word.Events[1].EventDate));
        }
コード例 #8
0
ファイル: TestWord.cs プロジェクト: yu-kopylov/cramtool
        public void TestTranslationEvents()
        {
            Word word = new Word();

            word.Events.Add(new WordEvent(DateTime.UtcNow.AddDays(-1), WordEventType.Added));
            word.Events.Add(new WordEvent(DateTime.UtcNow.AddDays(1), WordEventType.Remembered));

            word.MarkTranslation(WordEventType.Forgotten, "a");
            Assert.That(word.Events.Count, Is.EqualTo(3));
            Assert.That(word.Events[0].EventType, Is.EqualTo(WordEventType.Added));
            Assert.That(word.Events[1].EventType, Is.EqualTo(WordEventType.Remembered));
            Assert.That(word.Events[2].EventType, Is.EqualTo(WordEventType.Forgotten));
            Assert.That(word.Events[0].Translation, Is.Null);
            Assert.That(word.Events[1].Translation, Is.Null);
            Assert.That(word.Events[2].Translation, Is.EqualTo("a"));

            word.MarkTranslation(WordEventType.Remembered, "b");
            Assert.That(word.Events.Count, Is.EqualTo(4));
            Assert.That(word.Events[0].EventType, Is.EqualTo(WordEventType.Added));
            Assert.That(word.Events[1].EventType, Is.EqualTo(WordEventType.Remembered));
            Assert.That(word.Events[2].EventType, Is.EqualTo(WordEventType.Forgotten));
            Assert.That(word.Events[3].EventType, Is.EqualTo(WordEventType.Remembered));
            Assert.That(word.Events[0].Translation, Is.Null);
            Assert.That(word.Events[1].Translation, Is.Null);
            Assert.That(word.Events[2].Translation, Is.EqualTo("a"));
            Assert.That(word.Events[3].Translation, Is.EqualTo("b"));

            word.MarkTranslation(WordEventType.Remembered, "a");
            Assert.That(word.Events.Count, Is.EqualTo(4));
            Assert.That(word.Events[0].EventType, Is.EqualTo(WordEventType.Added));
            Assert.That(word.Events[1].EventType, Is.EqualTo(WordEventType.Remembered));
            Assert.That(word.Events[2].EventType, Is.EqualTo(WordEventType.Remembered));
            Assert.That(word.Events[3].EventType, Is.EqualTo(WordEventType.Remembered));
            Assert.That(word.Events[0].Translation, Is.Null);
            Assert.That(word.Events[1].Translation, Is.Null);
            Assert.That(word.Events[2].Translation, Is.EqualTo("b"));
            Assert.That(word.Events[3].Translation, Is.EqualTo("a"));
        }
コード例 #9
0
        private static WordEventInfo CreateEventInfo(Word word, WordEventInfo prevEventInfo, WordEvent wordEvent)
        {
            if (prevEventInfo == null || wordEvent.EventType != WordEventType.Remembered)
            {
                return new WordEventInfo(word, wordEvent, WordState.Studied, wordEvent.EventDate);
            }

            TimeSpan timeSinceLastStateChange = wordEvent.EventDate - prevEventInfo.LastStateChange;

            if (prevEventInfo.WordState == WordState.Studied && timeSinceLastStateChange >= WordInfo.TimeToMarkRepeated)
            {
                return new WordEventInfo(word, wordEvent, WordState.Repeated, wordEvent.EventDate);
            }

            if (prevEventInfo.WordState == WordState.Repeated && timeSinceLastStateChange >= WordInfo.TimeToMarkLearned)
            {
                return new WordEventInfo(word, wordEvent, WordState.Learned, wordEvent.EventDate);
            }

            if (prevEventInfo.WordState == WordState.Learned && timeSinceLastStateChange >= WordInfo.TimeToMarkVerified)
            {
                return new WordEventInfo(word, wordEvent, WordState.Verified, wordEvent.EventDate);
            }

            return new WordEventInfo(word, wordEvent, prevEventInfo.WordState, prevEventInfo.LastStateChange);
        }
コード例 #10
0
        private static WordXml ConvertToXml(Word word)
        {
            var wordXml = new WordXml();

            wordXml.Name = word.Name;
            wordXml.Description = word.Description;
            wordXml.Tags = string.IsNullOrEmpty(word.Tags) ? null : word.Tags;
            wordXml.Events = new WordEventXml[word.Events.Count];
            int idx = 0;
            foreach (WordEvent wordEvent in word.Events)
            {
                wordXml.Events[idx++] = ConvertToXml(wordEvent);
            }

            return wordXml;
        }
コード例 #11
0
 private void EditWord(object sender, ExecutedRoutedEventArgs e)
 {
     EditableWord = new Word();
     EditableWord.Name = CurrentWordForm.WordInfo.Word.Name;
     EditableWord.Description = CurrentWordForm.WordInfo.Word.Description;
     EditableWord.Tags = CurrentWordForm.WordInfo.Word.Tags;
 }
コード例 #12
0
 private void AddWord(object sender, ExecutedRoutedEventArgs e)
 {
     CurrentWordForm = null;
     EditableWord = new Word();
     EditableWord.Name = (SearchText ?? "").Trim();
     EditableWord.Description = "";
     EditableWord.Tags = "";
 }
コード例 #13
0
ファイル: WordInfo.cs プロジェクト: yu-kopylov/cramtool
        public static WordInfo Create(WordList wordList, Word word)
        {
            WordInfo res = new WordInfo();

            res.WordList = wordList;
            res.Word = word;

            res.Update();

            return res;
        }