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); } }
/// <summary> /// This goes through the collected list of WfiWordforms that do not have any analyses, and generates /// a guess for any whose forms exactly match a LexemeForm (or AlternateForm) of a stem/root entry. /// </summary> /// <param name="progress"></param> private void AddEntryGuesses(ProgressState progress) { if (m_rgEmptyWfis.Count == 0) return; MapEmptyWfToInfo(); progress.Breath(); if (m_mapEmptyWfInfo.Count == 0) return; foreach (EmptyWwfAnno ewa in m_rgEmptyWfis) { IWfiWordform ww = WfiWordform.CreateFromDBObject(m_cache, ewa.m_hvoWwf); EmptyWwfKey key = new EmptyWwfKey(ww.Hvo, ewa.m_ws); EmptyWwfInfo info; if (!m_mapEmptyWfInfo.TryGetValue(key, out info)) continue; IWfiAnalysis wa; if (ww.AnalysesOC.Count == 0) { ITsString tssName = null; int wsVern = 0; ILexEntryRef ler = SandboxBase.GetVariantRef(m_cache, info.m_hvoEntry, true); int hvoEntryToDisplay = info.m_hvoEntry; if (ler != null) { ICmObject coRef = ler.ComponentLexemesRS[0]; if (coRef is ILexSense) hvoEntryToDisplay = (coRef as ILexSense).EntryID; else hvoEntryToDisplay = coRef.Hvo; wsVern = StringUtils.GetWsAtOffset(m_tssPara, 0); tssName = InterlinDocChild.GetLexEntryTss(Cache, hvoEntryToDisplay, wsVern, ler); info.m_hvoSense = m_cache.MainCacheAccessor.get_VecItem(hvoEntryToDisplay, (int)LexEntry.LexEntryTags.kflidSenses, 0); info.m_hvoMsa = m_cache.MainCacheAccessor.get_ObjectProp(info.m_hvoSense, (int)LexSense.LexSenseTags.kflidMorphoSyntaxAnalysis); int clidMsa = m_cache.GetClassOfObject(info.m_hvoMsa); if (info.m_hvoPOS == 0) { info.m_hvoPOS = m_cache.MainCacheAccessor.get_ObjectProp(info.m_hvoMsa, (int)MoStemMsa.MoStemMsaTags.kflidPartOfSpeech); } } wa = new WfiAnalysis(); ww.AnalysesOC.Add(wa); wa.CategoryRAHvo = info.m_hvoPOS; WfiGloss wg = new WfiGloss(); wa.MeaningsOC.Add(wg); // Not all entries have senses. if (info.m_hvoSense != 0) { MultiUnicodeAccessor muaGloss = new MultiUnicodeAccessor(m_cache, info.m_hvoSense, /* ls.Id */ (int)LexSense.LexSenseTags.kflidGloss, "LexSense_Gloss"); wg.Form.MergeAlternatives(muaGloss); } WfiMorphBundle wmb = new WfiMorphBundle(); wa.MorphBundlesOS.Append(wmb); wmb.MorphRAHvo = info.m_hvoForm; if (tssName != null && wsVern != 0) wmb.Form.SetAlternative(tssName, wsVern); wmb.MsaRAHvo = info.m_hvoMsa; wmb.SenseRAHvo = info.m_hvoSense; // Now, set up an approved "Computer" evaluation of this generated analysis wa.SetAgentOpinion(m_cache.LangProject.DefaultComputerAgent, Opinions.approves); } else { // The same unanalyzed word may occur twice in a paragraph... wa = ww.AnalysesOC.ToArray()[0]; Debug.Assert(ww.AnalysesOC.Count == 1); Debug.Assert(wa.CategoryRAHvo == info.m_hvoPOS); Debug.Assert(wa.MorphBundlesOS.Count == 1); Debug.Assert(wa.MorphBundlesOS[0].MorphRAHvo == info.m_hvoForm); Debug.Assert(wa.MorphBundlesOS[0].MsaRAHvo == info.m_hvoMsa); Debug.Assert(wa.MorphBundlesOS[0].SenseRAHvo == info.m_hvoSense); } } progress.Breath(); }