/// ------------------------------------------------------------------------------------ public RecordCache(PaProject project) { _project = project; _phoneticFieldName = _project.GetPhoneticField().Name; PhoneCache = new PhoneCache(project); RecordCacheEntry.ResetCounter(); }
/// ------------------------------------------------------------------------------------ public void BuildWordCache(ToolStripProgressBar progBar) { FindWordInitialGeneratedAmbigousSequences(); var tmpWordCache = new WordCache(); var recEntryParser = new RecordEntryParser(_phoneticFieldName, TempRecordCache.Add); foreach (var entry in this) { if (progBar != null) { progBar.Increment(1); } //// A record entry doesn't need parsing if it came from a PAXML data source //// or from an SA data source. //// In that case, a word cache entry only needs to have two things done here: //// 1) have its owning record entry set and 2) it needs to be added to the //// word cache. if (entry.NeedsParsing) { recEntryParser.ParseEntry(entry); } foreach (var wentry in entry.WordEntries) { wentry.RecordEntry = entry; tmpWordCache.Add(wentry); } } UnfilteredPhoneCache = GetPhonesFromWordCache(tmpWordCache); FindOtherGeneratedAmbiguousSequences(); SearchEngine.PhoneCache = UnfilteredPhoneCache; BuildFilteredWordCache(tmpWordCache); }
/// ------------------------------------------------------------------------------------ private PhoneCache GetPhonesFromWordCache(IEnumerable <WordCacheEntry> wordCache) { var phoneCache = new PhoneCache(_project); foreach (var entry in wordCache) { var phones = entry.Phones; if (phones == null) { continue; } for (int i = 0; i < phones.Length; i++) { // Don't bother adding break characters. if (App.BreakChars.Contains(phones[i])) { continue; } if (!phoneCache.ContainsKey(phones[i])) { phoneCache.AddPhone(phones[i]); } // Determine if the current phone is the primary // phone in an uncertain group. bool isPrimaryUncertainPhone = (entry.ContiansUncertainties && entry.UncertainPhones.ContainsKey(i)); // When the phone is the primary phone in an uncertain group, we // don't add it to the total count but to the counter that keeps // track of the primary uncertain phones. Then we also add to the // cache the non primary uncertain phones. if (!isPrimaryUncertainPhone) { phoneCache[phones[i]].TotalCount++; } else { phoneCache[phones[i]].CountAsPrimaryUncertainty++; // Go through the uncertain phones and add them to the cache. if (entry.ContiansUncertainties) { AddUncertainPhonesToCache(entry.UncertainPhones[i], phoneCache); UpdateSiblingUncertainties(entry.UncertainPhones, phoneCache); } } } } AddUndefinedCharsToCaches(phoneCache); return(phoneCache); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Goes through all the undefined phonetic characters found in data sources and adds /// temporary (i.e. as long as this session of PA is running) records for them in the /// IPA character cache and the phone cache. /// </summary> /// ------------------------------------------------------------------------------------ private static void AddUndefinedCharsToCaches(PhoneCache phoneCache) { if (App.IPASymbolCache.UndefinedCharacters == null || App.IPASymbolCache.UndefinedCharacters.Count == 0) { return; } foreach (var upci in App.IPASymbolCache.UndefinedCharacters) { App.IPASymbolCache.AddUndefinedCharacter(upci.Character); phoneCache.AddUndefinedPhone(upci.Character.ToString()); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Adds the specified list of uncertain phones to the phone cache. It is assumed the /// first (i.e. primary) phone in the list has already been added to the cache and, /// therefore, it will not be added nor its count incremented. /// </summary> /// ------------------------------------------------------------------------------------ private static void AddUncertainPhonesToCache(string[] uncertainPhoneGroup, PhoneCache phoneCache) { // Go through the uncertain phone groups, skipping the // primary one in each group since that was already added // to the cache above. for (int i = 1; i < uncertainPhoneGroup.Length; i++) { string phone = uncertainPhoneGroup[i]; // Don't bother adding break characters. if (!App.BreakChars.Contains(phone)) { if (!phoneCache.ContainsKey(phone)) { phoneCache.AddPhone(phone); } phoneCache[phone].CountAsNonPrimaryUncertainty++; } } }