Ejemplo n.º 1
0
        /// <summary>
        /// Gets all kanji with minimal info.
        /// </summary>
        /// <returns>All kanji with minimal info.</returns>
        public IEnumerable <KanjiEntity> GetAllKanji()
        {
            DaoConnection connection = null;

            try
            {
                // Create and open synchronously the primary Kanji connection.
                connection = DaoConnection.Open(DaoConnectionEnum.KanjiDatabase);

                IEnumerable <NameValueCollection> results = connection.Query(
                    string.Format("SELECT * FROM {0}", SqlHelper.Table_Kanji));

                KanjiBuilder kanjiBuilder = new KanjiBuilder();
                foreach (NameValueCollection nvcKanji in results)
                {
                    KanjiEntity kanji = kanjiBuilder.BuildEntity(nvcKanji, null);
                    yield return(kanji);
                }
            }
            finally
            {
                if (connection != null)
                {
                    connection.Dispose();
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets all kanji with minimal info.
        /// </summary>
        /// <returns>All kanji with minimal info.</returns>
        public IEnumerable<KanjiEntity> GetAllKanji()
        {
            DaoConnection connection = null;
            try
            {
                // Create and open synchronously the primary Kanji connection.
                connection = DaoConnection.Open(DaoConnectionEnum.KanjiDatabase);

                IEnumerable<NameValueCollection> results = connection.Query(
                  "SELECT * FROM " + SqlHelper.Table_Kanji);

                KanjiBuilder kanjiBuilder = new KanjiBuilder();
                foreach (NameValueCollection nvcKanji in results)
                {
                    KanjiEntity kanji = kanjiBuilder.BuildEntity(nvcKanji, null);
                    yield return kanji;
                }
            }
            finally
            {
                if (connection != null)
                {
                    connection.Dispose();
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets a set of kanji matching the given filters.
        /// </summary>
        /// <param name="radicals">Filters out kanji which do not contain all
        /// of the contained radicals.</param>
        /// <param name="textFilter">If set, filters out all kanji that are not
        /// contained in the string.</param>
        /// <param name="meaningFilter">Filter for the meaning of the kanji.</param>
        /// <param name="anyReadingFilter">Filter matching any reading of the kanji.
        /// <remarks>If set, this parameter will override the three reading filters.
        /// </remarks></param>
        /// <param name="onYomiFilter">Filter for the on'yomi reading of the kanji.
        /// <remarks>This parameter will be ignored if
        /// <paramref name="anyReadingFilter"/> is set.</remarks></param>
        /// <param name="kunYomiFilter">Filter for the kun'yomi reading of the kanji.
        /// <remarks>This parameter will be ignored if
        /// <paramref name="anyReadingFilter"/> is set.</remarks></param>
        /// <param name="nanoriFilter">Filter for the nanori reading of the kanji.
        /// <remarks>This parameter will be ignored if
        /// <paramref name="anyReadingFilter"/> is set.</remarks></param>
        /// <returns>Kanji matching the given filters.</returns>
        public IEnumerable <KanjiEntity> GetFilteredKanji(RadicalGroup[] radicals, string textFilter,
                                                          string meaningFilter, string anyReadingFilter, string onYomiFilter, string kunYomiFilter,
                                                          string nanoriFilter, int jlptLevel, int wkLevel)
        {
            List <DaoParameter> parameters = new List <DaoParameter>();
            string sqlFilter = BuildKanjiFilterClauses(parameters, radicals, textFilter,
                                                       meaningFilter, anyReadingFilter, onYomiFilter, kunYomiFilter, nanoriFilter,
                                                       jlptLevel, wkLevel);

            DaoConnection connection    = null;
            DaoConnection srsConnection = null;

            try
            {
                // Create and open synchronously the primary Kanji connection.
                connection = DaoConnection.Open(DaoConnectionEnum.KanjiDatabase);

                // Create the secondary Srs connection and open it asynchronously.
                srsConnection = new DaoConnection(DaoConnectionEnum.SrsDatabase);
                srsConnection.OpenAsync();

                // FILTERS COMPUTED.
                // Execute the final request.
                IEnumerable <NameValueCollection> results = connection.Query(string.Format(
                                                                                 "SELECT * FROM {0} k {1}ORDER BY (k.{2} IS NULL),(k.{2});",
                                                                                 SqlHelper.Table_Kanji,
                                                                                 sqlFilter,
                                                                                 SqlHelper.Field_Kanji_MostUsedRank),
                                                                             parameters.ToArray());

                KanjiBuilder kanjiBuilder = new KanjiBuilder();
                foreach (NameValueCollection nvcKanji in results)
                {
                    KanjiEntity kanji = kanjiBuilder.BuildEntity(nvcKanji, null);
                    IncludeKanjiMeanings(connection, kanji);
                    IncludeRadicals(connection, kanji);
                    IncludeSrsEntries(srsConnection, kanji);
                    yield return(kanji);
                }
            }
            finally
            {
                if (connection != null)
                {
                    connection.Dispose();
                }
                if (srsConnection != null)
                {
                    srsConnection.Dispose();
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Retrieves and includes kanji entities in the given radical entity.
        /// </summary>
        private void IncludeKanji(DaoConnection connection, RadicalEntity radical)
        {
            IEnumerable <NameValueCollection> results = connection.Query(
                string.Format(
                    "SELECT kr.{0} {1} FROM {2} kr WHERE kr.{3}=@rid",
                    SqlHelper.Field_Kanji_Radical_KanjiId,
                    SqlHelper.Field_Kanji_Id,
                    SqlHelper.Table_Kanji_Radical,
                    SqlHelper.Field_Kanji_Radical_RadicalId),
                new DaoParameter("@rid", radical.ID));

            KanjiBuilder kanjiBuilder = new KanjiBuilder();

            foreach (NameValueCollection nvcKanjiRadical in results)
            {
                KanjiEntity kanji = kanjiBuilder.BuildEntity(nvcKanjiRadical, null);
                radical.Kanji.Add(kanji);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Includes the kanji of the given vocab in the entity.
        /// </summary>
        private void IncludeKanji(DaoConnection connection, DaoConnection srsConnection,
                                  VocabEntity vocab)
        {
            IEnumerable <NameValueCollection> results = connection.Query(
                string.Format("SELECT k.* FROM {0} kv JOIN {1} k ON (k.{2}=kv.{3}) WHERE kv.{4}=@vid",
                              SqlHelper.Table_Kanji_Vocab,
                              SqlHelper.Table_Kanji,
                              SqlHelper.Field_Kanji_Id,
                              SqlHelper.Field_Kanji_Vocab_KanjiId,
                              SqlHelper.Field_Kanji_Vocab_VocabId),
                new DaoParameter("@vid", vocab.ID));

            KanjiBuilder kanjiBuilder = new KanjiBuilder();

            foreach (NameValueCollection nvcKanji in results)
            {
                KanjiEntity kanji = kanjiBuilder.BuildEntity(nvcKanji, null);
                KanjiDao.IncludeKanjiMeanings(connection, kanji);
                KanjiDao.IncludeRadicals(connection, kanji);
                KanjiDao.IncludeSrsEntries(srsConnection, kanji);
                vocab.Kanji.Add(kanji);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Includes the kanji of the given vocab in the entity.
        /// </summary>
        private void IncludeKanji(DaoConnection connection, DaoConnection srsConnection,
            VocabEntity vocab)
        {
            IEnumerable<NameValueCollection> results = connection.Query(
                "SELECT k.* FROM " + SqlHelper.Table_Kanji_Vocab + " kv "
                + "JOIN " + SqlHelper.Table_Kanji + " k ON (k."
                + SqlHelper.Field_Kanji_Id + "=kv." + SqlHelper.Field_Kanji_Vocab_KanjiId
                + ") WHERE kv." + SqlHelper.Field_Kanji_Vocab_VocabId + "=@vid",
                new DaoParameter("@vid", vocab.ID));

            KanjiBuilder kanjiBuilder = new KanjiBuilder();
            foreach (NameValueCollection nvcKanji in results)
            {
                KanjiEntity kanji = kanjiBuilder.BuildEntity(nvcKanji, null);
                KanjiDao.IncludeKanjiMeanings(connection, kanji);
                KanjiDao.IncludeRadicals(connection, kanji);
                KanjiDao.IncludeSrsEntries(srsConnection, kanji);
                vocab.Kanji.Add(kanji);
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Gets a set of kanji matching the given filters.
        /// </summary>
        /// <param name="radicals">Filters out kanji which do not contain all
        /// of the contained radicals.</param>
        /// <param name="textFilter">If set, filters out all kanji that are not
        /// contained in the string.</param>
        /// <param name="meaningFilter">Filter for the meaning of the kanji.</param>
        /// <param name="anyReadingFilter">Filter matching any reading of the kanji.
        /// <remarks>If set, this parameter will override the three reading filters.
        /// </remarks></param>
        /// <param name="onYomiFilter">Filter for the on'yomi reading of the kanji.
        /// <remarks>This parameter will be ignored if
        /// <paramref name="anyReadingFilter"/> is set.</remarks></param>
        /// <param name="kunYomiFilter">Filter for the kun'yomi reading of the kanji.
        /// <remarks>This parameter will be ignored if
        /// <paramref name="anyReadingFilter"/> is set.</remarks></param>
        /// <param name="nanoriFilter">Filter for the nanori reading of the kanji.
        /// <remarks>This parameter will be ignored if
        /// <paramref name="anyReadingFilter"/> is set.</remarks></param>
        /// <returns>Kanji matching the given filters.</returns>
        public IEnumerable<KanjiEntity> GetFilteredKanji(RadicalGroup[] radicals, string textFilter,
            string meaningFilter, string anyReadingFilter, string onYomiFilter, string kunYomiFilter,
            string nanoriFilter)
        {
            List<DaoParameter> parameters = new List<DaoParameter>();
            string sqlFilter = BuildKanjiFilterClauses(parameters, radicals, textFilter,
                meaningFilter, anyReadingFilter, onYomiFilter, kunYomiFilter, nanoriFilter);

            DaoConnection connection = null;
            DaoConnection srsConnection = null;
            try
            {
                // Create and open synchronously the primary Kanji connection.
                connection = DaoConnection.Open(DaoConnectionEnum.KanjiDatabase);

                // Create the secondary Srs connection and open it asynchronously.
                srsConnection = new DaoConnection(DaoConnectionEnum.SrsDatabase);
                srsConnection.OpenAsync();

                // FILTERS COMPUTED.
                // Execute the final request.
                IEnumerable<NameValueCollection> results = connection.Query(
                    "SELECT * "
                + "FROM " + SqlHelper.Table_Kanji + " k "
                + sqlFilter
                + "ORDER BY (k." + SqlHelper.Field_Kanji_MostUsedRank + " IS NULL),"
                + "(k." + SqlHelper.Field_Kanji_MostUsedRank + ");",
                parameters.ToArray());

                KanjiBuilder kanjiBuilder = new KanjiBuilder();
                foreach (NameValueCollection nvcKanji in results)
                {
                    KanjiEntity kanji = kanjiBuilder.BuildEntity(nvcKanji, null);
                    IncludeKanjiMeanings(connection, kanji);
                    IncludeRadicals(connection, kanji);
                    IncludeSrsEntries(srsConnection, kanji);
                    yield return kanji;
                }
            }
            finally
            {
                if (connection != null)
                {
                    connection.Dispose();
                }
                if (srsConnection != null)
                {
                    srsConnection.Dispose();
                }
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Retrieves and includes kanji entities in the given radical entity.
        /// </summary>
        private void IncludeKanji(DaoConnection connection, RadicalEntity radical)
        {
            IEnumerable<NameValueCollection> results = connection.Query(
                "SELECT kr." + SqlHelper.Field_Kanji_Radical_KanjiId + " "
                + SqlHelper.Field_Kanji_Id + " FROM " + SqlHelper.Table_Kanji_Radical
                + " kr WHERE kr." + SqlHelper.Field_Kanji_Radical_RadicalId + "=@rid",
                new DaoParameter("@rid", radical.ID));

            KanjiBuilder kanjiBuilder = new KanjiBuilder();
            foreach (NameValueCollection nvcKanjiRadical in results)
            {
                KanjiEntity kanji = kanjiBuilder.BuildEntity(nvcKanjiRadical, null);
                radical.Kanji.Add(kanji);
            }
        }