예제 #1
0
        private string BuildValueForCard(Card card, bool placeExtraInfoWithCardValue)
        {
            // Main subject
            string mainSubject = (mCardKey == CardKey.kEnglish ? card.GetKeyResult(CardKey.kKana) : card.GetKeyResult(CardKey.kEnglish));

            // Extra info for key, but only if we ARE a multi answer card
            string valueExtraInfoNote = "";

            if (placeExtraInfoWithCardValue && card.GetExtraInformation().Length > 0)
            {
                valueExtraInfoNote = card.GetExtraInformation();
            }

            string valueForm = "";

            if (mDeckSerializer.HasExtraOptionEnabled(StudyOptions.Option.kIncludeVerbGroup) && card.HasCardType(CardType.kVerb))
            {
                valueForm = "Form: " + card.GetFormString();
            }

            string chapterNum = "";

            if (mDeckSerializer.HasExtraOptionEnabled(StudyOptions.Option.kIncludeChapterSourceInResult))
            {
                // If we have multiple distinct cards, each gets a chapter
                if (mCards.Count > 1)
                {
                    if (card.GetBookAndChapterNum().IsValid())
                    {
                        chapterNum = card.GetBookAndChapterNum().ToString();
                    }
                }
                // But if the cards were truly equivalent, then instead we show it as one card with multiple chapters
                else if (mCardChapterNums.Count > 0)
                {
                    chapterNum = string.Join("], [", mCardChapterNums);
                }
            }

            // Secondary subject
            string secondarySubject = (mCardKey == CardKey.kKanji ? card.GetKeyResult(CardKey.kKana) : card.GetKeyResult(CardKey.kKanji));

            if (secondarySubject.Equals(mainSubject))
            {
                secondarySubject = "";
            }

            // Kanji links
            List <string> kanjiLinks = card.GetKanjiLinks();

            // Word forms
            // Special case, calls to format are handled here for convenience
            List <WordForm> enabledWordForms = new List <WordForm>();

            card.GetEnabledWordForms(ref enabledWordForms);

            string wordFormText = "";

            if (enabledWordForms.Count > 0)
            {
                wordFormText = "";
                WordFormCategory lastCategorySeen = WordFormCategory.kBeginner;

                foreach (WordForm wordForm in enabledWordForms)
                {
                    if (wordForm.IsTypeAndPoliteness(WordFormType.kPerfect, WordPoliteness.kPolite))
                    {
                        continue; // The mainSubject is expected to be perfect polite
                    }

                    if (string.IsNullOrEmpty(wordFormText) || wordForm.GetWordFormCategory() != lastCategorySeen)
                    {
                        wordFormText    += kLineBreak;
                        lastCategorySeen = wordForm.GetWordFormCategory();
                    }

                    if (wordForm.TryGetDescription(out string wordFormDescription))
                    {
                        wordFormText += Format_InfoLine(wordFormDescription, wordForm.GetWord());
                    }
                    else
                    {
                        wordFormText += Format_PlainText(wordForm.GetWord());
                    }
                }
            }

            // Finish
            return
                (Format_PreNote(mSharedPreNote) +
                 Format_MainSubject(mainSubject) +
                 Format_WordSpecificity(valueExtraInfoNote) +
                 Format_WordSpecificity(valueForm) +
                 Format_WordSpecificity(chapterNum) +
                 Format_PlainText(secondarySubject) +
                 Format_InfoLine("漢字", string.Join(" , ", kanjiLinks)) +
                 wordFormText);
        }
예제 #2
0
 public FormTypeInfo(WordFormCategory category, WordFormConfig config = WordFormConfig.kNone)
 {
     mCategory = category;
     mConfig   = config;
 }
예제 #3
0
        private string BuildKey(bool placeExtraInfoWithCardValue)
        {
            // Main Subject
            string keyText = mCards[0].GetKeyResult(mCardKey);

            if (keyText.Length == 0)
            {
                if (mCardKey == CardKey.kKanji)
                {
                    keyText = mCards[0].GetKeyResult(CardKey.kKana);
                }
                else
                {
                    throw new Exception(string.Format("Card \"{0}\" is missing entry for key \"{1}\"", mCards[0].ToString(), mCardKey.ToString()));
                }
            }

            // Extra info for key, but only if we are NOT a multi answer card
            string keyExtraInfoNote = "";

            if (!placeExtraInfoWithCardValue && mCards[0].GetExtraInformation().Length > 0)
            {
                keyExtraInfoNote = mCards[0].GetExtraInformation();
            }

            // Key notes describing what extra forms we expect
            string          keyNote          = "";
            List <WordForm> enabledWordForms = new List <WordForm>();

            mCards[0].GetEnabledWordForms(ref enabledWordForms);

            List <string> formDescriptions = new List <string>();

            WordFormCategory lastSeenCategory = WordFormCategory.kBeginner;

            foreach (WordForm form in enabledWordForms)
            {
                if (form.TryGetDescription(out string description) && !formDescriptions.Contains(description))
                {
                    if ((formDescriptions.Count > 0) && form.GetWordFormCategory() != lastSeenCategory)
                    {
                        keyNote += string.Join(", ", formDescriptions) + "•";
                        formDescriptions.Clear();
                        lastSeenCategory = form.GetWordFormCategory();
                    }

                    formDescriptions.Add(description);
                }
            }

            if (formDescriptions.Count > 0)
            {
                keyNote += string.Join(", ", formDescriptions);
            }

            // Finish
            return
                (Format_PreNote(mSharedPreNote) +
                 Format_MainSubject(keyText) +
                 Format_WordSpecificity(keyExtraInfoNote) +
                 Format_PlainText(keyNote));
        }