Exemple #1
0
        /// <summary>
        /// Includes the categories of the given meaning in the entity.
        /// </summary>
        private void IncludeMeaningCategories(DaoConnection connection, VocabMeaning meaning)
        {
            IEnumerable <NameValueCollection> categories = connection.Query(
                string.Format("SELECT vc.* FROM {0} vmvc JOIN {1} vc ON (vmvc.{2}=vc.{3}) WHERE vmvc.{4}=@mid",
                              SqlHelper.Table_VocabMeaning_VocabCategory,
                              SqlHelper.Table_VocabCategory,
                              SqlHelper.Field_VocabMeaning_VocabCategory_VocabCategoryId,
                              SqlHelper.Field_VocabCategory_Id,
                              SqlHelper.Field_VocabMeaning_VocabCategory_VocabMeaningId),
                new DaoParameter("@mid", meaning.ID));

            VocabCategoryBuilder categoryBuilder = new VocabCategoryBuilder();

            foreach (NameValueCollection nvcCategory in categories)
            {
                VocabCategory category = categoryBuilder.BuildEntity(nvcCategory, null);
                meaning.Categories.Add(category);
            }
        }
Exemple #2
0
        /// <summary>
        /// Includes the meanings of the given vocab in the entity.
        /// </summary>
        private void IncludeMeanings(DaoConnection connection, VocabEntity vocab)
        {
            IEnumerable <NameValueCollection> meanings = connection.Query(
                string.Format("SELECT vm.* FROM {0} vvm JOIN {1} vm ON (vvm.{2}=vm.{3}) WHERE vvm.{4}=@vid",
                              SqlHelper.Table_Vocab_VocabMeaning,
                              SqlHelper.Table_VocabMeaning,
                              SqlHelper.Field_Vocab_VocabMeaning_VocabMeaningId,
                              SqlHelper.Field_VocabMeaning_Id,
                              SqlHelper.Field_Vocab_VocabMeaning_VocabId),
                new DaoParameter("@vid", vocab.ID));

            VocabMeaningBuilder meaningBuilder = new VocabMeaningBuilder();

            foreach (NameValueCollection nvcMeaning in meanings)
            {
                VocabMeaning meaning = meaningBuilder.BuildEntity(nvcMeaning, null);
                IncludeMeaningCategories(connection, meaning);
                vocab.Meanings.Add(meaning);
            }
        }
Exemple #3
0
        /// <summary>
        /// Parses a meaning element node.
        /// Updates the list with the available info.
        /// </summary>
        /// <param name="xmeaningElement">Element to parse.</param>
        /// <param name="vocabList">Vocab list to be updated.</param>
        private void ParseMeaning(XElement xmeaningElement, List <VocabEntity> vocabList)
        {
            // First, like in the reading nodes, we have to determine the vocabs the node targets.
            // There are two optional constraint nodes in a meaning node.

            VocabEntity[] targets;
            // Get all kanji reading constraints in an array.
            string[] kanjiConstraints = xmeaningElement.Elements(XmlNode_MeaningKanjiConstraint)
                                        .Select(x => x.Value).ToArray();
            // Get all kana reading constraints in an array.
            string[] kanaConstraints = xmeaningElement.Elements(XmlNode_MeaningReadingConstraint)
                                       .Select(x => x.Value).ToArray();

            // Filter from the vocab list.
            if (kanjiConstraints.Any() || kanaConstraints.Any())
            {
                targets = vocabList.Where(v => kanjiConstraints.Contains(v.KanjiWriting) ||
                                          kanaConstraints.Contains(v.KanaWriting)).ToArray();
            }
            else
            {
                targets = vocabList.ToArray();
            }

            // Targets acquired. Next, we will read the info of the node.

            // Get the categories by selecting on some nodes the DB categories matching the node values.
            List <VocabCategory> categories = new List <VocabCategory>();

            categories.AddRange(xmeaningElement.Elements(XmlNode_MeaningCategory)
                                .Select(x => GetCategoryByLabel(x.Value))
                                .Where(c => c != null));
            categories.AddRange(xmeaningElement.Elements(XmlNode_MeaningDialect)
                                .Select(x => GetCategoryByLabel(x.Value))
                                .Where(c => c != null));
            categories.AddRange(xmeaningElement.Elements(XmlNode_MeaningField)
                                .Select(x => GetCategoryByLabel(x.Value))
                                .Where(c => c != null));
            categories.AddRange(xmeaningElement.Elements(XmlNode_MeaningMisc)
                                .Select(x => GetCategoryByLabel(x.Value))
                                .Where(c => c != null));

            // Then, get the meanings.
            VocabMeaning meaning = new VocabMeaning()
            {
                Categories = categories
            };

            // For each meaning entry node
            foreach (XElement xmeaningEntry in xmeaningElement.Elements(XmlNode_MeaningEntry))
            {
                // Get the language and value.
                string language = null;
                if (xmeaningEntry.Attribute(XmlNs + XmlAttribute_Language) != null)
                {
                    language = _cultureDictionary[
                        xmeaningEntry.Attribute(XmlNs + XmlAttribute_Language).Value];

                    if (language.ToLower() == "en")
                    {
                        language = null;
                    }
                }
                string value = xmeaningEntry.Value;

                // Build a meaning entry and add it to the meaning.
                // Only take english meanings (for now?).
                if (language == null)
                {
                    meaning.Meaning += value + " ; ";
                }
            }
            meaning.Meaning = meaning.Meaning.TrimEnd(new char[] { ';', ' ' });

            // Value the targets.
            foreach (VocabEntity target in targets)
            {
                target.Meanings.Add(meaning);
            }
        }