/// <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);
        }
Beispiel #2
0
		private void MapEmptyWfToInfo()
		{
			m_mapEmptyWfInfo.Clear();
			IOleDbCommand odc = null;
			try
			{
				StringBuilder sbSql = new StringBuilder();
				sbSql.AppendLine("SELECT wwf.Obj, wwf.Ws, le.Id, mf.Id, msa.Id, msa.PartOfSpeech, ls.Id");
				sbSql.AppendLine(" FROM LexEntry le");
				sbSql.AppendLine(" JOIN MoStemAllomorph_ mf ON mf.Owner$=le.Id AND mf.OwnFlid$ IN (5002029,5002030)");
				sbSql.Append(" JOIN MoMorphType_ mmt ON mmt.Id=mf.MorphType");
				sbSql.AppendFormat(" AND mmt.Guid$ <> '{0}' AND mmt.Guid$ <> '{1}'",
					MoMorphType.kguidMorphBoundRoot, MoMorphType.kguidMorphBoundStem);
				sbSql.AppendLine();
				sbSql.AppendLine(" JOIN MoForm_Form mff ON mff.Obj=mf.Id");
				sbSql.AppendLine(" JOIN WfiWordform_Form wwf ON wwf.Txt=mff.Txt AND wwf.Ws=mff.Ws");
				sbSql.AppendLine(" LEFT OUTER JOIN MoStemMsa_ msa ON msa.Owner$=le.Id");
				sbSql.AppendLine(" LEFT OUTER JOIN LexSense_ ls ON ls.MorphoSyntaxAnalysis=msa.Id");
				sbSql.AppendLine(" LEFT OUTER JOIN WfiWordform_Analyses wwa ON wwa.Src=wwf.Obj");
				sbSql.AppendLine(" WHERE wwa.Dst IS NULL");
				sbSql.AppendLine(" ORDER BY le.HomographNumber, mf.OwnFlid$, ls.OwnOrd$;");
				string sQry = sbSql.ToString();
				m_cache.DatabaseAccessor.CreateCommand(out odc);
				odc.ExecCommand(sQry, (int)SqlStmtType.knSqlStmtSelectWithOneRowset);
				odc.GetRowset(0);
				bool fMoreRows;
				odc.NextRow(out fMoreRows);
				for (; fMoreRows; odc.NextRow(out fMoreRows))
				{
					int hvoWwf = DbOps.ReadInt(odc, 0);
					int wsWwf = DbOps.ReadInt(odc, 1);
					if (hvoWwf == 0 || wsWwf == 0)
						continue;
					int hvoEntry = DbOps.ReadInt(odc, 2);
					int hvoForm = DbOps.ReadInt(odc, 3);
					if (hvoEntry == 0 || hvoForm == 0)
						continue;
					int hvoMsa = DbOps.ReadInt(odc, 4);
					int hvoPOS = DbOps.ReadInt(odc, 5);
					int hvoSense = DbOps.ReadInt(odc, 6);
					EmptyWwfKey key = new EmptyWwfKey(hvoWwf, wsWwf);
					EmptyWwfInfo info;
					if (!m_mapEmptyWfInfo.TryGetValue(key, out info))
					{
						info = new EmptyWwfInfo(hvoEntry, hvoForm, hvoMsa, hvoPOS, hvoSense);
						m_mapEmptyWfInfo.Add(key, info);
					}
				}
			}
			catch (Exception exc)
			{
				// We shouldn't have any errors thrown, but absorb any that are.
				Debug.WriteLine("Exception ignored in ParagraphParser.MapEmptyWfToInfo(): {0}", exc.Message);
			}
			finally
			{
				DbOps.ShutdownODC(ref odc);
			}
		}