private XElement CreateAllomorphElement(Allomorph allomorph) { bool isNull = (bool?)allomorph.Properties["IsNull"] ?? false; if (isNull) { var slotID = (int)allomorph.Morpheme.Properties["SlotID"]; IMoInflAffixSlot slot; if (!m_cache.ServiceLocator.GetInstance <IMoInflAffixSlotRepository>().TryGetObject(slotID, out slot)) { return(null); } var nullInflTypeID = (int)allomorph.Morpheme.Properties["InflTypeID"]; ILexEntryInflType nullInflType; if (!m_cache.ServiceLocator.GetInstance <ILexEntryInflTypeRepository>().TryGetObject(nullInflTypeID, out nullInflType)) { return(null); } var isPrefix = (bool)allomorph.Properties["IsPrefix"]; return(new XElement("Allomorph", new XAttribute("id", 0), new XAttribute("type", isPrefix ? MoMorphTypeTags.kMorphPrefix : MoMorphTypeTags.kMorphSuffix), new XElement("Form", "^0"), new XElement("Morpheme", new XAttribute("id", 0), new XAttribute("type", "infl"), new XElement("HeadWord", string.Format("Automatically generated null affix for the {0} irregularly inflected form", nullInflType.Name.BestAnalysisAlternative.Text)), new XElement("Gloss", (nullInflType.GlossPrepend.BestAnalysisAlternative.Text == "***" ? "" : nullInflType.GlossPrepend.BestAnalysisAlternative.Text) + (nullInflType.GlossAppend.BestAnalysisAlternative.Text == "***" ? "" : nullInflType.GlossAppend.BestAnalysisAlternative.Text)), new XElement("Category", slot.OwnerOfClass <IPartOfSpeech>().Abbreviation.BestAnalysisAlternative.Text), new XElement("Slot", new XAttribute("optional", slot.Optional), slot.Name.BestAnalysisAlternative.Text)))); } var formID = (int?)allomorph.Properties["ID"] ?? 0; IMoForm form; if (formID == 0 || !m_cache.ServiceLocator.GetInstance <IMoFormRepository>().TryGetObject(formID, out form)) { return(null); } var formID2 = (int?)allomorph.Properties["ID2"] ?? 0; var msaID = (int)allomorph.Morpheme.Properties["ID"]; IMoMorphSynAnalysis msa; if (!m_cache.ServiceLocator.GetInstance <IMoMorphSynAnalysisRepository>().TryGetObject(msaID, out msa)) { return(null); } var inflTypeID = (int?)allomorph.Morpheme.Properties["InflTypeID"] ?? 0; ILexEntryInflType inflType = null; if (inflTypeID != 0 && !m_cache.ServiceLocator.GetInstance <ILexEntryInflTypeRepository>().TryGetObject(inflTypeID, out inflType)) { return(null); } return(HCParser.CreateAllomorphElement("Allomorph", form, msa, inflType, formID2 != 0)); }
public void PopulateTreeFromFeatureSystem() { // Set up sample data IFsFeatStruc featStruct; ILangProject lp = CreateFeatureSystem(out featStruct); // Set up the xml fs description XmlDocument doc = new XmlDocument(); string sFileDir = Path.Combine(SIL.FieldWorks.Common.FwUtils.DirectoryFinder.FwSourceDirectory, Path.Combine(@"FDO", Path.Combine(@"FDOTests", @"TestData"))); string sFile = Path.Combine(sFileDir, "FeatureSystem2.xml"); doc.Load(sFile); XmlNode itemNeut = doc.SelectSingleNode("//item[@id='vNeut']"); // Add some complex features IFsFeatureSystem msfs = lp.MsFeatureSystemOA; msfs.AddFeatureFromXml(itemNeut); // Now add a feature that differs only in value XmlNode itemFem = doc.SelectSingleNode("//item[@id='vFem']"); msfs.AddFeatureFromXml(itemFem); // Now add another feature to the complex one XmlNode item1st = doc.SelectSingleNode("//item[@id='v1']"); msfs.AddFeatureFromXml(item1st); // now get a simple, top-level closed feature sFile = Path.Combine(sFileDir, "FeatureSystem3.xml"); doc.Load(sFile); XmlNode itemImpfv = doc.SelectSingleNode("//item[@id='vImpfv']"); msfs.AddFeatureFromXml(itemImpfv); XmlNode itemCont = doc.SelectSingleNode("//item[@id='vCont']"); msfs.AddFeatureFromXml(itemCont); using (var dlg = new FeatureSystemInflectionFeatureListDlg()) { ILexEntryInflType cobj = Cache.ServiceLocator.GetInstance <ILexEntryInflTypeFactory>().Create(); lp.LexDbOA.VariantEntryTypesOA.PossibilitiesOS.Add(cobj); dlg.SetDlgInfo(Cache, (Mediator)null, cobj, 0); // load some feature system values into treeview FeatureStructureTreeView tv = dlg.TreeView; Assert.AreEqual(2, tv.Nodes.Count, "Count of top level nodes in tree view"); TreeNodeCollection col = tv.Nodes[0].Nodes; Assert.AreEqual(3, col.Count, "Count of first level nodes in tree view"); } }
private XElement CreateMorphemeElement(Morpheme morpheme) { var msaID = (int?)morpheme.Properties["ID"] ?? 0; IMoMorphSynAnalysis msa; if (msaID == 0 || !m_cache.ServiceLocator.GetInstance <IMoMorphSynAnalysisRepository>().TryGetObject(msaID, out msa)) { return(null); } var inflTypeID = (int?)morpheme.Properties["InflTypeID"] ?? 0; ILexEntryInflType inflType = null; if (inflTypeID != 0 && !m_cache.ServiceLocator.GetInstance <ILexEntryInflTypeRepository>().TryGetObject(inflTypeID, out inflType)) { return(null); } return(HCParser.CreateMorphemeElement(msa, inflType)); }
private void ConvertLexEntryInflType(XmlDocument doc, XmlNode node, ILexEntryInflType lexEntryInflType) { var lexEntryInflTypeNode = CreateXmlElement(doc, "lexEntryInflType", node); var nullTempNode = CreateXmlElement(doc, "alloform", node); nullTempNode.InnerText = "0"; string sNullGloss = null; StringBuilder sbGloss = new StringBuilder(); if (string.IsNullOrEmpty(lexEntryInflType.GlossPrepend.BestAnalysisAlternative.Text)) { sbGloss.Append(lexEntryInflType.GlossPrepend.BestAnalysisAlternative.Text); sbGloss.Append("..."); } sbGloss.Append(lexEntryInflType.GlossAppend.BestAnalysisAlternative.Text); nullTempNode = CreateXmlElement(doc, "gloss", node); nullTempNode.InnerXml = CreateEntities(sbGloss.ToString()); var sMsg = string.Format(ParserUIStrings.ksIrregularlyInflectedFormNullAffix, lexEntryInflType.ShortName); nullTempNode = CreateXmlElement(doc, "citationForm", node); nullTempNode.InnerXml = CreateEntities(sMsg); CreateInflMsaForLexEntryInflType(doc, node, lexEntryInflType); }
private static void WriteInflMsaForLexEntryInflType(XmlWriter writer, string wordType, ILexEntryInflType lexEntryInflType) { IMoInflAffixSlot slot; if (wordType != null) { slot = lexEntryInflType.Services.GetInstance <IMoInflAffixSlotRepository>().GetObject(Convert.ToInt32(wordType)); } else { var slots = lexEntryInflType.SlotsRC; IMoInflAffixSlot firstSlot = slots.FirstOrDefault(); slot = firstSlot; } if (slot != null) { writer.WriteStartElement("inflMsa"); WritePosXmlAttribute(writer, slot.Owner as IPartOfSpeech, "cat"); writer.WriteAttributeString("slot", slot.Hvo.ToString(CultureInfo.InvariantCulture)); writer.WriteAttributeString("slotAbbr", slot.Name.BestAnalysisAlternative.Text); writer.WriteAttributeString("slotOptional", "false"); WriteFeatureStructureNodes(writer, lexEntryInflType.InflFeatsOA, lexEntryInflType.Hvo); writer.WriteEndElement(); //inflMsa } }
/// <summary> /// NOTE: this routine is ignorant of calling context, so caller must provide NoteDependency to the possibleVariant and the sense /// (e.g. vwenv.NoteDependency(new[] { wfiMorphBundle.Hvo }, new[] { WfiMorphBundleTags.kflidSense }, 1); /// vwenv.NoteDependency(new[] { wfiMorphBundle.Hvo }, new[] { WfiMorphBundleTags.kflidInflType }, 1); /// </summary> /// <param name="vwenv"></param> /// <param name="possibleVariant"></param> /// <param name="sense"></param> /// <param name="spec"></param> /// <param name="inflType"></param> /// <returns>true if there was anything to display </returns> internal bool DisplayLexGlossWithInflType(IVwEnv vwenv, ILexEntry possibleVariant, ILexSense sense, InterlinLineSpec spec, ILexEntryInflType inflType) { int iLineChoice = m_lineChoices.IndexOf(spec); ILexEntryRef ler; if (possibleVariant.IsVariantOfSenseOrOwnerEntry(sense, out ler)) { var wsPreferred = GetRealWsOrBestWsForContext(sense.Hvo, spec); var wsGloss = Cache.ServiceLocator.WritingSystemManager.Get(wsPreferred); var wsUser = Cache.ServiceLocator.WritingSystemManager.UserWritingSystem; var testGloss = sense.Gloss.get_String(wsPreferred); // don't bother adding anything for an empty gloss. if (testGloss.Text != null && testGloss.Text.Length >= 0) { vwenv.OpenParagraph(); // see if we have an irregularly inflected form type reference var leitFirst = ler.VariantEntryTypesRS.Where( let => let.ClassID == LexEntryInflTypeTags.kClassId).FirstOrDefault(); // add any GlossPrepend info if (leitFirst != null) { vwenv.OpenInnerPile(); // TODO: add dependency to VariantType GlossPrepend/Append names vwenv.NoteDependency(new[] { ler.Hvo }, new[] { LexEntryRefTags.kflidVariantEntryTypes }, 1); vwenv.OpenParagraph(); ITsString tssPrepend = null; if (inflType != null) { tssPrepend = MorphServices.AddTssGlossAffix(null, inflType.GlossPrepend, wsGloss, wsUser); } else { ITsIncStrBldr sbPrepend; ITsIncStrBldr sbAppend; JoinGlossAffixesOfInflVariantTypes(ler, wsPreferred, out sbPrepend, out sbAppend); if (sbPrepend.Text != null) tssPrepend = sbPrepend.GetString(); } if (tssPrepend != null) vwenv.AddString(tssPrepend); vwenv.CloseParagraph(); vwenv.CloseInnerPile(); } // add gloss of main entry or sense { vwenv.OpenInnerPile(); // NOTE: remember to NoteDependency from OuterObject vwenv.AddObj(sense.Hvo, this, kfragLineChoices + iLineChoice); vwenv.CloseInnerPile(); } // now add variant type info if (leitFirst != null) { vwenv.OpenInnerPile(); // TODO: add dependency to VariantType GlossPrepend/Append names vwenv.NoteDependency(new[] { ler.Hvo }, new[] { LexEntryRefTags.kflidVariantEntryTypes }, 1); vwenv.OpenParagraph(); ITsString tssAppend = null; if (inflType != null) { tssAppend = MorphServices.AddTssGlossAffix(null, inflType.GlossAppend, wsGloss, wsUser); } else { ITsIncStrBldr sbPrepend; ITsIncStrBldr sbAppend; JoinGlossAffixesOfInflVariantTypes(ler, wsPreferred, out sbPrepend, out sbAppend); if (sbAppend.Text != null) tssAppend = sbAppend.GetString(); } { // Use AddProp/DisplayVariant to store GlossAppend with m_tssPendingGlossAffix // this allows InterlinearExporter to know to export a glsAppend item try { if (tssAppend != null) m_tssPendingGlossAffix = tssAppend; else m_tssPendingGlossAffix = m_tssMissingGlossAppend; vwenv.AddProp(ktagGlossAppend, this, 0); } finally { m_tssPendingGlossAffix = null; } } vwenv.CloseParagraph(); vwenv.CloseInnerPile(); } vwenv.CloseParagraph(); return true; } } return false; }
internal static bool TryGetLexGlossWithInflTypeTss(ILexEntry possibleVariant, ILexSense sense, InterlinLineSpec spec, InterlinLineChoices lineChoices, int vernWsContext, ILexEntryInflType inflType, out ITsString result) { FdoCache cache = possibleVariant.Cache; using (var vcLexGlossFrag = new InterlinVc(cache)) { vcLexGlossFrag.LineChoices = lineChoices; vcLexGlossFrag.PreferredVernWs = vernWsContext; result = null; var collector = new TsStringCollectorEnv(null, vcLexGlossFrag.Cache.MainCacheAccessor, possibleVariant.Hvo) { RequestAppendSpaceForFirstWordInNewParagraph = false }; if (vcLexGlossFrag.DisplayLexGlossWithInflType(collector, possibleVariant, sense, spec, inflType)) { result = collector.Result; return true; } return false; } }
private bool GetMorphs(Word ws, out List <MorphInfo> result) { var morphs = new Dictionary <Morpheme, MorphInfo>(); result = new List <MorphInfo>(); foreach (Annotation <ShapeNode> morph in ws.Morphs) { Allomorph allomorph = ws.GetAllomorph(morph); var formID = (int?)allomorph.Properties["ID"] ?? 0; if (formID == 0) { continue; } var formID2 = (int?)allomorph.Properties["ID2"] ?? 0; string formStr = ws.Shape.GetNodes(morph.Span).ToString(ws.Stratum.CharacterDefinitionTable, false); int curFormID; MorphInfo morphInfo; if (!morphs.TryGetValue(allomorph.Morpheme, out morphInfo)) { curFormID = formID; } else if (formID2 > 0) { // circumfix curFormID = formID2; } else { morphInfo.String += formStr; continue; } IMoForm form; if (!m_cache.ServiceLocator.GetInstance <IMoFormRepository>().TryGetObject(curFormID, out form)) { result = null; return(false); } var msaID = (int)allomorph.Morpheme.Properties["ID"]; IMoMorphSynAnalysis msa; if (!m_cache.ServiceLocator.GetInstance <IMoMorphSynAnalysisRepository>().TryGetObject(msaID, out msa)) { result = null; return(false); } var inflTypeID = (int?)allomorph.Morpheme.Properties["InflTypeID"] ?? 0; ILexEntryInflType inflType = null; if (inflTypeID > 0 && !m_cache.ServiceLocator.GetInstance <ILexEntryInflTypeRepository>().TryGetObject(inflTypeID, out inflType)) { result = null; return(false); } morphInfo = new MorphInfo { Form = form, String = formStr, Msa = msa, InflType = inflType, IsCircumfix = formID2 > 0 }; morphs[allomorph.Morpheme] = morphInfo; switch ((form.MorphTypeRA == null ? Guid.Empty : form.MorphTypeRA.Guid).ToString()) { case MoMorphTypeTags.kMorphInfix: case MoMorphTypeTags.kMorphInfixingInterfix: if (result.Count == 0) { result.Add(morphInfo); } else { result.Insert(result.Count - 1, morphInfo); } break; default: result.Add(morphInfo); break; } } return(true); }
private static void WriteLexEntryInflTypeElement(XmlWriter writer, string wordType, ILexEntryInflType lexEntryInflType) { writer.WriteStartElement("lexEntryInflType"); writer.WriteEndElement(); writer.WriteElementString("alloform", "0"); string sNullGloss = null; var sbGloss = new StringBuilder(); if (string.IsNullOrEmpty(lexEntryInflType.GlossPrepend.BestAnalysisAlternative.Text)) { sbGloss.Append(lexEntryInflType.GlossPrepend.BestAnalysisAlternative.Text); sbGloss.Append("..."); } sbGloss.Append(lexEntryInflType.GlossAppend.BestAnalysisAlternative.Text); writer.WriteElementString("gloss", sbGloss.ToString()); var sMsg = string.Format(ParserCoreStrings.ksIrregularlyInflectedFormNullAffix, lexEntryInflType.ShortName); writer.WriteElementString("citationForm", sMsg); WriteInflMsaForLexEntryInflType(writer, wordType, lexEntryInflType); }
/// <summary> /// Update the sandbox cache to reflect a choice of the real MoForm and the /// entry indicated by the FdoCache hvos passed. /// </summary> internal void UpdateMorphEntry(IMoForm moFormReal, ILexEntry entryReal, ILexSense senseReal, ILexEntryInflType inflType = null) { CheckDisposed(); bool fDirty = m_sandbox.Caches.DataAccess.IsDirty(); bool fApproved = !m_sandbox.UsingGuess; bool fHasApprovedWordGloss = m_sandbox.HasWordGloss() && (fDirty || fApproved); bool fHasApprovedWordCat = m_sandbox.HasWordCat() && (fDirty || fApproved); var undoAction = new UpdateMorphEntryAction(m_sandbox, m_hvoMorph); // before changes. // Make a new morph, if one does not already exist, corresponding to the // selected item. Its form must match what is already displayed. Store it as // the new value. int hvoMorph = m_sandbox.CreateSecondaryAndCopyStrings(InterlinLineChoices.kflidMorphemes, moFormReal.Hvo, MoFormTags.kflidForm); m_caches.DataAccess.SetObjProp(m_hvoMorph, ktagSbMorphForm, hvoMorph); m_caches.DataAccess.PropChanged(m_rootb, (int)PropChangeType.kpctNotifyAll, m_hvoMorph, ktagSbMorphForm, 0, 1, 1); // Try to establish the sense. Call this before SetSelectedEntry and LoadSecDataForEntry. // reset cached gloss, since we should establish the sense according to the real sense or real entry. m_caches.DataAccess.SetObjProp(m_hvoMorph, ktagSbMorphGloss, 0); var morphEntry = moFormReal.Owner as ILexEntry; ILexSense realDefaultSense = m_sandbox.EstablishDefaultSense(m_hvoMorph, morphEntry, senseReal, inflType); // Make and install a secondary object to correspond to the real LexEntry. // (The zero says we are not guessing any more, since the user selected this entry.) m_sandbox.LoadSecDataForEntry(morphEntry, senseReal != null ? senseReal : realDefaultSense, m_hvoSbWord, m_caches.DataAccess as IVwCacheDa, m_wsVern, m_hvoMorph, 0, m_caches.MainCache.MainCacheAccessor, null); m_caches.DataAccess.PropChanged(m_rootb, (int)PropChangeType.kpctNotifyAll, m_hvoMorph, ktagSbMorphEntry, 0, 1, WasReal()); // Notify any delegates that the selected Entry changed. m_sandbox.SetSelectedEntry(entryReal); // fHasApprovedWordGloss: if an approved word gloss already exists -- don't replace it // fHasApprovedWordCat: if an approved word category already exists -- don't replace it CopyLexEntryInfoToMonomorphemicWordGlossAndPos(!fHasApprovedWordGloss, !fHasApprovedWordCat); undoAction.GetNewVals(); // If we're doing this as part of something undoable, and then undo it, we should undo this also, // especially so the Sandbox isn't left displaying something whose creation has been undone. (FWR-3547) if (m_caches.MainCache.ActionHandlerAccessor.CurrentDepth > 0) { m_caches.MainCache.ActionHandlerAccessor.AddAction(undoAction); } return; }
/// <summary> /// /// </summary> /// <param name="hvoMorph">IMoForm (e.g. wmb.MorphRA)</param> /// <param name="hvoMainEntryOfVariant">for variant specs, this is hvoMorph's Entry.VariantEntryRef.ComponentLexeme target, 0 otherwise</param> /// <param name="tssName"></param> /// <param name="hvoSense">ILexSense (e.g. wmb.SensaRA)</param> /// <param name="nameSense"></param> /// <param name="hvoMsa">IMoMorphSynAnalysis (e.g. wmb.MsaRA)</param> /// <param name="nameMsa"></param> public MorphItem(int hvoMorph, int hvoMainEntryOfVariant, ITsString tssName, int hvoSense, string nameSense, int hvoMsa, string nameMsa) { m_hvoMorph = hvoMorph; m_hvoMainEntryOfVariant = hvoMainEntryOfVariant; m_name = tssName; m_hvoSense = hvoSense; m_nameSense = nameSense; m_hvoMsa = hvoMsa; m_nameMsa = nameMsa; m_inflType = null; m_entryRef = null; }
public void LexEntryInflTypeAnalysisWithNullForSlotFiller() { IWfiWordform brubs = CheckAnalysisSize("brubsTEST", 0, true); ILexDb ldb = Cache.LanguageProject.LexDbOA; ParseResult result = null; UndoableUnitOfWorkHelper.Do("Undo stuff", "Redo stuff", m_actionHandler, () => { // Verb brub which is a present tense irregularly inflected form of 'believe' // with automatically generated null Tense slot and an -s Plural Number slot filler // (This is not supposed to be English, in case you're wondering....) ILexEntryInflType presentTenseLexEntryInflType = m_lexEntryInflTypeFactory.Create(); Cache.LangProject.LexDbOA.VariantEntryTypesOA.PossibilitiesOS.Add(presentTenseLexEntryInflType); ILexEntry believeV = m_entryFactory.Create(); IMoStemAllomorph believeVForm = m_stemAlloFactory.Create(); believeV.AlternateFormsOS.Add(believeVForm); believeVForm.Form.VernacularDefaultWritingSystem = Cache.TsStrFactory.MakeString("believeVTEST", m_vernacularWS.Handle); IMoStemMsa believeVMsa = m_stemMsaFactory.Create(); believeV.MorphoSyntaxAnalysesOC.Add(believeVMsa); ILexSense believeVSense = m_senseFactory.Create(); believeV.SensesOS.Add(believeVSense); believeVSense.MorphoSyntaxAnalysisRA = believeVMsa; ILexEntry brubV = m_entryFactory.Create(); IMoStemAllomorph brubVForm = m_stemAlloFactory.Create(); brubV.AlternateFormsOS.Add(brubVForm); brubVForm.Form.VernacularDefaultWritingSystem = Cache.TsStrFactory.MakeString("brubVTEST", m_vernacularWS.Handle); ILexEntryRef lexEntryref = m_lexEntryRefFactory.Create(); brubV.EntryRefsOS.Add(lexEntryref); lexEntryref.ComponentLexemesRS.Add(believeV); lexEntryref.VariantEntryTypesRS.Add(presentTenseLexEntryInflType); ILexEntry nullPresent = m_entryFactory.Create(); IMoAffixAllomorph nullPresentForm = m_afxAlloFactory.Create(); nullPresent.AlternateFormsOS.Add(nullPresentForm); nullPresentForm.Form.VernacularDefaultWritingSystem = Cache.TsStrFactory.MakeString("nullPRESENTTEST", m_vernacularWS.Handle); IMoInflAffMsa nullPresentMsa = m_inflAffMsaFactory.Create(); nullPresent.MorphoSyntaxAnalysesOC.Add(nullPresentMsa); ILexEntry sPlural = m_entryFactory.Create(); IMoAffixAllomorph sPluralForm = m_afxAlloFactory.Create(); sPlural.AlternateFormsOS.Add(sPluralForm); sPluralForm.Form.VernacularDefaultWritingSystem = Cache.TsStrFactory.MakeString("sPLURALTEST", m_vernacularWS.Handle); IMoInflAffMsa sPluralMsa = m_inflAffMsaFactory.Create(); sPlural.MorphoSyntaxAnalysesOC.Add(sPluralMsa); result = new ParseResult(new[] { new ParseAnalysis(new[] { new ParseMorph(brubVForm, MorphServices.GetMainOrFirstSenseOfVariant(brubV.EntryRefsOS[0]).MorphoSyntaxAnalysisRA, (ILexEntryInflType)brubV.EntryRefsOS[0].VariantEntryTypesRS[0]), new ParseMorph(sPluralForm, sPluralMsa) }) }); }); m_filer.ProcessParse(brubs, ParserPriority.Low, result); ExecuteIdleQueue(); CheckAnalysisSize("brubsTEST", 1, false); var analysis = brubs.AnalysesOC.ElementAt(0); Assert.AreEqual(2, analysis.MorphBundlesOS.Count, "Expected only 2 morphs in the analysis"); var morphBundle = analysis.MorphBundlesOS.ElementAt(0); Assert.IsNotNull(morphBundle.Form, "First bundle: form is not null"); Assert.IsNotNull(morphBundle.MsaRA, "First bundle: msa is not null"); Assert.IsNotNull(morphBundle.InflTypeRA, "First bundle: infl type is not null"); }
/// <summary> /// Given that we have made hvoEntryReal the lex entry for the (sandbox) morpheme /// hvoMorph, look for the sense given by hvoSenseReal and fill it in. /// </summary> /// <param name="hvoMorph">the sandbox id of the Morph object</param> /// <param name="entryReal">the real database id of the lex entry</param> /// <param name="senseReal"> /// The real database id of the sense to use. If zero, use the first sense of the entry /// (if there is one) as a default. /// </param> /// <param name="inflType"></param> /// <returns>default (real) sense if we found one, null otherwise.</returns> private ILexSense EstablishDefaultSense(int hvoMorph, ILexEntry entryReal, ILexSense senseReal, ILexEntryInflType inflType) { CheckDisposed(); ILexSense variantSense = null; // If the entry has no sense we can't do anything. if (entryReal.SensesOS.Count == 0) { if (senseReal != null) { //if ((entryReal as ILexEntry).IsVariantOfSenseOrOwnerEntry(senseReal, out ler)) variantSense = senseReal; } else { variantSense = GetSenseForVariantIfPossible(entryReal); } if (variantSense == null) return null; // nothing useful we can do. } // If we already have a gloss for this entry, don't overwrite it with a default. int hvoMorphGloss = m_caches.DataAccess.get_ObjectProp(hvoMorph, ktagSbMorphGloss); if (hvoMorphGloss != 0 && entryReal.Hvo == m_hvoLastSelEntry && senseReal == null) return null; ILexSense defSenseReal; if (variantSense != null) defSenseReal = variantSense; else { if (senseReal == null) defSenseReal = entryReal.SensesOS[0]; else defSenseReal = senseReal; } int hvoDefSense; if (variantSense != null && defSenseReal == variantSense) { hvoDefSense = m_caches.FindOrCreateSec(defSenseReal.Hvo, kclsidSbNamedObj, kSbWord, ktagSbWordDummy); var cda = (IVwCacheDa)m_caches.DataAccess; int wsVern = RawWordformWs; CacheLexGlossWithInflTypeForAllCurrentWs(entryReal, hvoDefSense, wsVern, cda, inflType); int hvoInflType = 0; if (inflType != null) hvoInflType = m_caches.FindOrCreateSec(inflType.Hvo, kclsidSbNamedObj, kSbWord, ktagSbWordDummy); cda.CacheObjProp(hvoMorph, ktagSbNamedObjInflType, hvoInflType); m_caches.DataAccess.PropChanged(m_rootb, (int)PropChangeType.kpctNotifyAll, hvoMorph, ktagSbNamedObjInflType, 0, 1, 0); } else { // add normal LexGloss without variant info hvoDefSense = CreateSecondaryAndCopyStrings(InterlinLineChoices.kflidLexGloss, defSenseReal.Hvo, LexSenseTags.kflidGloss); } // We're guessing the gloss if we just took the first sense, but if the user chose // one it is definite. m_caches.DataAccess.SetInt(hvoDefSense, ktagSbNamedObjGuess, senseReal == null ? 1 : 0); m_caches.DataAccess.SetObjProp(hvoMorph, ktagSbMorphGloss, hvoDefSense); m_caches.DataAccess.PropChanged(m_rootb, (int)PropChangeType.kpctNotifyAll, hvoMorph, ktagSbMorphGloss, 0, 1, 0); // Now if the sense has an MSA, set that up as a default too. var defMsaReal = defSenseReal.MorphoSyntaxAnalysisRA; int cOldMsa = 0; if (m_caches.DataAccess.get_ObjectProp(hvoMorph, ktagSbMorphPos) != 0) cOldMsa = 1; if (defMsaReal != null) { int hvoNewPos = m_caches.FindOrCreateSec(defMsaReal.Hvo, kclsidSbNamedObj, kSbWord, ktagSbWordDummy); foreach (int ws in m_choices.WritingSystemsForFlid(InterlinLineChoices.kflidLexPos, true)) { // Since ws maybe ksFirstAnal/ksFirstVern, we need to get what is actually // used in order to retrieve the data in Vc.Display(). See LT_7976. ITsString tssNew = defMsaReal.InterlinAbbrTSS(ws); int wsActual = TsStringUtils.GetWsAtOffset(tssNew, 0); m_caches.DataAccess.SetMultiStringAlt(hvoNewPos, ktagSbNamedObjName, wsActual, tssNew); } m_caches.DataAccess.SetInt(hvoNewPos, ktagSbNamedObjGuess, senseReal == null ? 1 : 0); m_caches.DataAccess.SetObjProp(hvoMorph, ktagSbMorphPos, hvoNewPos); m_caches.DataAccess.PropChanged(m_rootb, (int)PropChangeType.kpctNotifyAll, hvoMorph, ktagSbMorphPos, 0, 1, cOldMsa); } else { // Going to null MSA, we still need to record the value and propagate the // change! See LT-4246. m_caches.DataAccess.SetObjProp(hvoMorph, ktagSbMorphPos, 0); m_caches.DataAccess.PropChanged(m_rootb, (int)PropChangeType.kpctNotifyAll, hvoMorph, ktagSbMorphPos, 0, 0, cOldMsa); } return defSenseReal; }
private void CacheLexGlossWithInflTypeForAllCurrentWs(ILexEntry possibleVariant, int hvoLexSenseSec, int wsVern, IVwCacheDa cda, ILexEntryInflType inflType) { IList<int> currentAnalysisWsList = m_caches.MainCache.ServiceLocator.WritingSystems.CurrentAnalysisWritingSystems.Select(wsObj => wsObj.Handle).ToArray(); CacheStringAltForAllCurrentWs(currentAnalysisWsList, cda, hvoLexSenseSec, ktagSbNamedObjName, delegate(int wsLexGloss) { var hvoSenseReal = m_caches.RealHvo(hvoLexSenseSec); var sense = Cache.ServiceLocator.GetInstance<ILexSenseRepository>().GetObject(hvoSenseReal); var spec = m_choices.CreateSpec(InterlinLineChoices.kflidLexGloss, wsLexGloss); var choices = new InterlinLineChoices(Cache, m_choices.m_wsDefVern, m_choices.m_wsDefAnal); choices.Add(spec); ITsString tssResult; return InterlinVc.TryGetLexGlossWithInflTypeTss(possibleVariant, sense, spec, choices, wsVern, inflType, out tssResult) ? tssResult : null; }); }
internal static XElement CreateMorphemeElement(IMoMorphSynAnalysis msa, ILexEntryInflType inflType) { var msaElem = new XElement("Morpheme", new XAttribute("id", msa.Hvo)); switch (msa.ClassID) { case MoStemMsaTags.kClassId: var stemMsa = (IMoStemMsa)msa; msaElem.Add(new XAttribute("type", "stem")); if (stemMsa.PartOfSpeechRA != null) { msaElem.Add(new XElement("Category", stemMsa.PartOfSpeechRA.Abbreviation.BestAnalysisAlternative.Text)); } if (stemMsa.FromPartsOfSpeechRC.Count > 0) { msaElem.Add(new XElement("FromCategories", stemMsa.FromPartsOfSpeechRC.Select(pos => new XElement("Category", pos.Abbreviation.BestAnalysisAlternative.Text)))); } if (stemMsa.InflectionClassRA != null) { msaElem.Add(new XElement("InflClass", stemMsa.InflectionClassRA.Abbreviation.BestAnalysisAlternative.Text)); } break; case MoDerivAffMsaTags.kClassId: var derivMsa = (IMoDerivAffMsa)msa; msaElem.Add(new XAttribute("type", "deriv")); if (derivMsa.FromPartOfSpeechRA != null) { msaElem.Add(new XElement("FromCategory", derivMsa.FromPartOfSpeechRA.Abbreviation.BestAnalysisAlternative.Text)); } if (derivMsa.ToPartOfSpeechRA != null) { msaElem.Add(new XElement("ToCategory", derivMsa.ToPartOfSpeechRA.Abbreviation.BestAnalysisAlternative.Text)); } if (derivMsa.ToInflectionClassRA != null) { msaElem.Add(new XElement("ToInflClass", derivMsa.ToInflectionClassRA.Abbreviation.BestAnalysisAlternative.Text)); } break; case MoUnclassifiedAffixMsaTags.kClassId: var unclassMsa = (IMoUnclassifiedAffixMsa)msa; msaElem.Add(new XAttribute("type", "unclass")); if (unclassMsa.PartOfSpeechRA != null) { msaElem.Add(new XElement("Category", unclassMsa.PartOfSpeechRA.Abbreviation.BestAnalysisAlternative.Text)); } break; case MoInflAffMsaTags.kClassId: var inflMsa = (IMoInflAffMsa)msa; msaElem.Add(new XAttribute("type", "infl")); if (inflMsa.PartOfSpeechRA != null) { msaElem.Add(new XElement("Category", inflMsa.PartOfSpeechRA.Abbreviation.BestAnalysisAlternative.Text)); } if (inflMsa.SlotsRC.Count > 0) { IMoInflAffixSlot slot = inflMsa.SlotsRC.First(); msaElem.Add(new XElement("Slot", new XAttribute("optional", slot.Optional), slot.Name.BestAnalysisAlternative.Text)); } break; } msaElem.Add(new XElement("HeadWord", msa.OwnerOfClass <ILexEntry>().HeadWord.Text)); var glossSB = new StringBuilder(); if (inflType != null) { string prepend = inflType.GlossPrepend.BestAnalysisAlternative.Text; if (prepend != "***") { glossSB.Append(prepend); } } ILexSense sense = msa.OwnerOfClass <ILexEntry>().SenseWithMsa(msa); glossSB.Append(sense == null ? ParserCoreStrings.ksQuestions : sense.Gloss.BestAnalysisAlternative.Text); if (inflType != null) { string append = inflType.GlossAppend.BestAnalysisAlternative.Text; if (append != "***") { glossSB.Append(append); } } msaElem.Add(new XElement("Gloss", glossSB.ToString())); return(msaElem); }
internal static XElement CreateAllomorphElement(string name, IMoForm form, IMoMorphSynAnalysis msa, ILexEntryInflType inflType, bool circumfix) { Guid morphTypeGuid = circumfix ? MoMorphTypeTags.kguidMorphCircumfix : (form.MorphTypeRA == null ? Guid.Empty : form.MorphTypeRA.Guid); var elem = new XElement(name, new XAttribute("id", form.Hvo), new XAttribute("type", GetMorphTypeString(morphTypeGuid)), new XElement("Form", circumfix ? form.OwnerOfClass <ILexEntry>().HeadWord.Text : form.GetFormWithMarkers(form.Cache.DefaultVernWs)), new XElement("LongName", form.LongName)); elem.Add(CreateMorphemeElement(msa, inflType)); return(elem); }
public MorphItem(MorphItemOptions options) : this(options.HvoMoForm, options.HvoEntry, options.TssName, options.HvoSense, options.SenseName, options.HvoMsa, options.MsaName) { m_inflType = options.InflType; m_entryRef = options.EntryRef; if (m_entryRef != null) { var entry = GetMainEntryOfVariant(m_entryRef); m_hvoMainEntryOfVariant = entry.Hvo; } }
public ParseMorph(IMoForm form, IMoMorphSynAnalysis msa, ILexEntryInflType inflType) { m_form = form; m_msa = msa; m_inflType = inflType; }
private static MorphItem GetMorphItem(IMoForm mf, ITsString tssName, ILexSense sense, ITsString tssSense, ILexEntryRef ler, int hvoLexEntry, ILexEntryInflType inflType) { IMoMorphSynAnalysis msa = null; string msaText = null; if (sense != null) { msa = sense.MorphoSyntaxAnalysisRA; if (msa != null) msaText = msa.InterlinearName; } var options = new MorphItemOptions { HvoMoForm = HvoOrZero(mf), HvoEntry = ler != null ? hvoLexEntry : 0, TssName = tssName, HvoSense = HvoOrZero(sense), SenseName = tssSense != null ? tssSense.Text : null, HvoMsa = HvoOrZero(msa), MsaName = msaText, InflType = inflType, EntryRef = ler, }; return new MorphItem(options); }
private void ExportLexEntryInflTypeFields(TextWriter w, ILexEntryInflType item) { if (item == null) return; ExportMultiUnicode(w, item.ReverseAbbr); ExportMultiUnicode(w, item.GlossAppend); }
private static void WriteInflMsaForLexEntryInflType(XmlWriter writer, string wordType, ILexEntryInflType lexEntryInflType) { IMoInflAffixSlot slot; if (wordType != null) { slot = lexEntryInflType.Services.GetInstance<IMoInflAffixSlotRepository>().GetObject(Convert.ToInt32(wordType)); } else { var slots = lexEntryInflType.SlotsRC; IMoInflAffixSlot firstSlot = slots.FirstOrDefault(); slot = firstSlot; } if (slot != null) { writer.WriteStartElement("inflMsa"); WritePosXmlAttribute(writer, slot.Owner as IPartOfSpeech, "cat"); writer.WriteAttributeString("slot", slot.Hvo.ToString(CultureInfo.InvariantCulture)); writer.WriteAttributeString("slotAbbr", slot.Name.BestAnalysisAlternative.Text); writer.WriteAttributeString("slotOptional", "false"); WriteFeatureStructureNodes(writer, lexEntryInflType.InflFeatsOA, lexEntryInflType.Hvo); writer.WriteEndElement(); //inflMsa } }
/// <summary> /// Handle launching of the LexEntryInflType features editor. /// </summary> protected override void HandleChooser() { VectorReferenceLauncher vrl = null; using (FeatureSystemInflectionFeatureListDlg dlg = new FeatureSystemInflectionFeatureListDlg()) { IFsFeatStruc originalFs = m_obj as IFsFeatStruc; Slice parentSlice = Slice; if (originalFs == null) { int owningFlid; ILexEntryInflType leit = parentSlice.Object as ILexEntryInflType; owningFlid = (parentSlice as FeatureSystemInflectionFeatureListDlgLauncherSlice).Flid; dlg.SetDlgInfo(m_cache, m_mediator, m_propertyTable, leit, owningFlid); } else { dlg.SetDlgInfo(m_cache, m_mediator, m_propertyTable, originalFs, (parentSlice as FeatureSystemInflectionFeatureListDlgLauncherSlice).Flid); } const string ksPath = "/group[@id='Linguistics']/group[@id='Morphology']/group[@id='FeatureChooser']/"; dlg.Text = StringTable.Table.GetStringWithXPath("InflectionFeatureTitle", ksPath); dlg.Prompt = StringTable.Table.GetStringWithXPath("InflectionFeaturesPrompt", ksPath); dlg.LinkText = StringTable.Table.GetStringWithXPath("InflectionFeaturesLink", ksPath); DialogResult result = dlg.ShowDialog(parentSlice.FindForm()); if (result == DialogResult.OK) { if (dlg.FS != null) { m_obj = dlg.FS; } m_msaInflectionFeatureListDlgLauncherView.Init(m_cache, dlg.FS); } else if (result == DialogResult.Yes) { /* * // Get the VectorReferenceLauncher for the Inflection Features slice. * // Since we're not changing tools, we want to change the chooser dialog. * // See LT-5913 for motivation. * Control ctl = this.Parent; * while (ctl != null && !(ctl is Slice)) * ctl = ctl.Parent; * Slice slice = ctl as Slice; * if (slice != null) * { * DataTree dt = slice.ContainingDataTree; * for (int i = 0; i < dt.Slices.Count; ++i) * { * Slice sliceT = dt.FieldOrDummyAt(i); * vrl = sliceT.Control as VectorReferenceLauncher; * if (vrl != null) * { * if (vrl.Flid == PartOfSpeechTags.kflidInflectableFeats) * break; * vrl = null; * } * } * } * if (vrl == null) * { * // We do, too, need to change tools! Sometimes this slice shows up in a different context, * // such as the main data entry view. See LT-7167. * // go to m_highestPOS in editor * // TODO: this should be reviewed by someone who knows how these links should be done * // I'm just guessing. * // Also, is there some way to know the application name and tool name without hard coding them? */ var linkJump = new FwLinkArgs("featuresAdvancedEdit", m_cache.LanguageProject.MsFeatureSystemOA.Guid); m_mediator.PostMessage("FollowLink", linkJump); /*} * else * { * vrl.HandleExternalChooser(); * }*/ } } }
protected void CreateInflMsaForLexEntryInflType(XmlDocument doc, XmlNode node, ILexEntryInflType lexEntryInflType) { /*var slots = lexEntryInflType.SlotsRC; * IMoInflAffixSlot firstSlot = null; * foreach (var slot in slots) * { * if (firstSlot == null) * firstSlot = slot; * }*/ IMoInflAffixSlot slot; var slotId = node.SelectSingleNode("MoForm/@wordType"); if (slotId != null) { slot = m_cache.ServiceLocator.GetInstance <IMoInflAffixSlotRepository>().GetObject(Convert.ToInt32(slotId.InnerText)); } else { var slots = lexEntryInflType.SlotsRC; IMoInflAffixSlot firstSlot = null; foreach (var slot1 in slots) // there's got to be a better way to do this... { firstSlot = slot1; break; } slot = firstSlot; } XmlNode nullInflMsaNode; nullInflMsaNode = CreateXmlElement(doc, "inflMsa", node); CreatePOSXmlAttribute(doc, nullInflMsaNode, slot.Owner as IPartOfSpeech, "cat"); CreateXmlAttribute(doc, "slot", slot.Hvo.ToString(), nullInflMsaNode); CreateXmlAttribute(doc, "slotAbbr", slot.Name.BestAnalysisAlternative.Text, nullInflMsaNode); CreateXmlAttribute(doc, "slotOptional", "false", nullInflMsaNode); CreateFeatureStructureNodes(doc, nullInflMsaNode, lexEntryInflType.InflFeatsOA, lexEntryInflType.Hvo); }
public void LexEntryInflTypeTwoAnalyses() { IWfiWordform creb = CheckAnalysisSize("crebTEST", 0, true); ILexDb ldb = Cache.LanguageProject.LexDbOA; ParseResult result = null; UndoableUnitOfWorkHelper.Do("Undo stuff", "Redo stuff", m_actionHandler, () => { // Verb creb which is a past tense, plural irregularly inflected form of 'believe' and also 'seek' // with automatically generated null Tense slot and an automatically generated null Number slot filler // (This is not supposed to be English, in case you're wondering....) ILexEntryInflType pastTenseLexEntryInflType = m_lexEntryInflTypeFactory.Create(); ILexEntryInflType pluralTenseLexEntryInflType = m_lexEntryInflTypeFactory.Create(); Cache.LangProject.LexDbOA.VariantEntryTypesOA.PossibilitiesOS.Add(pastTenseLexEntryInflType); Cache.LangProject.LexDbOA.VariantEntryTypesOA.PossibilitiesOS.Add(pluralTenseLexEntryInflType); ILexEntry believeV = m_entryFactory.Create(); IMoStemAllomorph believeVForm = m_stemAlloFactory.Create(); believeV.AlternateFormsOS.Add(believeVForm); believeVForm.Form.VernacularDefaultWritingSystem = TsStringUtils.MakeString("believeVTEST", m_vernacularWS.Handle); IMoStemMsa believeVMsa = m_stemMsaFactory.Create(); believeV.MorphoSyntaxAnalysesOC.Add(believeVMsa); ILexSense believeVSense = m_senseFactory.Create(); believeV.SensesOS.Add(believeVSense); believeVSense.MorphoSyntaxAnalysisRA = believeVMsa; ILexEntry seekV = m_entryFactory.Create(); IMoStemAllomorph seekVForm = m_stemAlloFactory.Create(); believeV.AlternateFormsOS.Add(seekVForm); seekVForm.Form.VernacularDefaultWritingSystem = TsStringUtils.MakeString("seekVTEST", m_vernacularWS.Handle); IMoStemMsa seekVMsa = m_stemMsaFactory.Create(); seekV.MorphoSyntaxAnalysesOC.Add(seekVMsa); ILexSense seekVSense = m_senseFactory.Create(); seekV.SensesOS.Add(seekVSense); seekVSense.MorphoSyntaxAnalysisRA = seekVMsa; ILexEntry crebV = m_entryFactory.Create(); IMoStemAllomorph crebVForm = m_stemAlloFactory.Create(); crebV.AlternateFormsOS.Add(crebVForm); crebVForm.Form.VernacularDefaultWritingSystem = TsStringUtils.MakeString("crebVTEST", m_vernacularWS.Handle); ILexEntryRef lexEntryref = m_lexEntryRefFactory.Create(); crebV.EntryRefsOS.Add(lexEntryref); lexEntryref.ComponentLexemesRS.Add(believeV); lexEntryref.VariantEntryTypesRS.Add(pastTenseLexEntryInflType); lexEntryref.VariantEntryTypesRS.Add(pluralTenseLexEntryInflType); lexEntryref = m_lexEntryRefFactory.Create(); crebV.EntryRefsOS.Add(lexEntryref); lexEntryref.ComponentLexemesRS.Add(seekV); lexEntryref.VariantEntryTypesRS.Add(pastTenseLexEntryInflType); lexEntryref.VariantEntryTypesRS.Add(pluralTenseLexEntryInflType); ILexEntry nullPast = m_entryFactory.Create(); IMoAffixAllomorph nullPastForm = m_afxAlloFactory.Create(); nullPast.AlternateFormsOS.Add(nullPastForm); nullPastForm.Form.VernacularDefaultWritingSystem = TsStringUtils.MakeString("nullPASTTEST", m_vernacularWS.Handle); IMoInflAffMsa nullPastMsa = m_inflAffMsaFactory.Create(); nullPast.MorphoSyntaxAnalysesOC.Add(nullPastMsa); ILexEntry nullPlural = m_entryFactory.Create(); IMoAffixAllomorph nullPluralForm = m_afxAlloFactory.Create(); nullPlural.AlternateFormsOS.Add(nullPluralForm); nullPluralForm.Form.VernacularDefaultWritingSystem = TsStringUtils.MakeString("nullPLURALTEST", m_vernacularWS.Handle); IMoInflAffMsa nullPluralMsa = m_inflAffMsaFactory.Create(); nullPlural.MorphoSyntaxAnalysesOC.Add(nullPluralMsa); result = new ParseResult(new[] { new ParseAnalysis(new[] { new ParseMorph(crebVForm, MorphServices.GetMainOrFirstSenseOfVariant(crebV.EntryRefsOS[1]).MorphoSyntaxAnalysisRA, (ILexEntryInflType)crebV.EntryRefsOS[1].VariantEntryTypesRS[0]) }), new ParseAnalysis(new[] { new ParseMorph(crebVForm, MorphServices.GetMainOrFirstSenseOfVariant(crebV.EntryRefsOS[0]).MorphoSyntaxAnalysisRA, (ILexEntryInflType)crebV.EntryRefsOS[0].VariantEntryTypesRS[0]) }) }); }); m_filer.ProcessParse(creb, ParserPriority.Low, result); ExecuteIdleQueue(); CheckAnalysisSize("crebTEST", 2, false); foreach (var analysis in creb.AnalysesOC) { Assert.AreEqual(1, analysis.MorphBundlesOS.Count, "Expected only 1 morph in the analysis"); var morphBundle = analysis.MorphBundlesOS.ElementAt(0); Assert.IsNotNull(morphBundle.Form, "First bundle: form is not null"); Assert.IsNotNull(morphBundle.MsaRA, "First bundle: msa is not null"); Assert.IsNotNull(morphBundle.InflTypeRA, "First bundle: infl type is not null"); } }