public void GlossAddedEvent() { // Listen for events int lexemeAddedCount = 0; int senseAddedCount = 0; int glossAddedCount = 0; string glossText = ""; m_lexicon.LexemeAdded += (sender, e) => lexemeAddedCount++; m_lexicon.LexiconSenseAdded += (sender, e) => senseAddedCount++; m_lexicon.LexiconGlossAdded += (sender, e) => { glossAddedCount++; glossText = e.Gloss.Text; }; Lexeme lexeme = m_lexicon.FindOrCreateLexeme(LexemeType.Word, "word"); m_lexicon.AddLexeme(lexeme); LexiconSense sense = lexeme.AddSense(); sense.AddGloss("en", "somegloss"); Assert.AreEqual(1, glossAddedCount); Assert.AreEqual("somegloss", glossText); }
public void SensesRetained() { Lexeme lex = m_lexicon.CreateLexeme(LexemeType.Word, "a"); m_lexicon.AddLexeme(lex); LexiconSense sense = lex.AddSense(); sense.AddGloss("en", "glossen"); sense.AddGloss("fr", "glossfr"); Assert.AreEqual(1, lex.Senses.Count()); Assert.AreEqual(2, lex.Senses.First().Glosses.Count()); sense = m_lexicon[lex.Id].Senses.First(); // Make sure we're working with the one stored in the lexicon Assert.AreEqual("en", sense.Glosses.First().Language); Assert.AreEqual("glossen", sense.Glosses.First().Text); Assert.AreEqual("fr", sense.Glosses.ElementAt(1).Language); Assert.AreEqual("glossfr", sense.Glosses.ElementAt(1).Text); sense.RemoveGloss("en"); sense = m_lexicon[lex.Id].Senses.First(); // Make sure we're working with the one stored in the lexicon Assert.AreEqual(1, sense.Glosses.Count()); Assert.AreEqual("fr", sense.Glosses.First().Language); Assert.AreEqual("glossfr", sense.Glosses.First().Text); }
internal void OnLexiconGlossAdded(Lexeme lexeme, LexiconSense sense, LanguageText gloss) { if (LexiconGlossAdded != null) { LexiconGlossAdded(this, new FdoLexiconGlossAddedEventArgs(lexeme, sense, gloss)); } }
internal void OnLexiconSenseAdded(Lexeme lexeme, LexiconSense sense) { if (LexiconSenseAdded != null) { LexiconSenseAdded(this, new FdoLexiconSenseAddedEventArgs(lexeme, sense)); } }
public void RemoveSense(LexiconSense sense) { using (m_lexicon.ActivationContext.Activate()) { ILexEntry entry; if (!m_lexicon.TryGetEntry(m_key, out entry)) { return; } NonUndoableUnitOfWorkHelper.Do(m_lexicon.Cache.ActionHandlerAccessor, () => { var leSense = (LexSenseLexiconSense)sense; if (entry.AllSenses.Count == 1) { foreach (int ws in leSense.Sense.Gloss.AvailableWritingSystemIds) { leSense.Sense.Gloss.set_String(ws, (ITsString)null); } } else { leSense.Sense.Delete(); } }); } }
public void FindOrCreate() { Lexeme lex = m_lexicon.CreateLexeme(LexemeType.Word, "a"); LexiconSense sense = lex.AddSense(); sense.AddGloss("en", "monkey"); Lexeme lex2 = m_lexicon.FindOrCreateLexeme(LexemeType.Word, "a"); Assert.AreEqual(lex.Id, lex2.Id); Assert.AreEqual(LexemeType.Word, lex2.Type); Assert.AreEqual("a", lex2.LexicalForm); Assert.AreEqual(1, lex2.Senses.Count()); Assert.AreEqual(1, lex2.Senses.First().Glosses.Count()); Assert.AreEqual("en", lex2.Senses.First().Glosses.First().Language); Assert.AreEqual("monkey", lex2.Senses.First().Glosses.First().Text); Lexeme lex3 = m_lexicon.FindOrCreateLexeme(LexemeType.Suffix, "bob"); Assert.AreNotEqual(lex.Id, lex3.Id); Assert.AreNotEqual(lex2.Id, lex3.Id); Assert.AreEqual(LexemeType.Suffix, lex3.Type); Assert.AreEqual("bob", lex3.LexicalForm); Assert.AreEqual(0, lex3.Senses.Count()); }
public LexiconSense AddSense() { LexiconSense sense = null; bool lexemeAdded = false; using (m_lexicon.ActivationContext.Activate()) { NonUndoableUnitOfWorkHelper.Do(m_lexicon.Cache.ActionHandlerAccessor, () => { IWfiWordform wordform; if (!m_lexicon.TryGetWordform(m_key.LexicalForm, out wordform)) { wordform = m_lexicon.CreateWordform(m_key.LexicalForm); lexemeAdded = true; } // For wordforms, our "senses" could be new meanings of an analysis for the word // or it could be a brand new analysis. Because we have no idea what the user actually // wanted, we just assume the worst (they want to create a new analysis for the word // with a new meaning). IWfiAnalysis analysis = m_lexicon.Cache.ServiceLocator.GetInstance <IWfiAnalysisFactory>().Create(); wordform.AnalysesOC.Add(analysis); analysis.ApprovalStatusIcon = (int)Opinions.approves; // Assume the analysis from the external application is user approved IMoStemAllomorph morph = m_lexicon.Cache.ServiceLocator.GetInstance <IMoStemAllomorphRepository>().AllInstances().FirstOrDefault(allo => { ITsString tss = allo.Form.StringOrNull(m_lexicon.DefaultVernWs); if (tss != null) { return(tss.Text == LexicalForm.Normalize(NormalizationForm.FormD)); } return(false); }); if (morph != null) { IWfiMorphBundle mb = m_lexicon.Cache.ServiceLocator.GetInstance <IWfiMorphBundleFactory>().Create(); analysis.MorphBundlesOS.Add(mb); mb.MorphRA = morph; var entry = morph.OwnerOfClass <ILexEntry>(); mb.SenseRA = entry.SensesOS[0]; mb.MsaRA = entry.SensesOS[0].MorphoSyntaxAnalysisRA; } IWfiGloss gloss = m_lexicon.Cache.ServiceLocator.GetInstance <IWfiGlossFactory>().Create(); analysis.MeaningsOC.Add(gloss); sense = new WfiGlossLexiconSense(m_lexicon, m_key, gloss); }); } if (lexemeAdded) { m_lexicon.OnLexemeAdded(this); } m_lexicon.OnLexiconSenseAdded(this, sense); return(sense); }
public void AddingSenseAddsLexeme() { Lexeme lex = m_lexicon.CreateLexeme(LexemeType.Word, "a"); LexiconSense sense = lex.AddSense(); sense.AddGloss("en", "test"); Assert.AreEqual(1, m_lexicon.Lexemes.Count()); lex = m_lexicon[lex.Id]; // Make sure we're using the one stored in the lexicon Assert.AreEqual(LexemeType.Word, lex.Type); Assert.AreEqual("a", lex.LexicalForm); Assert.AreEqual(1, lex.Senses.Count()); Assert.AreEqual("en", lex.Senses.First().Glosses.First().Language); Assert.AreEqual("test", lex.Senses.First().Glosses.First().Text); }
public LexiconSense AddSense() { LexiconSense sense = null; bool lexemeAdded = false; m_lexicon.UpdatingEntries = true; try { using (m_lexicon.ActivationContext.Activate()) { NonUndoableUnitOfWorkHelper.Do(m_lexicon.Cache.ActionHandlerAccessor, () => { ILexEntry entry; if (!m_lexicon.TryGetEntry(m_key, out entry)) { entry = m_lexicon.CreateEntry(m_key); lexemeAdded = true; } if (entry.AllSenses.Count == 1 && entry.SensesOS[0].Gloss.StringCount == 0) { // An empty sense exists (probably was created during a call to AddLexeme) sense = new LexSenseLexiconSense(m_lexicon, m_key, entry.SensesOS[0]); } else { ILexSense newSense = m_lexicon.Cache.ServiceLocator.GetInstance <ILexSenseFactory>().Create( entry, new SandboxGenericMSA(), (string)null); sense = new LexSenseLexiconSense(m_lexicon, m_key, newSense); } }); } } finally { m_lexicon.UpdatingEntries = false; } if (lexemeAdded) { m_lexicon.OnLexemeAdded(this); } m_lexicon.OnLexiconSenseAdded(this, sense); return(sense); }
public void RemoveSense(LexiconSense sense) { NonUndoableUnitOfWorkHelper.Do(m_lexicon.Cache.ActionHandlerAccessor, () => { var glossSense = (WfiGlossLexiconSense)sense; if (!glossSense.Gloss.Analysis.OccurrencesInTexts.Any(seg => seg.AnalysesRS.Contains(glossSense.Gloss))) { IWfiAnalysis analysis = glossSense.Gloss.Analysis; if (analysis.MeaningsOC.Count == 1 && !analysis.OccurrencesInTexts.Any()) { analysis.Delete(); } else { glossSense.Gloss.Delete(); } } }); }
public void MultipleCreatesReferToSameSenses() { Lexeme lex = m_lexicon.CreateLexeme(LexemeType.Word, "a"); Lexeme lex2 = m_lexicon.CreateLexeme(LexemeType.Word, "a"); m_lexicon.AddLexeme(lex); LexiconSense sense = lex.AddSense(); sense.AddGloss("en", "test"); Assert.AreEqual(1, lex2.Senses.Count()); // Make sure the one that was added has the right sense now lex = m_lexicon[lex.Id]; Assert.AreEqual(LexemeType.Word, lex.Type); Assert.AreEqual("a", lex.LexicalForm); Assert.AreEqual(1, lex.Senses.Count()); Assert.AreEqual("en", lex.Senses.First().Glosses.First().Language); Assert.AreEqual("test", lex.Senses.First().Glosses.First().Text); }
public void RemoveSenseSucceeds() { Lexeme lex = m_lexicon.CreateLexeme(LexemeType.Word, "a"); m_lexicon.AddLexeme(lex); LexiconSense sense = lex.AddSense(); sense.AddGloss("en", "gloss1"); LexiconSense sense2 = lex.AddSense(); sense.AddGloss("en", "gloss1"); // Test remove at lex.RemoveSense(sense2); Assert.AreEqual(1, lex.Senses.Count()); Assert.AreEqual(sense, lex.Senses.First()); }
public void NormalizeStrings() { Lexeme lex = m_lexicon.CreateLexeme(LexemeType.Stem, "Vacaci\u00f3n"); // Uses composed accented letter 'o' m_lexicon.AddLexeme(lex); lex = m_lexicon[new LexemeKey(LexemeType.Stem, "Vacaci\u00f3n").Id]; Assert.IsNotNull(lex); Assert.AreEqual(LexemeType.Stem, lex.Type); Assert.AreEqual("Vacaci\u00f3n", lex.LexicalForm); LexiconSense sense = lex.AddSense(); Assert.IsNotNull(sense); LanguageText gloss = sense.AddGloss("en", "D\u00f3nde"); Lexeme reGetLex = m_lexicon[lex.Id]; Assert.AreEqual(gloss.Text, reGetLex.Senses.First().Glosses.First().Text); }
public FdoLexiconSenseAddedEventArgs(Lexeme lexeme, LexiconSense sense) { m_lexeme = lexeme; m_sense = sense; }
public FdoLexiconGlossAddedEventArgs(Lexeme lexeme, LexiconSense sense, LanguageText gloss) { m_lexeme = lexeme; m_sense = sense; m_gloss = gloss; }
public void RemoveSense(LexiconSense sense) { using (m_lexicon.ActivationContext.Activate()) { NonUndoableUnitOfWorkHelper.Do(m_lexicon.Cache.ActionHandlerAccessor, () => { var glossSense = (WfiGlossLexiconSense) sense; if (!glossSense.Gloss.Analysis.OccurrencesInTexts.Any(seg => seg.AnalysesRS.Contains(glossSense.Gloss))) { IWfiAnalysis analysis = glossSense.Gloss.Analysis; if (analysis.MeaningsOC.Count == 1 && !analysis.OccurrencesInTexts.Any()) analysis.Delete(); else glossSense.Gloss.Delete(); } }); } }
public void RemoveSense(LexiconSense sense) { using (m_lexicon.ActivationContext.Activate()) { ILexEntry entry; if (!m_lexicon.TryGetEntry(m_key, out entry)) return; NonUndoableUnitOfWorkHelper.Do(m_lexicon.Cache.ActionHandlerAccessor, () => { var leSense = (LexSenseLexiconSense)sense; if (entry.AllSenses.Count == 1) { foreach (int ws in leSense.Sense.Gloss.AvailableWritingSystemIds) leSense.Sense.Gloss.set_String(ws, (ITsString) null); } else { leSense.Sense.Delete(); } }); } }