Beispiel #1
0
        private static void IncrementPhraseWindow(PhraseWindow phraseWindow)
        {
            string sqlConditions =
                $"PrecedingWord3Id = {phraseWindow.PrecedingWord3Id.ToStringOrDefault()}" +
                $" and PrecedingWord2Id = {phraseWindow.PrecedingWord2Id.ToStringOrDefault()}" +
                $" and PrecedingWord1Id = {phraseWindow.PrecedingWord1Id.ToStringOrDefault()}" +
                $" and SuggestedWordId = {phraseWindow.SuggestedWordId}";

            int       today = PersistenceService.DB.TodayAsInt();
            string    sql   = $"Select ID from WordSequences where {sqlConditions} limit 1";
            DataTable data  = PersistenceService.DB.ExecuteQuery(sql);

            if (data.Rows.Count == 0)
            {
                sql = "Insert into WordSequences(PrecedingWord3Id, PrecedingWord2Id, PrecedingWord1Id, SuggestedWordId, UsageCount, LastUsedDate)" +
                      $" values (" +
                      $" {phraseWindow.PrecedingWord3Id.ToStringOrDefault()}," +
                      $" {phraseWindow.PrecedingWord2Id.ToStringOrDefault()}," +
                      $" {phraseWindow.PrecedingWord1Id.ToStringOrDefault()}," +
                      $" {phraseWindow.SuggestedWordId}, 1, {today})";
            }
            else
            {
                sql = $"Update WordSequences set UsageCount = UsageCount + 1, LastUsedDate = {today} " +
                      $" where {sqlConditions}";
            }
            PersistenceService.DB.ExecuteNonQuery(sql);
        }
Beispiel #2
0
        /// <summary>
        /// This method will run a 4 word sliding window across the sentence and update
        /// the database so we can learn which word sequences the user uses most often.
        /// For a 5 word sentence the entries will be
        /// null, null, null, word1
        /// null, null, word1, word2
        /// null, word1, word2, word3
        /// word1, word2, word3, word4
        /// word2, word3, word4, word5
        /// </summary>
        /// <param name="wordIds"></param>
        public static void IncrementPhraseUsage(IEnumerable <int> wordIds)
        {
            IEnumerable <PhraseWindow> phraseWindows = PhraseWindow.CreatePhraseWindows(wordIds);

            foreach (PhraseWindow phraseWindow in phraseWindows)
            {
                IncrementPhraseWindow(phraseWindow);
            }
        }
Beispiel #3
0
        public static IEnumerable <PhraseWindow> CreatePhraseWindows(IEnumerable <int> wordIds)
        {
            var result          = new List <PhraseWindow>();
            var suggestedWordId = wordIds.First();

            wordIds = wordIds.Skip(1);
            var wordWindow = new PhraseWindow(suggestedWordId);

            result.Add(wordWindow);
            foreach (int wordId in wordIds)
            {
                wordWindow = wordWindow.Next(wordId);
                result.Add(wordWindow);
            }
            return(result);
        }