/// ------------------------------------------------------------------------------------
        /// <summary>
        /// Adds the lexeme to the lexicon.
        /// </summary>
        /// <exception cref="ArgumentException">if matching lexeme is already in lexicon</exception>
        /// ------------------------------------------------------------------------------------
        public void AddLexeme(LexicalEntry lexeme)
        {
            LexicalProviderManager.ResetLexicalProviderTimer();
            Logger.WriteEvent("Adding new lexeme from an external application: " + lexeme.LexicalForm);

            NonUndoableUnitOfWorkHelper.Do(m_cache.ActionHandlerAccessor, () =>
            {
                string sForm = lexeme.LexicalForm;
                switch (lexeme.Type)
                {
                case LexemeType.Word:
                    ITsString tss = TsStringUtils.MakeTss(lexeme.LexicalForm, m_cache.DefaultVernWs);
                    m_cache.ServiceLocator.GetInstance <IWfiWordformFactory>().Create(tss);
                    break;

                default:
                    {
                        SandboxGenericMSA msa = new SandboxGenericMSA();
                        msa.MsaType           = (lexeme.Type == LexemeType.Stem) ? MsaType.kStem : MsaType.kUnclassified;

                        IMoMorphType morphType = GetMorphTypeForLexemeType(lexeme.Type);
                        ITsString tssForm      = TsStringUtils.MakeTss(sForm, m_cache.DefaultVernWs);
                        m_cache.ServiceLocator.GetInstance <ILexEntryFactory>().Create(morphType, tssForm, null, msa);
                        break;
                    }
                }
            });
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Creates a new LexicalEntry from the specified word form in the DB
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private LexicalEntry CreateEntryFromDbWordform(IWfiWordform wordform)
        {
            const int    homograph = 1;
            LexicalEntry entry     = new LexicalEntry(LexemeType.Word, wordform.Form.VernacularDefaultWritingSystem.Text, homograph);

            foreach (IWfiAnalysis dbAnalysis in wordform.AnalysesOC)
            {
                // Since our "sense" is really an analysis for a wordform, assume that any meanings
                // for that analysis are glosses for the same "sense".
                LexSense sense = new LexSense(kAnalysisPrefix + dbAnalysis.Guid.ToString());
                foreach (IWfiGloss gloss in dbAnalysis.MeaningsOC)
                {
                    AddDbGlossesToSense(sense, gloss.Form);
                }
                entry.Senses.Add(sense);
            }
            return(entry);
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Creates a new LexicalEntry from the specified lexical entry in the DB
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private LexicalEntry CreateEntryFromDbEntry(LexemeType type, ILexEntry dbEntry)
        {
            if (type == LexemeType.Word)
            {
                throw new ArgumentException("Lexeme type specified can not be created from a LexEntry");
            }

            // A homograph number of zero in the DB means there is only one entry for the wordform.
            // However, the interface requires there be an entry with a homograph of one even if
            // there is only one entry.
            LexicalEntry entry = new LexicalEntry(type, dbEntry.HomographForm,
                                                  dbEntry.HomographNumber > 0 ? dbEntry.HomographNumber : 1);

            // Add the senses to the interface (non-DB) entry
            foreach (ILexSense dbSense in dbEntry.SensesOS)
            {
                LexSense sense = new LexSense(dbSense.Guid.ToString());
                AddDbGlossesToSense(sense, dbSense.Gloss);
                entry.Senses.Add(sense);                 // Add the sense to the list of senses
            }
            return(entry);
        }
Exemplo n.º 4
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Creates a new LexicalEntry from the specified word form in the DB
		/// </summary>
		/// ------------------------------------------------------------------------------------
		private LexicalEntry CreateEntryFromDbWordform(IWfiWordform wordform)
		{
			const int homograph = 1;
			LexicalEntry entry = new LexicalEntry(LexemeType.Word, wordform.Form.VernacularDefaultWritingSystem.Text, homograph);
			foreach (IWfiAnalysis dbAnalysis in wordform.AnalysesOC)
			{
				// Since our "sense" is really an analysis for a wordform, assume that any meanings
				// for that analysis are glosses for the same "sense".
				LexSense sense = new LexSense(kAnalysisPrefix + dbAnalysis.Guid.ToString());
				foreach (IWfiGloss gloss in dbAnalysis.MeaningsOC)
					AddDbGlossesToSense(sense, gloss.Form);
				entry.Senses.Add(sense);
			}
			return entry;
		}
Exemplo n.º 5
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Creates a new LexicalEntry from the specified lexical entry in the DB
		/// </summary>
		/// ------------------------------------------------------------------------------------
		private LexicalEntry CreateEntryFromDbEntry(LexemeType type, ILexEntry dbEntry)
		{
			if (type == LexemeType.Word)
				throw new ArgumentException("Lexeme type specified can not be created from a LexEntry");

			// A homograph number of zero in the DB means there is only one entry for the wordform.
			// However, the interface requires there be an entry with a homograph of one even if
			// there is only one entry.
			LexicalEntry entry = new LexicalEntry(type, dbEntry.HomographForm,
				dbEntry.HomographNumber > 0 ? dbEntry.HomographNumber : 1);

			// Add the senses to the interface (non-DB) entry
			foreach (ILexSense dbSense in dbEntry.SensesOS)
			{
				LexSense sense = new LexSense(dbSense.Guid.ToString());
				AddDbGlossesToSense(sense, dbSense.Gloss);
				entry.Senses.Add(sense); // Add the sense to the list of senses
			}
			return entry;
		}
Exemplo n.º 6
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Adds the lexeme to the lexicon.
		/// </summary>
		/// <exception cref="ArgumentException">if matching lexeme is already in lexicon</exception>
		/// ------------------------------------------------------------------------------------
		public void AddLexeme(LexicalEntry lexeme)
		{
			LexicalProviderManager.ResetLexicalProviderTimer();
			Logger.WriteEvent("Adding new lexeme from an external application: " + lexeme.LexicalForm);

			NonUndoableUnitOfWorkHelper.Do(m_cache.ActionHandlerAccessor, () =>
				{
					string sForm = lexeme.LexicalForm;
					switch(lexeme.Type)
					{
						case LexemeType.Word:
							ITsString tss = TsStringUtils.MakeTss(lexeme.LexicalForm, m_cache.DefaultVernWs);
							m_cache.ServiceLocator.GetInstance<IWfiWordformFactory>().Create(tss);
							break;
						default:
						{
							SandboxGenericMSA msa = new SandboxGenericMSA();
							msa.MsaType = (lexeme.Type == LexemeType.Stem) ? MsaType.kStem : MsaType.kUnclassified;

							IMoMorphType morphType = GetMorphTypeForLexemeType(lexeme.Type);
							ITsString tssForm = TsStringUtils.MakeTss(sForm, m_cache.DefaultVernWs);
							m_cache.ServiceLocator.GetInstance<ILexEntryFactory>().Create(morphType, tssForm, (ITsString) null, msa);
							break;
						}
					}
				});
		}