Example #1
0
 public void AddEntry(string entry, DictionaryEntry newEntryWithUsageCount)
 {
     //Also add to entries for auto complete
     var autoCompleteHash = entry.CreateAutoCompleteDictionaryEntryHash(log: false);
     AddToDictionary(entry, autoCompleteHash, newEntryWithUsageCount);
     if (!string.IsNullOrWhiteSpace(entry) && entry.Contains(" "))
     {
         //Entry is a phrase - also add with a dictionary entry hash (first letter of each word)
         var phraseAutoCompleteHash = entry.CreateDictionaryEntryHash(log: false);
         AddToDictionary(entry, phraseAutoCompleteHash, newEntryWithUsageCount);
     }
 }
        public void AddEntry(string entry, DictionaryEntry dictionaryEntry)
        {
            var ngrams = ToNGrams(entry).ToList();
            var metaData = new EntryMetadata(dictionaryEntry, ngrams.Count());

            foreach (var ngram in ngrams)
            {
                if (entries.ContainsKey(ngram))
                {
                    entries[ngram].Add(metaData);
                }
                else
                {
                    entries[ngram] = new HashSet<EntryMetadata> {metaData};
                }
            }
        }
Example #3
0
        public void AddEntry(string entry, DictionaryEntry dictionaryEntry)
        {
            if (entry.Contains(" "))
            {
                //Entry is a phrase - also add with a dictionary entry hash (first letter of each word)
                var phraseAutoCompleteHash = entry.CreateDictionaryEntryHash(false);
                AddEntry(phraseAutoCompleteHash, dictionaryEntry);
            }

            var ngrams = ToNGrams(entry).ToList();
            var metaData = new EntryMetadata(dictionaryEntry, ngrams.Count);

            foreach (var ngram in ngrams)
            {
                if (entries.ContainsKey(ngram))
                {
                    entries[ngram].Add(metaData);
                }
                else
                {
                    entries[ngram] = new HashSet<EntryMetadata> {metaData};
                }
            }
        }
Example #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.CreateDictionaryEntryHash(log: !loadedFromDictionaryFile);
                if (!string.IsNullOrWhiteSpace(hash))
                {
                    var newEntryWithUsageCount = new DictionaryEntry { UsageCount = usageCount, Entry = entry };

                    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
                    var autoCompleteHash = entry.CreateAutoCompleteDictionaryEntryHash(log: false);
                    AddAutoCompleteEntry(entry, autoCompleteHash, newEntryWithUsageCount);
                    if (!string.IsNullOrWhiteSpace(entry) && entry.Contains(" "))
                    {
                        //Entry is a phrase - also add with a dictionary entry hash (first letter of each word)
                        var phraseAutoCompleteHash = entry.CreateDictionaryEntryHash(log: !loadedFromDictionaryFile);
                        AddAutoCompleteEntry(entry, phraseAutoCompleteHash, newEntryWithUsageCount);
                    }

                    if (!loadedFromDictionaryFile)
                    {
                        Log.DebugFormat("Adding new (not loaded from dictionary file) entry '{0}' to in-memory dictionary with hash '{1}'", entry, hash);
                        SaveUserDictionaryToFile();
                    }
                }
            }
        }
Example #5
0
 private void AddAutoCompleteEntry(string entry, string autoCompleteHash, DictionaryEntry newEntryWithUsageCount)
 {
     if (!string.IsNullOrWhiteSpace(autoCompleteHash))
     {
         if (entriesForAutoComplete.ContainsKey(autoCompleteHash))
         {
             if (entriesForAutoComplete[autoCompleteHash].All(nwwuc => nwwuc.Entry != entry))
             {
                 entriesForAutoComplete[autoCompleteHash].Add(newEntryWithUsageCount);
             }
         }
         else
         {
             entriesForAutoComplete.Add(autoCompleteHash, new List<DictionaryEntry> {newEntryWithUsageCount});
         }
     }
 }
        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);
        }
Example #7
0
 public EntryMetadata(DictionaryEntry dictionaryEntry, int nGramCount)
 {
     DictionaryEntry = dictionaryEntry;
     NGramCount = nGramCount;
 }