/// <summary> /// This overload finds guesses for wordforms specified in a dictionary that maps a wordform to the /// string that we want to match (might be a different case form). /// </summary> /// <param name="wordsToMatch"></param> /// <returns></returns> private Dictionary <IWfiWordform, EmptyWwfInfo> MapWordsForComputerGuessesToBestMatchingEntry(Dictionary <IWfiWordform, ITsString> wordsToMatch) { var matchingMorphs = new Dictionary <ITsString, IMoStemAllomorph>(new TsStringEquator()); foreach (var tssWord in wordsToMatch.Values) { matchingMorphs[tssWord] = null; } MorphServices.GetMatchingMonomorphemicMorphs(Cache, matchingMorphs); var mapEmptyWfInfo = new Dictionary <IWfiWordform, EmptyWwfInfo>(); foreach (var kvp in wordsToMatch) { var word = kvp.Key; var tssWord = kvp.Value; var bestMatchingMorph = matchingMorphs[tssWord]; if (bestMatchingMorph != null) { var entryOrVariant = bestMatchingMorph.OwnerOfClass <ILexEntry>(); ILexEntry mainEntry; ILexSense sense; GetMainEntryAndSense(entryOrVariant, out mainEntry, out sense); if (sense == null && mainEntry.SensesOS.Count > 0) { sense = mainEntry.SensesOS.Where(s => s.MorphoSyntaxAnalysisRA is IMoStemMsa) .FirstOrDefault(); } IMoStemMsa msa = null; IPartOfSpeech pos = null; if (sense != null) { msa = (IMoStemMsa)sense.MorphoSyntaxAnalysisRA; pos = msa.PartOfSpeechRA; } // map the word to its best entry. var entryInfo = new EmptyWwfInfo(bestMatchingMorph, msa, pos, sense); mapEmptyWfInfo.Add(word, entryInfo); } } return(mapEmptyWfInfo); }
/// <summary> /// Confirm that we can break the specified string into the two parts needed for a circumfix. /// Return true (and the two parts, not stripped of affix markers) if successful. /// </summary> public static bool GetCircumfixLeftAndRightParts(FdoCache cache, ITsString tssLexemeForm, out string sLeftMember, out string sRightMember) { // split citation form into left and right parts sLeftMember = null; sRightMember = null; var aSpacePeriod = new[] { ' ', '.' }; var lexemeForm = tssLexemeForm.Text; var iLeftEnd = lexemeForm.IndexOfAny(aSpacePeriod); if (iLeftEnd < 0) { return(false); } sLeftMember = lexemeForm.Substring(0, iLeftEnd); int iRightBegin = lexemeForm.LastIndexOfAny(aSpacePeriod); if (iRightBegin < 0) { return(false); } sRightMember = lexemeForm.Substring(iRightBegin + 1); int clsidForm; try { var temp = sLeftMember; MorphServices.FindMorphType(cache, ref temp, out clsidForm); temp = sRightMember; MorphServices.FindMorphType(cache, ref temp, out clsidForm); } catch (Exception) { return(false); } return(true); }