示例#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(
                  "SELECT vc.* FROM " + SqlHelper.Table_VocabMeaning_VocabCategory + " vmvc "
                + "JOIN " + SqlHelper.Table_VocabCategory + " vc ON (vmvc."
                + SqlHelper.Field_VocabMeaning_VocabCategory_VocabCategoryId + "=vc."
                + SqlHelper.Field_VocabCategory_Id + ") WHERE vmvc."
                + SqlHelper.Field_VocabMeaning_VocabCategory_VocabMeaningId + "=@mid",
                new DaoParameter("@mid", meaning.ID));

            VocabCategoryBuilder categoryBuilder = new VocabCategoryBuilder();
            foreach (NameValueCollection nvcCategory in categories)
            {
                VocabCategory category = categoryBuilder.BuildEntity(nvcCategory, null);
                meaning.Categories.Add(category);
            }
        }
示例#2
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);
            }
        }