public bool OnConvertAllomorph(object cmd) { Command command = cmd as Command; int toClsid = (int)m_dataEntryForm.Cache.MetaDataCacheAccessor.GetClassId(command.GetParameter("toClassName")); ILexEntry entry = m_dataEntryForm.Root as ILexEntry; Slice slice = m_dataEntryForm.CurrentSlice; IMoForm allomorph = slice.Object as IMoForm; if (entry != null && allomorph != null && toClsid != 0) { if (CheckForFormDataLoss(allomorph, toClsid)) { Form mainWindow = (Form)m_mediator.PropertyTable.GetValue("window"); IMoForm newForm = null; using (new WaitCursor(mainWindow)) { using (UndoRedoCommandHelper undoRedoTask = new UndoRedoCommandHelper(m_dataEntryForm.Cache, cmd as Command)) { newForm = CreateNewForm(toClsid); entry.ReplaceMoForm(allomorph, newForm); } m_dataEntryForm.RefreshList(false); } SelectNewFormSlice(newForm); } } return(true); }
private static void WriteInflectionClasses(XmlWriter writer, FdoCache fdoCache, int allomorphHvo) { if (allomorphHvo <= 0) { return; } // use IMoForm instead of IMoAffixForm or IMoAffixAllomorph because it could be an IMoStemAllomorph IMoForm form = fdoCache.ServiceLocator.GetInstance <IMoFormRepository>().GetObject(allomorphHvo); if (form == null) { return; } if (!(form is IMoAffixForm)) { return; } foreach (IMoInflClass ic in ((IMoAffixForm)form).InflectionClassesRC) { writer.WriteStartElement("inflectionClass"); writer.WriteAttributeString("id", ic.Hvo.ToString(CultureInfo.InvariantCulture)); writer.WriteAttributeString("abbr", ic.Abbreviation.BestAnalysisAlternative.Text); writer.WriteEndElement(); //inflectionClass } }
public bool OnConvertLexemeForm(object cmd) { var command = cmd as Command; var toClsid = m_dataEntryForm.Cache.MetaDataCacheAccessor.GetClassId(command.GetParameter("toClassName")); var entry = m_dataEntryForm.Root as ILexEntry; if (entry != null) { if (CheckForFormDataLoss(entry.LexemeFormOA, toClsid)) { var mainWindow = m_propertyTable.GetValue <Form>("window"); IMoForm newForm = null; using (new WaitCursor(mainWindow)) { UndoableUnitOfWorkHelper.Do(command.UndoText, command.RedoText, entry, () => { newForm = CreateNewForm(entry, toClsid); entry.ReplaceMoForm(entry.LexemeFormOA, newForm); }); m_dataEntryForm.RefreshList(false); } SelectNewFormSlice(newForm); } } return(true); }
public EmptyWwfInfo(IMoForm form, IMoMorphSynAnalysis msa, IPartOfSpeech pos, ILexSense sense) { Form = form; Msa = msa; Pos = pos; Sense = sense; }
public bool OnConvertAllomorph(object cmd) { var command = cmd as Command; int toClsid = (int)m_dataEntryForm.Cache.MetaDataCacheAccessor.GetClassId(command.GetParameter("toClassName")); var entry = m_dataEntryForm.Root as ILexEntry; var slice = m_dataEntryForm.CurrentSlice; var allomorph = slice.Object as IMoForm; if (entry != null && allomorph != null && toClsid != 0) { if (CheckForFormDataLoss(allomorph, toClsid)) { var mainWindow = (Form)m_mediator.PropertyTable.GetValue("window"); IMoForm newForm = null; using (new WaitCursor(mainWindow)) { UndoableUnitOfWorkHelper.Do(command.UndoText, command.RedoText, entry, () => { newForm = CreateNewForm(entry, toClsid); entry.ReplaceMoForm(allomorph, newForm); }); m_dataEntryForm.RefreshList(false); } SelectNewFormSlice(newForm); } } return(true); }
bool CheckForFormDataLoss(IMoForm origForm, int toClsid) { string msg = null; switch (origForm.ClassID) { case MoAffixAllomorph.kclsidMoAffixAllomorph: IMoAffixAllomorph affAllo = origForm as IMoAffixAllomorph; bool loseEnv = affAllo.PhoneEnvRC.Count > 0; bool losePos = affAllo.PositionRS.Count > 0; bool loseGram = affAllo.MsEnvFeaturesOAHvo != 0 || affAllo.MsEnvPartOfSpeechRAHvo != 0; if (loseEnv && losePos && loseGram) { msg = LexEdStrings.ksConvertFormLoseEnvInfixLocGramInfo; } else if (loseEnv && losePos) { msg = LexEdStrings.ksConvertFormLoseEnvInfixLoc; } else if (loseEnv && loseGram) { msg = LexEdStrings.ksConvertFormLoseEnvGramInfo; } else if (losePos && loseGram) { msg = LexEdStrings.ksConvertFormLoseInfixLocGramInfo; } else if (loseEnv) { msg = LexEdStrings.ksConvertFormLoseEnv; } else if (losePos) { msg = LexEdStrings.ksConvertFormLoseInfixLoc; } else if (loseGram) { msg = LexEdStrings.ksConvertFormLoseGramInfo; } break; case MoAffixProcess.kclsidMoAffixProcess: msg = LexEdStrings.ksConvertFormLoseRule; break; case MoStemAllomorph.kclsidMoStemAllomorph: // not implemented break; } if (msg != null) { DialogResult result = MessageBox.Show(msg, LexEdStrings.ksConvertFormLoseCaption, MessageBoxButtons.YesNo, MessageBoxIcon.Warning); return(result == DialogResult.Yes); } return(true); }
private void SwapAllomorphWithLexeme(ILexEntry entry, IMoForm allomorph, Command cmd) { using (UndoRedoCommandHelper undoRedoTask = new UndoRedoCommandHelper(m_dataEntryForm.Cache, cmd)) { entry.AlternateFormsOS.InsertAt(entry.LexemeFormOA, allomorph.IndexInOwner); entry.LexemeFormOA = allomorph; } }
private void SwapAllomorphWithLexeme(ILexEntry entry, IMoForm allomorph, Command cmd) { UndoableUnitOfWorkHelper.Do(cmd.UndoText, cmd.RedoText, entry, () => { entry.AlternateFormsOS.Insert(allomorph.IndexInOwner, entry.LexemeFormOA); entry.LexemeFormOA = allomorph; }); }
public void InvalidReduplicationForm(IMoForm form, string reason, IMoMorphSynAnalysis msa) { m_xmlWriter.WriteStartElement("LoadError"); m_xmlWriter.WriteAttributeString("type", "invalid-redup-form"); m_xmlWriter.WriteElementString("Form", form.Form.VernacularDefaultWritingSystem.Text); m_xmlWriter.WriteElementString("Hvo", msa.Hvo.ToString(CultureInfo.InvariantCulture)); m_xmlWriter.WriteElementString("Reason", reason); m_xmlWriter.WriteEndElement(); }
internal static XElement CreateAllomorphElement(string name, IMoForm form, IMoMorphSynAnalysis msa, bool circumfix) { var elem = new XElement(name, new XAttribute("id", form.Hvo), new XAttribute("type", GetMorphTypeString(circumfix ? MoMorphTypeTags.kguidMorphCircumfix : form.MorphTypeRA.Guid)), new XElement("Form", circumfix ? form.OwnerOfClass <ILexEntry>().HeadWord.Text : form.GetFormWithMarkers(form.Cache.DefaultVernWs)), new XElement("LongName", form.LongName)); elem.Add(CreateMorphemeElement(msa)); return(elem); }
public void InvalidEnvironment(IMoForm form, IPhEnvironment env, string reason, IMoMorphSynAnalysis msa) { m_xmlWriter.WriteStartElement("LoadError"); m_xmlWriter.WriteAttributeString("type", "invalid-environment"); m_xmlWriter.WriteElementString("Form", form.Form.VernacularDefaultWritingSystem.Text); m_xmlWriter.WriteElementString("Env", env.StringRepresentation.Text); m_xmlWriter.WriteElementString("Hvo", msa.Hvo.ToString(CultureInfo.InvariantCulture)); m_xmlWriter.WriteElementString("Reason", reason); m_xmlWriter.WriteEndElement(); }
void SelectNewFormSlice(IMoForm newForm) { foreach (Slice slice in m_dataEntryForm.Controls) { if (slice.Object.Hvo == newForm.Hvo) { m_dataEntryForm.ActiveControl = slice; break; } } }
public virtual bool OnSwapAllomorphWithLexeme(object cmd) { Slice slice = m_dataEntryForm.CurrentSlice; ILexEntry entry = m_dataEntryForm.Root as ILexEntry; IMoForm allomorph = slice.Object as IMoForm; if (entry != null && allomorph != null) { SwapAllomorphWithLexeme(entry, allomorph, cmd as Command); } return(true); }
public virtual bool OnDisplayConvertAllomorph(object commandObject, ref UIItemDisplayProperties display) { Command cmd = commandObject as Command; uint fromClsid = m_dataEntryForm.Cache.MetaDataCacheAccessor.GetClassId(cmd.GetParameter("fromClassName")); Slice slice = m_dataEntryForm.CurrentSlice; IMoForm allomorph = slice.Object as IMoForm; bool enable = allomorph != null && fromClsid != 0 && allomorph.ClassID == fromClsid; display.Visible = enable; display.Enabled = enable; return(true); }
private void SetSelectedObject() { foreach (ListViewItem lvi in m_lvAlloOptions.Items) { if (lvi.Selected) { m_allomorph = lvi.Tag as IMoForm; SetBottomMessage(); } } btnOK.Enabled = true; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Find an allomorph with the specified form, if any. Searches both LexemeForm and /// AlternateForms properties. /// </summary> /// <param name="entry"></param> /// <param name="tssform">The tssform.</param> /// <returns></returns> /// ------------------------------------------------------------------------------------ public static IMoForm FindMatchingAllomorph(ILexEntry entry, ITsString tssform) { IMoForm lf = entry.LexemeFormOA; int wsVern = TsStringUtils.GetWsAtOffset(tssform, 0); string form = tssform.Text; if (lf != null && lf.Form.get_String(wsVern).Text == form) { return(lf); } return(entry.AlternateFormsOS.FirstOrDefault(mf => mf.Form.get_String(wsVern).Text == form)); }
public void MultilingualStringBasedonStringDictionary() { FdoReferenceSequence <ILgWritingSystem> systems = Cache.LangProject.CurVernWssRS; ILexDb ld = Cache.LangProject.LexDbOA; ILexEntry le = MakeLexEntry(ld, "xyzTest1", "xyzDefn1.1", 0); IMoForm m = MoForm.MakeMorph(Cache, le, "-is"); m.Form.SetAlternative("iz", systems[1].Hvo); string t = "<entry><objAtomic objProperty='LexemeFormOA'/></entry>"; string c = "<class name='MoForm'><multilingualStringElement name='form' simpleProperty='NamesWithMarkers'/></class>"; string result = GetResultStringFromEntry(le, t, c); Assert.AreEqual("<entry><form ws=\"fr\">-is</form>\r\n<form ws=\"ur\">-iz</form>\r\n</entry>", result.Trim()); }
public void GetActualWs_MorphBundleBehavesLikeMoForm() { var wsManager = new WritingSystemManager(); CoreWritingSystemDefinition enWs; wsManager.GetOrSet("en", out enWs); int wsEng = enWs.Handle; CoreWritingSystemDefinition frWs; wsManager.GetOrSet("fr", out frWs); int wsFrn = frWs.Handle; var choices = new InterlinLineChoices(m_lp, wsFrn, wsEng); MakeStandardState(choices); InterlinLineSpec spec = choices[1]; Assert.AreEqual(InterlinLineChoices.kflidMorphemes, spec.Flid); // The StringFlid for this line spec always corresponds to a MoForm Assert.AreEqual(MoFormTags.kflidForm, spec.StringFlid); IWfiWordform wf; IWfiAnalysis wag; ITsString str = TsStringUtils.MakeString("WordForm", spec.WritingSystem); IWfiMorphBundle wmb = Cache.ServiceLocator.GetInstance <IWfiMorphBundleFactory>().Create(); NonUndoableUnitOfWorkHelper.Do(Cache.ActionHandlerAccessor, () => { wf = Cache.ServiceLocator.GetInstance <IWfiWordformFactory>().Create(str); wag = WordAnalysisOrGlossServices.CreateNewAnalysisWAG(wf); wag.MorphBundlesOS.Add(wmb); ILexEntry entry = Cache.ServiceLocator.GetInstance <ILexEntryFactory>().Create(); IMoForm moForm = Cache.ServiceLocator.GetInstance <IMoStemAllomorphFactory>().Create(); entry.AlternateFormsOS.Add(moForm); moForm.Form.set_String(spec.WritingSystem, "Morph"); wmb.MorphRA = moForm; }); // The line spec for displaying the Morpheme must be able to handle getting the ws from both // MorphBundles or MoForms Assert.True(spec.Flid == InterlinLineChoices.kflidMorphemes); int wmbWs = spec.GetActualWs(Cache, wmb.Hvo, spec.WritingSystem); int mfWs = spec.GetActualWs(Cache, wmb.MorphRA.Hvo, spec.WritingSystem); Assert.True(wmbWs == spec.WritingSystem); Assert.True(mfWs == spec.WritingSystem); }
public override string GetHvoRepresentation(FdoCache cache, int hvo) { ICmObject obj = cache.ServiceLocator.GetInstance <ICmObjectRepository>().GetObject(hvo); IMoForm form = obj as IMoForm; string sResult; if (form != null) { sResult = form.ShortName; } else { sResult = ParserUIStrings.ksUnknownAllomorph; // in case the user continues... throw new ApplicationException(sResult); } return(sResult); }
public override string GetHvoRepresentation(FdoCache cache, int hvo) { ICmObject obj = CmObject.CreateFromDBObject(cache, hvo); IMoForm form = obj as IMoForm; string sResult; if (form != null) { sResult = form.ShortName; } else { sResult = ParserUIStrings.ksUnknownAllomorph; // in case the user continues... throw new ApplicationException(sResult); } return(sResult); }
protected void ConvertAffixAlloFeats(XmlDocument doc, XmlNode node, IMoForm form, XmlNode tempNode) { IMoAffixAllomorph sallo = form as IMoAffixAllomorph; IFsFeatStruc fsFeatStruc = sallo.MsEnvFeaturesOA; if (fsFeatStruc != null && !fsFeatStruc.IsEmpty) { tempNode = CreateXmlElement(doc, "affixAlloFeats", node); CreateFeatureStructureNodes(doc, tempNode, fsFeatStruc, fsFeatStruc.Hvo); } else { // There's no overt stem name on this allomorph, but there might be overt stem names // on other allomorphs in this lexical entry. This allomorph, then, cannot bear any // of the features of these other stem names. If so, there will be a property named // NotStemNameddd or NotStemNamedddNotStemNamedddd, etc. CreateNotAffixAlloFeatsElement(doc, node, tempNode); } }
/// <summary> /// Make (two) monomorphemic analyses on our favorite wordform, connected to two entries, one with two glosses. /// </summary> private void MakeMonoAnalyses() { string formLexEntry = "axx"; ITsString tssLexEntryForm = Cache.MakeVernTss(formLexEntry); int clsidForm; ILexEntry entry = LexEntry.CreateEntry(Cache, MoMorphType.FindMorphType(Cache, new MoMorphTypeCollection(Cache), ref formLexEntry, out clsidForm), tssLexEntryForm, "axe", null); ILexSense senseAxe = entry.SensesOS[0]; IMoForm form = entry.LexemeFormOA; m_wfaAxe = new WfiAnalysis(); m_wfAxx.AnalysesOC.Add(m_wfaAxe); IWfiMorphBundle bundle = m_wfaAxe.MorphBundlesOS.Append(new WfiMorphBundle()); bundle.MorphRA = form; bundle.SenseRA = senseAxe; m_wgAxe = new WfiGloss(); m_wfaAxe.MeaningsOC.Add(m_wgAxe); m_wgAxe.Form.AnalysisDefaultWritingSystem = "axe"; m_wgChopper = new WfiGloss(); m_wfaAxe.MeaningsOC.Add(m_wgChopper); m_wgChopper.Form.AnalysisDefaultWritingSystem = "chopper"; m_wfaAxe.SetAgentOpinion(m_fdoCache.LangProject.DefaultUserAgent, Opinions.approves); ILexEntry entryCut = LexEntry.CreateEntry(Cache, MoMorphType.FindMorphType(Cache, new MoMorphTypeCollection(Cache), ref formLexEntry, out clsidForm), tssLexEntryForm, "cut", null); m_wfaCut = new WfiAnalysis(); m_wfAxx.AnalysesOC.Add(m_wfaCut); bundle = m_wfaCut.MorphBundlesOS.Append(new WfiMorphBundle()); bundle.MorphRA = entryCut.LexemeFormOA; bundle.SenseRA = entryCut.SensesOS[0]; m_wgCut = new WfiGloss(); m_wfaCut.MeaningsOC.Add(m_wgCut); m_wgCut.Form.AnalysisDefaultWritingSystem = "cut"; m_wfaCut.SetAgentOpinion(m_fdoCache.LangProject.DefaultUserAgent, Opinions.approves); m_cAnalyses += 2; }
protected void ConvertStemName(XmlDocument doc, XmlNode node, IMoForm form, XmlNode tempNode) { IMoStemAllomorph sallo = form as IMoStemAllomorph; IMoStemName sn = sallo.StemNameRA; if (sn != null) { tempNode = CreateXmlElement(doc, "stemName", node); CreateXmlAttribute(doc, "id", sn.Hvo.ToString(), tempNode); tempNode.InnerXml = CreateEntities(sn.Name.BestAnalysisAlternative.Text); } else { // There's no overt stem name on this allomorph, but there might be overt stem names // on other allomorphs in this lexical entry. This allomorph, then, cannot bear any // of the features of these other stem names. If so, there will be a property named // NotStemNameddd or NotStemNamedddNotStemNamedddd, etc. tempNode = CreateNotStemNameElement(doc, node, tempNode); } }
private void SwapValues(ILexEntry entry, IMoForm origForm, IMoForm newForm, int typeHvo, List <IMoMorphSynAnalysis> rgmsaOld) { DataTree dtree = this.Slice.ContainingDataTree; int idx = this.Slice.IndexInContainer; dtree.DoNotRefresh = true; // don't let the datatree repeatedly redraw itself... Debug.Assert(entry is LexEntry); (entry as LexEntry).ReplaceMoForm(origForm, newForm); newForm.MorphTypeRAHvo = typeHvo; (entry as LexEntry).ReplaceObsoleteMsas(rgmsaOld); // Dispose of any obsolete slices: new ones will replace them automatically in a moment // when the datatree is redrawn. foreach (Slice slice in this.Slice.ContainingDataTree.Controls) { if (slice.IsDisposed) { continue; } if (slice.Object is IMoMorphSynAnalysis && rgmsaOld.Contains(slice.Object as IMoMorphSynAnalysis)) { slice.Dispose(); } else if (slice is MSAReferenceComboBoxSlice) { slice.Dispose(); } } // now fix the record list, since it may be showing MoForm dependent columns (e.g. MorphType, Homograph, etc...) dtree.FixRecordList(); dtree.DoNotRefresh = false; Slice sliceT = dtree.Controls[idx] as Slice; if (sliceT != null && sliceT is MorphTypeAtomicReferenceSlice) { // When the new slice is created, the launch button is placed in the middle of // the slice rather than at the end. This fiddling with the slice width seems // to fix that. Then setting the index restores focus to the new slice. sliceT.Width += 1; sliceT.Width -= 1; dtree.GotoNextSliceAfterIndex(idx - 1); } }
protected override void HandleMatchingSelectionChanged() { m_fwcbAllomorphs.Items.Clear(); m_fwcbAllomorphs.Text = String.Empty; if (m_selEntryID == 0) { return; } m_fwcbAllomorphs.SuspendLayout(); ILexEntry le = LexEntry.CreateFromDBObject(m_cache, m_selEntryID); /* NB: We remove abstract MoForms, because the adhoc allo coprohibiton object wants them removed. * If any other client of this dlg comes along that wants them, * we will need to feed in a parameter that tells us whether to exclude them or not. */ // Add the lexeme form, if it exists. IMoForm lf = le.LexemeFormOA; if (lf != null && !lf.IsAbstract) { m_fwcbAllomorphs.Items.Add(new LAllomorph(le.LexemeFormOA)); } foreach (IMoForm allo in le.AlternateFormsOS) { if (!allo.IsAbstract) { m_fwcbAllomorphs.Items.Add(new LAllomorph(allo)); } } if (m_fwcbAllomorphs.Items.Count > 0) { m_fwcbAllomorphs.SelectedItem = m_fwcbAllomorphs.Items[0]; } btnOK.Enabled = m_fwcbAllomorphs.Items.Count > 0; m_fwcbAllomorphs.ResumeLayout(); // For a resizeable dialog, we don't want AdjustForStylesheet to really change its size, // because then it ends up growing every time it launches! int oldHeight = this.Height; m_fwcbAllomorphs.AdjustForStyleSheet(this, grplbl, m_mediator); this.Height = oldHeight; }
private static void WriteStemNameElement(XmlWriter writer, IMoForm form, string props) { var sallo = form as IMoStemAllomorph; Debug.Assert(sallo != null); IMoStemName sn = sallo.StemNameRA; if (sn != null) { writer.WriteStartElement("stemName"); writer.WriteAttributeString("id", sn.Hvo.ToString(CultureInfo.InvariantCulture)); writer.WriteString(sn.Name.BestAnalysisAlternative.Text); writer.WriteEndElement(); //stemName } else { // There's no overt stem name on this allomorph, but there might be overt stem names // on other allomorphs in this lexical entry. This allomorph, then, cannot bear any // of the features of these other stem names. If so, there will be a property named // NotStemNameddd or NotStemNamedddNotStemNamedddd, etc. WriteNotStemNameElement(writer, props); } }
public void TestOwningFlid() { Assert.AreEqual(0, Cache.LangProject.OwningFlid); // no owner Assert.AreEqual(LangProjectTags.kflidLexDb, Cache.LangProject.LexDbOA.OwningFlid); // atomic, on an owner with many var servLoc = Cache.ServiceLocator; ILexEntry entry = null; ICmResource resource = null; ILexSense sense1 = null; ILexSense sense2 = null; ILexSense sense3 = null; IMoForm form1 = null; IMoForm form2 = null; UndoableUnitOfWorkHelper.Do("Undo stuff", "Redo stuff", m_actionHandler, () => { resource = servLoc.GetInstance <ICmResourceFactory>().Create(); Cache.LangProject.LexDbOA.ResourcesOC.Add(resource); entry = servLoc.GetInstance <ILexEntryFactory>().Create(); sense1 = servLoc.GetInstance <ILexSenseFactory>().Create(); entry.SensesOS.Add(sense1); sense2 = servLoc.GetInstance <ILexSenseFactory>().Create(); entry.SensesOS.Add(sense2); sense3 = servLoc.GetInstance <ILexSenseFactory>().Create(); entry.SensesOS.Add(sense3); form1 = servLoc.GetInstance <IMoStemAllomorphFactory>().Create(); entry.AlternateFormsOS.Add(form1); form2 = servLoc.GetInstance <IMoStemAllomorphFactory>().Create(); entry.AlternateFormsOS.Add(form2); } ); Assert.AreEqual(LexDbTags.kflidResources, resource.OwningFlid); // owning collection Assert.AreEqual(LexEntryTags.kflidSenses, sense1.OwningFlid); // owning sequence Assert.AreEqual(LexEntryTags.kflidSenses, sense2.OwningFlid); // owning sequence, middle Assert.AreEqual(LexEntryTags.kflidSenses, sense3.OwningFlid); // owning sequence, last Assert.AreEqual(LexEntryTags.kflidAlternateForms, form1.OwningFlid); // owning sequence, not longest Assert.AreEqual(LexEntryTags.kflidAlternateForms, form2.OwningFlid); // owning sequence, not longest or first }
private static void WriteAffixAlloFeatsElement(XmlWriter writer, IMoForm form, string propsText) { var sallo = form as IMoAffixAllomorph; if (sallo == null) { return; // the form could be an IMoAffixProcess in which case there are no MsEnvFeatures. } IFsFeatStruc fsFeatStruc = sallo.MsEnvFeaturesOA; if (fsFeatStruc != null && !fsFeatStruc.IsEmpty) { writer.WriteStartElement("affixAlloFeats"); WriteFeatureStructureNodes(writer, fsFeatStruc, fsFeatStruc.Hvo); writer.WriteEndElement(); //affixAlloFeats } else { // There's no overt stem name on this allomorph, but there might be overt stem names // on other allomorphs in this lexical entry. This allomorph, then, cannot bear any // of the features of these other stem names. If so, there will be a property named // NotStemNameddd or NotStemNamedddNotStemNamedddd, etc. WriteNotAffixAlloFeatsElement(writer, form.Cache, propsText); } }
private static void HandleInfix(ILexEntry entry, IMoForm allomorph) { const string sDefaultPostionEnvironment = "/#[C]_"; var infix = allomorph as IMoAffixAllomorph; if (infix == null) return; // something's wrong... var cache = entry.Cache; var env = PhEnvironment.DefaultInfixEnvironment(cache, sDefaultPostionEnvironment); if (env != null) { infix.PositionRS.Add(env); } else { // create default infix position environment var strFact = cache.TsStrFactory; var defAnalWs = entry.Services.WritingSystems.DefaultAnalysisWritingSystem; var ppd = cache.LangProject.PhonologicalDataOA; env = new PhEnvironment(); ppd.EnvironmentsOS.Add(env); env.StringRepresentation = strFact.MakeString(sDefaultPostionEnvironment, cache.DefaultVernWs); env.Description.set_String(defAnalWs.Handle, strFact.MakeString("Default infix position environment", defAnalWs.Handle)); env.Name.set_String(defAnalWs.Handle, strFact.MakeString("After stem-initial consonant", defAnalWs.Handle)); infix.PositionRS.Add(env); } }
public string ExtractTextSegmentAsANA(ISegment segment) { BadGlosses.Clear(); var sb = new StringBuilder(); var sbA = new StringBuilder(); var sbD = new StringBuilder(); var sbC = new StringBuilder(); var sbFD = new StringBuilder(); var sbP = new StringBuilder(); var sbW = new StringBuilder(); foreach (IAnalysis analysis in segment.AnalysesRS) { var wordform = analysis.Wordform; if (wordform == null) { continue; } sbA.Clear(); sbA.Append("\\a "); sbD.Clear(); sbD.Append("\\d "); sbC.Clear(); sbC.Append("\\cat "); sbFD.Clear(); sbFD.Append("\\fd "); sbP.Clear(); sbP.Append("\\p "); sbW.Clear(); sbW.Append("\\w "); var shape = wordform.Form.VernacularDefaultWritingSystem.Text; sbW.Append(shape + "\n"); int ambiguities = wordform.AnalysesOC.Count; if (ambiguities > 1) { String ambigs = "%" + ambiguities + "%"; sbA.Append(ambigs); sbD.Append(ambigs); sbC.Append(ambigs); sbFD.Append(ambigs); sbP.Append(ambigs); } foreach (IWfiAnalysis wfiAnalysis in wordform.AnalysesOC) { IWfiMorphBundle previous = null; IMoForm previousMorph = null; var maxMorphs = wfiAnalysis.MorphBundlesOS.Count; int i = 0; foreach (IWfiMorphBundle bundle in wfiAnalysis.MorphBundlesOS) { var msa = bundle.MsaRA; if (msa == null) { continue; } var morph = bundle.MorphRA; if (morph == null) { continue; } if (msa is IMoStemMsa && !IsAttachedClitic(morph.MorphTypeRA.Guid, maxMorphs)) { if (previous == null) { sbA.Append("< "); } else { if (previousMorph.MorphTypeRA.IsPrefixishType || previousMorph.MorphTypeRA.Guid == MoMorphTypeTags.kguidMorphProclitic) { sbA.Append(" < "); } } } if (msa is IMoStemMsa && !IsAttachedClitic(morph.MorphTypeRA.Guid, maxMorphs)) { var cat = msa.PartOfSpeechForWsTSS(Cache.DefaultAnalWs).Text; sbA.Append(cat + " "); } else if (i > 0) { sbA.Append(" "); } if (morph != null) { sbD.Append(morph.Form.VernacularDefaultWritingSystem.Text); } var sense = bundle.SenseRA; if (sense == null) { // a sense can be missing from a bundle if the bundle is built by the parser filer var entryOfMsa = (ILexEntry)msa.Owner; sense = entryOfMsa.SensesOS.FirstOrDefault(s => s.MorphoSyntaxAnalysisRA == msa); if (sense != null) { HandleSense(sbA, sbFD, sense); } else if (morph != null) { var entry = (ILexEntry)morph.Owner; var sense2 = entry.SensesOS.FirstOrDefault(); if (sense2 == null) { sbA.Append("missing_sense"); } else { HandleSense(sbA, sbFD, sense2); } } } else { HandleSense(sbA, sbFD, sense); } if (msa is IMoStemMsa && !IsAttachedClitic(morph.MorphTypeRA.Guid, maxMorphs)) { sbA.Append(" "); var next = wfiAnalysis.MorphBundlesOS.ElementAtOrDefault(i + 1); if (next == null) { sbA.Append(">"); } else { var nextMorph = next.MorphRA; if (nextMorph == null || nextMorph.MorphTypeRA.IsSuffixishType || nextMorph.MorphTypeRA.Guid == MoMorphTypeTags.kguidMorphEnclitic) { sbA.Append(">"); } } } sbP.Append(bundle.Guid.ToString()); previous = bundle; previousMorph = morph; i++; if (i < maxMorphs) { sbD.Append("-"); sbFD.Append("="); sbP.Append("="); } } sbC.Append(GetOrComputeWordCategory(wfiAnalysis)); if (ambiguities > 1) { sbA.Append("%"); sbD.Append("%"); sbC.Append("%"); sbFD.Append("%"); sbP.Append("%"); } } sbA.Append("\n"); sbD.Append("\n"); sbC.Append("\n"); sbFD.Append("\n"); sbP.Append("\n"); sbW.Append("\n"); sb.Append(sbA.ToString()); sb.Append(sbD.ToString()); sb.Append(sbC.ToString()); sb.Append(sbP.ToString()); sb.Append(sbFD.ToString()); sb.Append(sbW.ToString()); } return(sb.ToString()); }
// Swap values of various attributes between an existing form that is a LexemeForm and // a newly created one. Includes adding the new one to the alternate forms of the entry, and // the id of the old one to a map of things to delete. private void SwapFormValues(ILexEntry entry, IMoForm origForm, IMoForm newForm, int typeHvo, Set<int> idsToDel) { entry.AlternateFormsOS.Add(newForm); origForm.SwapReferences(newForm); var muaOrigForm = origForm.Form; var muaNewForm = newForm.Form; muaNewForm.MergeAlternatives(muaOrigForm); newForm.MorphTypeRA = m_cache.ServiceLocator.GetInstance<IMoMorphTypeRepository>().GetObject(typeHvo); idsToDel.Add(origForm.Hvo); }
private string GetFormWithMarkers(IMoForm alt, int ws) { if (IsVoiceWritingSystem(ws)) { // The alternative contains a file path. We need to adjust and export and copy the file. // We also don't want to decorate the file name with any affix markers. // Form is MultiUnicode, so we don't need to check for a single run. var internalPath = alt.Form.get_String(ws).Text; // usually this will be unchanged, but it is pathologically possible that the file name conflicts. var writePath = ExportFile(internalPath, Path.Combine(FdoFileHelper.GetMediaDir(m_cache.LangProject.LinkedFilesRootDir), internalPath), "audio"); return writePath; } return alt.GetFormWithMarkers(ws); }
/// <summary> /// This replaces a MoForm belonging to this LexEntry with another one, presumably /// changing from a stem to an affix or vice versa. (A version of this code originally /// appeared in MorphTypeAtomicLauncher.cs, but is also needed for LIFT import.) /// </summary> /// <param name="mfOld"></param> /// <param name="mfNew"></param> public void ReplaceMoForm(IMoForm mfOld, IMoForm mfNew) { // save the environment references, if any. int[] envs = null; if (mfOld is IMoStemAllomorph) envs = (mfOld as IMoStemAllomorph).PhoneEnvRC.HvoArray; else if (mfOld is IMoAffixAllomorph) envs = (mfOld as IMoAffixAllomorph).PhoneEnvRC.HvoArray; else envs = new int[0]; int[] inflClasses = null; if (mfOld is IMoAffixForm) inflClasses = (mfOld as IMoAffixForm).InflectionClassesRC.HvoArray; else inflClasses = new int[0]; // if we are converting from one affix form to another, we should save the morph type int oldAffMorphType = 0; if (mfOld is IMoAffixForm) oldAffMorphType = mfOld.MorphTypeRAHvo; if (mfOld.OwningFlid == (int)LexEntry.LexEntryTags.kflidLexemeForm) { this.AlternateFormsOS.Append(mfNew); // trick to get it to be in DB so SwapReferences works } else { // insert the new form in the right location in the sequence. Debug.Assert(mfOld.OwningFlid == (int)LexEntry.LexEntryTags.kflidAlternateForms); bool fInserted = false; for (int i = 0; i < this.AlternateFormsOS.Count; ++i) { if (this.AlternateFormsOS.HvoArray[i] == mfOld.Hvo) { this.AlternateFormsOS.InsertAt(mfNew, i); fInserted = true; break; } } if (!fInserted) this.AlternateFormsOS.Append(mfNew); // This should NEVER happen, but... } mfOld.SwapReferences(mfNew.Hvo); MultiUnicodeAccessor muaOrigForm = mfOld.Form; MultiUnicodeAccessor muaNewForm = mfNew.Form; muaNewForm.MergeAlternatives(muaOrigForm); if (mfOld.OwningFlid == (int)LexEntry.LexEntryTags.kflidLexemeForm) this.LexemeFormOA = mfNew; // do we need to remove it from AlternateFormsOS?? else this.AlternateFormsOS.Remove(mfOld); // restore the environment references, if any. foreach (int hvo in envs) { if (mfNew is IMoStemAllomorph) (mfNew as IMoStemAllomorph).PhoneEnvRC.Add(hvo); else if (mfNew is IMoAffixAllomorph) (mfNew as IMoAffixAllomorph).PhoneEnvRC.Add(hvo); } foreach (int hvo in inflClasses) { if (mfNew is IMoAffixForm) (mfNew as IMoAffixForm).InflectionClassesRC.Add(hvo); } if (oldAffMorphType != 0 && mfNew is IMoAffixForm) mfNew.MorphTypeRAHvo = oldAffMorphType; }
private void SwapValues(ILexEntry entry, IMoForm origForm, IMoForm newForm, IMoMorphType type, List<IMoMorphSynAnalysis> rgmsaOld) { DataTree dtree = Slice.ContainingDataTree; int idx = Slice.IndexInContainer; dtree.DoNotRefresh = true; // don't let the datatree repeatedly redraw itself... entry.ReplaceMoForm(origForm, newForm); newForm.MorphTypeRA = type; entry.ReplaceObsoleteMsas(rgmsaOld); // Dispose of any obsolete slices: new ones will replace them automatically in a moment // when the datatree is redrawn. foreach (Slice slice in Slice.ContainingDataTree.Slices.ToArray()) { if (slice.IsDisposed) continue; if (slice.Object is IMoMorphSynAnalysis && rgmsaOld.Contains(slice.Object as IMoMorphSynAnalysis)) slice.Dispose(); else if (slice is MSAReferenceComboBoxSlice) slice.Dispose(); } // now fix the record list, since it may be showing MoForm dependent columns (e.g. MorphType, Homograph, etc...) dtree.FixRecordList(); dtree.DoNotRefresh = false; Slice sliceT = dtree.Slices[idx]; if (sliceT != null && sliceT is MorphTypeAtomicReferenceSlice) { // When the new slice is created, the launch button is placed in the middle of // the slice rather than at the end. This fiddling with the slice width seems // to fix that. Then setting the index restores focus to the new slice. sliceT.Width += 1; sliceT.Width -= 1; dtree.GotoNextSliceAfterIndex(idx - 1); } }
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 AddMorphItemToList(IMoForm mf, ILexEntryRef ler, ITsString tssSense, ILexSense sense, IWritingSystem wsAnalysis, ITsString tssName, int hvoLexEntry) { MorphItem mi; if (tssSense.Length == 0) { // If it doesn't have a gloss (e.g., from Categorised Entry), use the definition. tssSense = sense.Definition.get_String(wsAnalysis.Handle); } mi = GetMorphItem(mf, tssName, sense, tssSense, ler, hvoLexEntry, null); m_morphItems.Add(mi); }
/// <summary> /// /// </summary> /// <param name="mf"></param> /// <param name="le">the entry used in the morph bundle (for sense info). typically /// this is an owner of hvoMorph, but if not, it most likely has hvoMorph linked as its variant.</param> private void BuildMorphItemsFromEntry(IMoForm mf, ILexEntry le, ILexEntryRef ler) { int hvoLexEntry = 0; if (le != null) hvoLexEntry = le.Hvo; ITsString tssName = null; if (le != null) { tssName = LexEntryVc.GetLexEntryTss(m_caches.MainCache, le.Hvo, m_wsVern, ler); } else { // looks like we're not in a good state, so just use the form for the name. int wsActual; tssName = mf.Form.GetAlternativeOrBestTss(m_wsVern, out wsActual); } var wsAnalysis = m_caches.MainCache.ServiceLocator.WritingSystemManager.Get(m_caches.MainCache.DefaultAnalWs); // Populate morphItems with Sense/Msa level specifics if (le != null) { foreach (ILexSense sense in le.AllSenses) { var tssSense = sense.Gloss.get_String(wsAnalysis.Handle); if (ler != null) { MorphItem mi; var lexEntryInflTypes = ler.VariantEntryTypesRS.Where(let => let is ILexEntryInflType).Select(let => let as ILexEntryInflType); if (lexEntryInflTypes.Count() > 0) { foreach (var inflType in lexEntryInflTypes) { var glossAccessor = (tssSense.Length == 0 ? (IMultiStringAccessor) sense.Definition : sense.Gloss); tssSense = MorphServices.MakeGlossOptionWithInflVariantTypes(inflType, glossAccessor, wsAnalysis); mi = GetMorphItem(mf, tssName, sense, tssSense, ler, hvoLexEntry, inflType); m_morphItems.Add(mi); } } else { AddMorphItemToList(mf, ler, tssSense, sense, wsAnalysis, tssName, hvoLexEntry); } } else { AddMorphItemToList(mf, null, tssSense, sense, wsAnalysis, tssName, hvoLexEntry); } } } // Make a LexEntry level item m_morphItems.Add(new MorphItem(mf.Hvo, ler != null ? hvoLexEntry : 0, tssName)); }
protected void ConvertAffixAlloFeats(XmlDocument doc, XmlNode node, IMoForm form, XmlNode tempNode) { MoAffixAllomorph sallo = form as MoAffixAllomorph; IFsFeatStruc fsFeatStruc = sallo.MsEnvFeaturesOA; if (fsFeatStruc != null && !fsFeatStruc.IsEmpty) { tempNode = CreateXmlElement(doc, "affixAlloFeats", node); CreateFeatureStructureNodes(doc, tempNode, fsFeatStruc, fsFeatStruc.Hvo); } else { // There's no overt stem name on this allomorph, but there might be overt stem names // on other allomorphs in this lexical entry. This allomorph, then, cannot bear any // of the features of these other stem names. If so, there will be a property named // NotStemNameddd or NotStemNamedddNotStemNamedddd, etc. CreateNotAffixAlloFeatsElement(doc, node, tempNode); } }
bool CheckForFormDataLoss(IMoForm origForm, int toClsid) { string msg = null; switch (origForm.ClassID) { case MoAffixAllomorphTags.kClassId: IMoAffixAllomorph affAllo = origForm as IMoAffixAllomorph; bool loseEnv = affAllo.PhoneEnvRC.Count > 0; bool losePos = affAllo.PositionRS.Count > 0; bool loseGram = affAllo.MsEnvFeaturesOA != null || affAllo.MsEnvPartOfSpeechRA != null; if (loseEnv && losePos && loseGram) msg = LexEdStrings.ksConvertFormLoseEnvInfixLocGramInfo; else if (loseEnv && losePos) msg = LexEdStrings.ksConvertFormLoseEnvInfixLoc; else if (loseEnv && loseGram) msg = LexEdStrings.ksConvertFormLoseEnvGramInfo; else if (losePos && loseGram) msg = LexEdStrings.ksConvertFormLoseInfixLocGramInfo; else if (loseEnv) msg = LexEdStrings.ksConvertFormLoseEnv; else if (losePos) msg = LexEdStrings.ksConvertFormLoseInfixLoc; else if (loseGram) msg = LexEdStrings.ksConvertFormLoseGramInfo; break; case MoAffixProcessTags.kClassId: msg = LexEdStrings.ksConvertFormLoseRule; break; case MoStemAllomorphTags.kClassId: // not implemented break; } if (msg != null) { DialogResult result = MessageBox.Show(msg, LexEdStrings.ksConvertFormLoseCaption, MessageBoxButtons.YesNo, MessageBoxIcon.Warning); return result == DialogResult.Yes; } return true; }
// Swap values of various attributes between an existing form that is a LexemeForm and // a newly created one. Includes adding the new one to the alternate forms of the entry, and // the id of the old one to a map of things to delete. private void SwapFormValues(ILexEntry entry, IMoForm origForm, IMoForm newForm, int typeHvo, Set<int> idsToDel) { entry.AlternateFormsOS.Append(newForm); // trick to get it to be in DB so SwapReferences works origForm.SwapReferences(newForm.Hvo); MultiUnicodeAccessor muaOrigForm = origForm.Form; MultiUnicodeAccessor muaNewForm = newForm.Form; muaNewForm.MergeAlternatives(muaOrigForm); newForm.MorphTypeRAHvo = typeHvo; idsToDel.Add(origForm.Hvo); }
public LAllomorph(IMoForm allo) : base(allo.Hvo) { m_type = allo.ClassID; m_form = allo.Form.BestVernacularAlternative; }
/// <summary> /// Swap all references to this MoForm to use the new one /// </summary> /// <param name="newForm">the hvo of the new MoForm</param> public void SwapReferences(IMoForm newForm) { foreach (var adhocProhib in Services.GetInstance<IMoAlloAdhocProhibRepository>().AllInstances()) { if (adhocProhib.FirstAllomorphRA == this) adhocProhib.FirstAllomorphRA = newForm; for (int i = 0; i < adhocProhib.RestOfAllosRS.Count; i++) { if (adhocProhib.RestOfAllosRS[i] == this) adhocProhib.RestOfAllosRS.Replace(i, 1, new IMoForm[] { newForm }); } } foreach (var mb in Services.GetInstance<IWfiMorphBundleRepository>().AllInstances()) { if (mb.MorphRA == this) mb.MorphRA = newForm; } }
internal void CreateNewEntry(bool fCreateNow, out ILexEntry le, out IMoForm allomorph, out ILexSense sense) { CheckDisposed(); le = null; allomorph = null; sense = null; FdoCache cache = m_caches.MainCache; int hvoMorph = m_caches.DataAccess.get_ObjectProp(m_hvoMorph, ktagSbMorphForm); ITsString tssForm = m_caches.DataAccess.get_MultiStringAlt(hvoMorph, ktagSbNamedObjName, m_sandbox.RawWordformWs); // If we don't have a form or it isn't in a current vernacular writing system, give up. if (tssForm == null || tssForm.Length == 0 || !WritingSystemServices.GetAllWritingSystems(m_caches.MainCache, "all vernacular", null, 0, 0).Contains( TsStringUtils.GetWsOfRun(tssForm, 0))) { return; } var entryComponents = BuildEntryComponents(); bool fCreateAllomorph = false; bool fCreatedEntry = false; if (fCreateNow) { // just create a new entry based on the given information. le = cache.ServiceLocator.GetInstance<ILexEntryFactory>().Create(entryComponents); } else { using (InsertEntryDlg dlg = InsertEntryNow.CreateInsertEntryDlg(fCreateNow)) { dlg.SetDlgInfo(cache, m_sandbox.GetFullMorphForm(m_hvoMorph), m_sandbox.Mediator); dlg.TssGloss = entryComponents.GlossAlternatives.FirstOrDefault(); foreach (ITsString tss in entryComponents.GlossAlternatives.Skip(1)) dlg.SetInitialGloss(TsStringUtils.GetWsAtOffset(tss, 0), tss); dlg.ChangeUseSimilarToCreateAllomorph(); if (fCreateNow) { // just create a new entry based on the given information. dlg.CreateNewEntry(); } else { // bring up the dialog so the user can make further decisions. Form mainWnd = m_sandbox.FindForm(); // Making the form active fixes LT-2344 & LT-2345. // I'm (RandyR) not sure what adverse impact might show up by doing this. mainWnd.Activate(); // The combo should be automatically hidden by activating another window. // That works on Windows but not on Mono (reported as https://bugzilla.xamarin.com/show_bug.cgi?id=15848). // So to prevent the combo hanging around on Mono, we hide it explicitly here. HideCombo(); dlg.SetHelpTopic("khtpInsertEntryFromInterlinear"); if (dlg.ShowDialog(mainWnd) == DialogResult.OK) fCreateAllomorph = true; } dlg.GetDialogInfo(out le, out fCreatedEntry); if (!fCreatedEntry && !fCreateAllomorph) return; } } if (fCreateAllomorph && le.SensesOS.Count > 0) sense = le.SensesOS[0]; allomorph = MorphServices.FindMatchingAllomorph(le, tssForm); bool fCreatedAllomorph = false; if (allomorph == null) { using (UndoableUnitOfWorkHelper undoHelper = new UndoableUnitOfWorkHelper( cache.ServiceLocator.GetInstance<IActionHandler>(), ITextStrings.ksUndoAddAllomorphToSimilarEntry, ITextStrings.ksRedoAddAllomorphToSimilarEntry)) { allomorph = MorphServices.MakeMorph(le, tssForm); fCreatedAllomorph = true; Debug.Assert(allomorph != null); undoHelper.RollBack = false; } if (fCreatedEntry) { // Making the entry and the allomorph should feel like one indivisible action to the end user. ((IActionHandlerExtensions) cache.ActionHandlerAccessor).MergeLastTwoUnitsOfWork(); } } var allomorph1 = allomorph; var le1 = le; var sense1 = sense; if (fCreatedEntry || fCreatedAllomorph) { // If we've created something, then updating the sandbox needs to be undone as a unit with it, // so the sandbox isn't left showing something uncreated. UndoableUnitOfWorkHelper.Do("join me up", "join me up", cache.ActionHandlerAccessor, () => UpdateMorphEntry(allomorph1, le1, sense1)); ((IActionHandlerExtensions)cache.ActionHandlerAccessor).MergeLastTwoUnitsOfWork(); } else { // Updating the sandbox doesn't need to be undoable, no real data changes. UpdateMorphEntry(allomorph1, le1, sense1); } }
private void WriteAllFormsWithMarkers(TextWriter w, string wrappingElementName, string attrs, string elementName, IMoForm alt) { if (alt == null || alt.Form == null || alt.Form.StringCount == 0) return; if (!String.IsNullOrEmpty(wrappingElementName)) { if (String.IsNullOrEmpty(attrs)) w.WriteLine("<{0}>", wrappingElementName); else w.WriteLine("<{0} {1}>", wrappingElementName, attrs); } for (var i = 0; i < alt.Form.StringCount; ++i) { int ws; var tssForm = alt.Form.GetStringFromIndex(i, out ws); var sLang = m_cache.WritingSystemFactory.GetStrFromWs(ws); var internalPath = alt.Form.get_String(ws).Text; // a deleted audio link can leave an empty string - it's the file path // Chorus sometimes tells users "Report this problem to the developers" when missing this element // Users should refresh and try to send/receive again. if (!String.IsNullOrEmpty(internalPath)) w.WriteLine("<{0} lang=\"{1}\"><text>{2}</text></{0}>", elementName, MakeSafeAndNormalizedAttribute(sLang), MakeSafeAndNormalizedXml(GetFormWithMarkers(alt, ws))); } if (!String.IsNullOrEmpty(wrappingElementName)) w.WriteLine("</{0}>", wrappingElementName); }
private IMoMorphSynAnalysis GetMsaAndMoForm(ILexEntry entry, Guid slotType, string pos, out IMoForm form) { IMoMorphSynAnalysis msa; if (slotType == MoMorphTypeTags.kguidMorphStem) { form = Cache.ServiceLocator.GetInstance<IMoStemAllomorphFactory>().Create(); var stemMsa = Cache.ServiceLocator.GetInstance<IMoStemMsaFactory>().Create(); msa = stemMsa; entry.MorphoSyntaxAnalysesOC.Add(msa); stemMsa.PartOfSpeechRA = MakePartOfSpeech(pos); } else { form = Cache.ServiceLocator.GetInstance<IMoAffixAllomorphFactory>().Create(); var affixMsa = Cache.ServiceLocator.GetInstance<IMoInflAffMsaFactory>().Create(); msa = affixMsa; entry.MorphoSyntaxAnalysesOC.Add(msa); affixMsa.PartOfSpeechRA = MakePartOfSpeech(pos); } return msa; }
private void GetMorphInfo(out ITsString tssForm, out ITsString tssFullForm, out IMoForm morphReal, out IMoMorphType morphType) { morphReal = null; int hvoMorph = m_caches.DataAccess.get_ObjectProp(m_hvoMorph, ktagSbMorphForm); var hvoMorphReal = m_caches.RealHvo(hvoMorph); if (hvoMorphReal != 0) morphReal = m_caches.MainCache.ServiceLocator.GetInstance<IMoFormRepository>().GetObject(hvoMorphReal); ISilDataAccess sda = m_caches.DataAccess; tssForm = m_caches.DataAccess.get_MultiStringAlt(hvoMorph, ktagSbNamedObjName, m_sandbox.RawWordformWs); tssFullForm = m_sandbox.GetFullMorphForm(m_hvoMorph); string fullForm = tssFullForm.Text; morphType = null; if (morphReal != null) { morphType = morphReal.MorphTypeRA; } else { // if we don't have a form then we can't derive a type. (cf. LT-1621) if (string.IsNullOrEmpty(fullForm)) { morphType = null; } else { // Find the type for this morpheme int clsidForm; string fullFormTmp = fullForm; morphType = MorphServices.FindMorphType(m_caches.MainCache, ref fullFormTmp, out clsidForm); } } }
private static void HandleInfix(ILexEntry entry, IMoForm allomorph) { const string sDefaultPostionEnvironment = "/#[C]_"; IMoAffixAllomorph infix = allomorph as IMoAffixAllomorph; if (infix == null) return; // something's wrong... FdoCache cache = entry.Cache; int defaultInfixPositionHvo = PhEnvironment.DefaultInfixEnvironment(cache, sDefaultPostionEnvironment); if (defaultInfixPositionHvo > 0) infix.PositionRS.Append(defaultInfixPositionHvo); else { // create default infix position environment IPhPhonData ppd = cache.LangProject.PhonologicalDataOA; PhEnvironment env = new PhEnvironment(); ppd.EnvironmentsOS.Append(env); env.StringRepresentation.Text = sDefaultPostionEnvironment; env.Description.AnalysisDefaultWritingSystem.Text = "Default infix position environment"; env.Name.AnalysisDefaultWritingSystem = "After stem-initial consonant"; cache.PropChanged(null, PropChangeType.kpctNotifyAll, ppd.Hvo, (int)PhPhonData.PhPhonDataTags.kflidEnvironments, ppd.EnvironmentsOS.Count - 1, 1, 0); infix.PositionRS.Append(env); } }
/// <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; }
private void SetupAllomorphsData(out IMoForm firstAllomorphOut, out ILexEntry firstEntryWithAllomorphOut, out ILexEntry firstEntryWithoutAllomorphOut, out List<ILexEntry> entriesWithoutAllomorphsOut, out List<IMoForm> allomorphsOut) { IMoForm firstAllomorph = null; ILexEntry firstEntryWithAllomorph = null; ILexEntry firstEntryWithoutAllomorph = null; List<ILexEntry> entriesWithoutAllomorphs = new List<ILexEntry>(); List<IMoForm> allomorphs = new List<IMoForm>(); UndoableUnitOfWorkHelper.Do("SetupAllomorphsData", "SetupAllomorphsData", Cache.ActionHandlerAccessor, () => { // find an entry with allomorphs. foreach (ILexEntry entry in Cache.LangProject.LexDbOA.Entries) { if (entry.AlternateFormsOS.Count > 0) { allomorphs.AddRange(entry.AlternateFormsOS); if (firstAllomorph == null) { firstEntryWithAllomorph = entry; firstAllomorph = entry.AlternateFormsOS[0]; var newAllomorph = Cache.ServiceLocator.GetInstance<IMoStemAllomorphFactory>().Create(); entry.AlternateFormsOS.Add(newAllomorph); allomorphs.Add(newAllomorph); } } else { entriesWithoutAllomorphs.Add(entry); if (firstEntryWithoutAllomorph == null) firstEntryWithoutAllomorph = entry; } } }); firstAllomorphOut = firstAllomorph; firstEntryWithAllomorphOut = firstEntryWithAllomorph; firstEntryWithoutAllomorphOut = firstEntryWithoutAllomorph; entriesWithoutAllomorphsOut = entriesWithoutAllomorphs; allomorphsOut = allomorphs; }
protected void ConvertStemName(XmlDocument doc, XmlNode node, IMoForm form, XmlNode tempNode) { MoStemAllomorph sallo = form as MoStemAllomorph; IMoStemName sn = sallo.StemNameRA; if (sn != null) { tempNode = CreateXmlElement(doc, "stemName", node); CreateXmlAttribute(doc, "id", sn.Hvo.ToString(), tempNode); tempNode.InnerXml = CreateEntities(sn.Name.BestAnalysisAlternative.Text); } else { // There's no overt stem name on this allomorph, but there might be overt stem names // on other allomorphs in this lexical entry. This allomorph, then, cannot bear any // of the features of these other stem names. If so, there will be a property named // NotStemNameddd or NotStemNamedddNotStemNamedddd, etc. tempNode = CreateNotStemNameElement(doc, node, tempNode); } }
internal static XElement CreateAllomorphElement(string name, IMoForm form, IMoMorphSynAnalysis msa, bool circumfix) { var elem = new XElement(name, new XAttribute("id", form.Hvo), new XAttribute("type", GetMorphTypeString(circumfix ? MoMorphTypeTags.kguidMorphCircumfix : form.MorphTypeRA.Guid)), new XElement("Form", circumfix ? form.OwnerOfClass<ILexEntry>().HeadWord.Text : form.GetFormWithMarkers(form.Cache.DefaultVernWs)), new XElement("LongName", form.LongName)); elem.Add(CreateMorphemeElement(msa)); return elem; }
public void Initialize(IMoForm rootObj, int rootFlid, FdoCache cache) { CheckDisposed(); Debug.Assert(rootObj is IMoAffixAllomorph || rootObj is IMoStemAllomorph); Debug.Assert(cache != null && m_fdoCache == null); Cache = cache; m_tsf = cache.TsStrFactory; ResetValidator(); m_wsVern = m_fdoCache.ServiceLocator.WritingSystems.DefaultVernacularWritingSystem.Handle; m_rootObj = rootObj; m_rootFlid = rootFlid; if (m_rootb == null) MakeRoot(); }
private static void WriteAffixAlloFeatsElement(XmlWriter writer, IMoForm form, string propsText) { var sallo = form as IMoAffixAllomorph; if (sallo == null) return; // the form could be an IMoAffixProcess in which case there are no MsEnvFeatures. IFsFeatStruc fsFeatStruc = sallo.MsEnvFeaturesOA; if (fsFeatStruc != null && !fsFeatStruc.IsEmpty) { writer.WriteStartElement("affixAlloFeats"); WriteFeatureStructureNodes(writer, fsFeatStruc, fsFeatStruc.Hvo); writer.WriteEndElement(); //affixAlloFeats } else { // There's no overt stem name on this allomorph, but there might be overt stem names // on other allomorphs in this lexical entry. This allomorph, then, cannot bear any // of the features of these other stem names. If so, there will be a property named // NotStemNameddd or NotStemNamedddNotStemNamedddd, etc. WriteNotAffixAlloFeatsElement(writer, form.Cache, propsText); } }
void SelectNewFormSlice(IMoForm newForm) { foreach (Slice slice in m_dataEntryForm.Slices) { if (slice.Object.Hvo == newForm.Hvo) { m_dataEntryForm.ActiveControl = slice; break; } } }
private void WriteAlternateForm(TextWriter w, IMoForm alt) { w.Write("<variant"); WriteLiftDates(w, alt); switch (alt.ClassID) { case MoStemAllomorphTags.kClassId: { var stemAllo = alt as IMoStemAllomorph; Debug.Assert(stemAllo != null); var refer = GetProperty(alt, "LiftRefAttribute") as string; if (!String.IsNullOrEmpty(refer)) w.Write(" ref=\"{0}\"", MakeSafeAndNormalizedAttribute(refer)); w.WriteLine(">"); WriteAllFormsWithMarkers(w, null, null, "form", alt); foreach (var env in stemAllo.PhoneEnvRC) WritePhEnvironment(w, env); } break; case MoAffixAllomorphTags.kClassId: { var affixAllo = alt as IMoAffixAllomorph; Debug.Assert(affixAllo != null); var refer = GetProperty(alt, "LiftRefAttribute") as string; if (!String.IsNullOrEmpty(refer)) w.Write(" ref=\"{0}\"", MakeSafeAndNormalizedAttribute(refer)); w.WriteLine(">"); WriteAllFormsWithMarkers(w, null, null, "form", alt); foreach (var env in affixAllo.PhoneEnvRC) WritePhEnvironment(w, env); } break; case MoAffixProcessTags.kClassId: { w.WriteLine(">"); WriteAllFormsWithMarkers(w, null, null, "form", alt); } break; } if (alt.MorphTypeRA != null) WriteTrait(w, RangeNames.sDbMorphTypesOA, alt.MorphTypeRA.Name, m_wsEn); WriteCustomFields(w, alt); WriteLiftResidue(w, alt); w.WriteLine("</variant>"); }