コード例 #1
0
        public void AddEntry_called_with_existing_entry_does_not_update_usage_count()
        {
            ConfigureProvider();

            // try to make this the "t"-word with the highest usage
            autoComplete.AddEntry("these", new DictionaryEntry("these", 101));

            var suggestions = autoComplete.GetSuggestions("t");

            Assert.AreNotEqual("these", suggestions.First());
        }
コード例 #2
0
        private void AddEntryToDictionary(string entry)
        {
            if (string.IsNullOrWhiteSpace(entry))
            {
                return;
            }

            var hash = entry.CreateDictionaryEntryHash(false);

            if (string.IsNullOrWhiteSpace(hash))
            {
                return;
            }

            var newEntryWithUsageCount = new DictionaryEntry(entry);

            autoComplete.AddEntry(entry, newEntryWithUsageCount);
        }
コード例 #3
0
        private void AddEntryToDictionary(string entry)
        {
            if (string.IsNullOrWhiteSpace(entry))
            {
                return;
            }

            var hash = entry.NormaliseAndRemoveRepeatingCharactersAndHandlePhrases(false);

            if (string.IsNullOrWhiteSpace(hash))
            {
                return;
            }

            var newEntryWithUsageCount = new DictionaryEntry(entry);

            autoComplete.AddEntry(entry, newEntryWithUsageCount);
        }
コード例 #4
0
        private void AddEntryToDictionary(string entry, bool loadedFromDictionaryFile, int usageCount = 0)
        {
            if (entries != null &&
                !string.IsNullOrWhiteSpace(entry) &&
                (loadedFromDictionaryFile || !ExistsInDictionary(entry)))
            {
                //Add to in-memory (hashed) dictionary (and then save to custom dictionary file if new entry entered by user)
                var hash = entry.NormaliseAndRemoveRepeatingCharactersAndHandlePhrases(log: !loadedFromDictionaryFile);
                if (!string.IsNullOrWhiteSpace(hash))
                {
                    var newEntryWithUsageCount = new DictionaryEntry(entry, usageCount);

                    //Also add to entries for auto complete
                    manageAutoComplete.AddEntry(entry, newEntryWithUsageCount, hash);

                    if (!loadedFromDictionaryFile)
                    {
                        Log.DebugFormat("Adding new (not loaded from dictionary file) entry '{0}' to in-memory dictionary with hash '{1}'", entry, hash);
                        SaveUserDictionaryToFile();
                    }
                }
            }
        }
コード例 #5
0
        private void AddEntryToDictionary(string entry, bool loadedFromDictionaryFile, int usageCount = 0)
        {
            if (entries != null &&
                !string.IsNullOrWhiteSpace(entry) &&
                (loadedFromDictionaryFile || !ExistsInDictionary(entry)))
            {
                //Add to in-memory (hashed) dictionary (and then save to custom dictionary file if new entry entered by user)
                var hash = entry.CreateDictionaryEntryHash(log: !loadedFromDictionaryFile);
                if (!string.IsNullOrWhiteSpace(hash))
                {
                    var newEntryWithUsageCount = new DictionaryEntry(entry, usageCount);

                    if (entries.ContainsKey(hash))
                    {
                        if (entries[hash].All(nwwuc => nwwuc.Entry != entry))
                        {
                            entries[hash].Add(newEntryWithUsageCount);
                        }
                    }
                    else
                    {
                        entries.Add(hash, new List <DictionaryEntry> {
                            newEntryWithUsageCount
                        });
                    }

                    //Also add to entries for auto complete
                    manageAutoComplete.AddEntry(entry, newEntryWithUsageCount);

                    if (!loadedFromDictionaryFile)
                    {
                        Log.DebugFormat("Adding new (not loaded from dictionary file) entry '{0}' to in-memory dictionary with hash '{1}'", entry, hash);
                        SaveUserDictionaryToFile();
                    }
                }
            }
        }