Esempio n. 1
0
        public void LexEntriesComboHandler_ItemsInComboForInflVariant()
        {
            using (var sandbox = SetupSandbox(() =>
            {
                const string wff = "blonde";
                var mockText = MakeText(wff);
                var wf = MakeWordform(wff);
                var wa = MakeAnalysis(wf);
                var options = new MakeBundleOptions();
                options.LexEntryForm = wff;
                options.MakeMorph = (mff) =>
                {
                    Guid slotType = GetSlotType(mff);
                    IMoMorphSynAnalysis msa1;
                    var mainEntry = MakeEntry("blondEntry", "", slotType, out msa1);
                    var mainSense = MakeSense(mainEntry, "fair haired", msa1);

                    IMoMorphSynAnalysis msa2;
                    var variantEntry = MakeEntry("blondeEntry", "", slotType, out msa2);
                    ILexEntryType letDialectalVariantType = Cache.ServiceLocator.GetInstance <ILexEntryTypeRepository>().GetObject(LexEntryTypeTags.kguidLexTypDialectalVar);
                    letDialectalVariantType.Abbreviation.set_String(Cache.DefaultAnalWs, "dial.var. of");
                    letDialectalVariantType.Name.set_String(Cache.DefaultAnalWs, "Dialectal Variant");
                    letDialectalVariantType.ReverseAbbr.set_String(Cache.DefaultAnalWs, "dial.var.");

                    variantEntry.MakeVariantOf(mainSense, letDialectalVariantType);
                    return(variantEntry.LexemeFormOA);
                };
                options.MakeSense = (entry) =>
                {
                    var entryRef = entry.EntryRefsOS.First();
                    return(entryRef.ComponentLexemesRS.First() as ILexSense);
                };
                options.MakeMsa = (sense) => { return(sense.MorphoSyntaxAnalysisRA); };
                var wmb = MakeBundle(wa, options);
                var para = (IStTxtPara)mockText.ContentsOA.ParagraphsOS[0];
                var seg = para.SegmentsOS[0];
                seg.AnalysesRS.Add(wa);
                return(new AnalysisOccurrence(seg, 0));
            }))
            {
                var initialAnalysisStack = sandbox.CurrentAnalysisTree;
                using (var handler = GetComboHandler(sandbox, InterlinLineChoices.kflidLexEntries, 0) as SandboxBase.IhMissingEntry)
                {
                    var imorphItemCurrentSandboxState = handler.IndexOfCurrentItem;

                    Assert.That(imorphItemCurrentSandboxState, Is.EqualTo(1));

                    var handlerList = handler.ComboList.Items;

                    Assert.That(handlerList[0].ToString(), Is.EqualTo("Add New Sense for blondeEntry ..."));
                    Assert.That(handlerList[1].ToString(), Is.EqualTo("  fair haired, ???, blondEntry+dial.var."));
                    Assert.That(handlerList[2].ToString(), Is.EqualTo("    Add New Sense..."));
                }
            }
        }
Esempio n. 2
0
        protected ILexEntry AddVariantLexeme(List <ICmObject> addList, IVariantComponentLexeme origLe,
                                             string lexForm, IMoMorphType morphTypePoss, string gloss, IPartOfSpeech categoryPoss,
                                             ILexEntryType varType)
        {
            Assert.IsNotNull(varType, "Need a variant entry type!");
            var msa = new SandboxGenericMSA {
                MainPOS = categoryPoss
            };
            var comp = new LexEntryComponents {
                MorphType = morphTypePoss, MSA = msa
            };

            comp.GlossAlternatives.Add(m_tssFact.MakeString(gloss, Cache.DefaultAnalWs));
            comp.LexemeFormAlternatives.Add(m_tssFact.MakeString(lexForm, Cache.DefaultVernWs));
            var entry = m_entryFact.Create(comp);

            entry.MakeVariantOf(origLe, varType);
            addList.Add(entry);
            return(entry);
        }
Esempio n. 3
0
        /// <summary>
        /// </summary>
        /// <param name="variantEntryType"></param>
        /// <param name="gloss"></param>
        /// <param name="wsGloss"></param>
        /// <returns></returns>
        public static ITsString MakeGlossOptionWithInflVariantTypes(ILexEntryType variantEntryType, IMultiStringAccessor gloss, CoreWritingSystemDefinition wsGloss)
        {
            var inflVariantEntryType = variantEntryType as ILexEntryInflType;

            if (gloss == null || inflVariantEntryType == null)
            {
                return(null);
            }

            int       wsActual2;
            ITsString tssGloss = gloss.GetAlternativeOrBestTss(wsGloss.Handle, out wsActual2);

            if (tssGloss.Length == 0)
            {
                tssGloss = gloss.NotFoundTss;
            }

            var sb     = TsStringUtils.MakeIncStrBldr();
            var cache  = inflVariantEntryType.Cache;
            var wsUser = cache.ServiceLocator.WritingSystemManager.UserWritingSystem;

            ITsString tssGlossPrepend = AddTssGlossAffix(sb, inflVariantEntryType.GlossPrepend, wsGloss, wsUser);

            sb.AppendTsString(tssGloss);
            if (sb.Text.Length == 0)
            {
                return(null);                // TODO: add default value for gloss?
            }
            ITsString tssGlossAppend = AddTssGlossAffix(sb, inflVariantEntryType.GlossAppend, wsGloss, wsUser);

            if ((tssGlossPrepend == null || tssGlossPrepend.Length == 0) &&
                (tssGlossAppend == null || tssGlossAppend.Length == 0))
            {
                return(MakeGlossWithReverseAbbrs(gloss, wsGloss, new[] { variantEntryType }));
            }

            return(sb.GetString());
        }
		/// <summary>
		/// extracts the variant and component from the dialog, depending upon whether we're
		/// called from an "Insert Variant" or "Variant Of..." context.
		/// </summary>
		/// <param name="variant"></param>
		/// <param name="componentLexeme"></param>
		private void GetVariantAndComponentAndSelectedEntryType(out ILexEntry variant, out IVariantComponentLexeme componentLexeme, out ILexEntryType selectedEntryType)
		{
			variant = null;
			componentLexeme = null;
			if (m_fBackRefToVariant)
			{
				// in "Insert Variant" contexts,
				// we're calling the dialog from the component lexeme, so consider SelectedID as the variant.
				componentLexeme = m_startingEntry;
				variant = LexEntry.CreateFromDBObject(m_cache, SelectedID);
			}
			else
			{
				// in "Variant of..." contexts,
				// we're calling the dialog from the variant, so consider SelectedID the componentLexeme.
				variant = m_startingEntry;
				componentLexeme = CmObject.CreateFromDBObject(m_cache, SelectedID) as IVariantComponentLexeme;
			}
			if (m_fGetVariantEntryTypeFromTreeCombo)
				selectedEntryType = LexEntryType.CreateFromDBObject(m_cache, SelectedVariantEntryTypeHvo);
			else
				selectedEntryType = null;
		}
Esempio n. 5
0
		/// <summary>
		/// creates a variant entry from this (main) sense,
		/// and links the variant to this (main) sense via
		/// EntryRefs.ComponentLexemes
		/// </summary>
		/// <param name="variantType">the type of the new variant</param>
		/// <param name="tssVariantLexemeForm">the lexeme form of the new variant</param>
		/// <returns>the new variant entry reference</returns>
		public ILexEntryRef CreateVariantEntryAndBackRef(ILexEntryType variantType, ITsString tssVariantLexemeForm)
		{
			int hvoOwnerEntry = Cache.GetOwnerOfObjectOfClass(this.Hvo, LexEntry.kclsidLexEntry);
			LexEntry entry = LexEntry.CreateFromDBObject(Cache, hvoOwnerEntry) as LexEntry;
			return entry.CreateVariantEntryAndBackRef(this, variantType, tssVariantLexemeForm);
		}
Esempio n. 6
0
		private void cbComplexFormType_SelectedIndexChanged(object sender, EventArgs e)
		{
			m_complexType = m_cbComplexFormType.SelectedItem as ILexEntryType;
			m_fComplexForm = m_complexType != null;
			if (!m_fComplexForm)
			{
				var dum = (DummyEntryType)m_cbComplexFormType.SelectedItem;
				m_fComplexForm = dum.IsComplexForm;
			}
		}
Esempio n. 7
0
		/// <summary>
		///
		/// </summary>
		/// <param name="mainEntryOrSense"></param>
		/// <param name="variantEntryType"></param>
		/// <param name="targetVariantLexemeForm"></param>
		/// <returns></returns>
		public static ILexEntryRef FindMatchingVariantEntryBackRef(IVariantComponentLexeme mainEntryOrSense,
			ILexEntryType variantEntryType, ITsString targetVariantLexemeForm)
		{
			ILexEntryRef matchingEntryRef = null;
			foreach (int hvoLexEntryRef in mainEntryOrSense.VariantFormEntryBackRefs)
			{
				ILexEntryRef ler = LexEntryRef.CreateFromDBObject((mainEntryOrSense as ICmObject).Cache, hvoLexEntryRef);
				// this only handles matching single component lexemes,
				// so we only try to match those.
				if (ler.ComponentLexemesRS.Count == 1)
				{
					// next see if we can match on the same variant lexeme form
					ILexEntry variantEntry = (ler as CmObject).Owner as ILexEntry;
					if (variantEntry.LexemeFormOA == null || variantEntry.LexemeFormOA.Form == null)
						continue;
					int wsTargetVariant = StringUtils.GetWsAtOffset(targetVariantLexemeForm, 0);
					if (targetVariantLexemeForm.Equals(variantEntry.LexemeFormOA.Form.GetAlternativeTss(wsTargetVariant)))
					{
						// consider this a possible match. we'll use the last such possibility
						// if we can't find a matching variantEntryType (below.)
						matchingEntryRef = ler;
						// next see if we can also match against the type, we'll just 'use' that one.
						// otherwise keep going just in case we can find one that does match.
						if (variantEntryType != null && ler.VariantEntryTypesRS.Contains(variantEntryType))
							break;
					}
					// continue...
				}
			}
			return matchingEntryRef;
		}
Esempio n. 8
0
		/// <summary>
		/// creates a variant entry from this (main) sense,
		/// and links the variant to this (main) sense via
		/// EntryRefs.ComponentLexemes
		///
		/// NOTE: The caller will need to supply the lexemeForm subsequently.
		/// </summary>
		/// <param name="variantType">the type of the new variant</param>
		/// <returns>the new variant entry reference</returns>
		public ILexEntryRef CreateVariantEntryAndBackRef(ILexEntryType variantType)
		{
			return this.CreateVariantEntryAndBackRef(variantType, null);
		}
Esempio n. 9
0
		/// <summary>
		/// Make this entry a variant of the given componentLexeme (primary entry) with
		/// the given variantType
		/// </summary>
		/// <param name="componentLexeme"></param>
		/// <param name="variantType"></param>
		public ILexEntryRef MakeVariantOf(IVariantComponentLexeme componentLexeme, ILexEntryType variantType)
		{
			ILexEntryRef ler = this.EntryRefsOS.Append(new LexEntryRef());
			ler.RefType = LexEntryRef.krtVariant; // variant by default, but good to be explicit here.
			ler.HideMinorEntry = 0;
			ler.ComponentLexemesRS.Append(componentLexeme);
			if (variantType != null)
				ler.VariantEntryTypesRS.Append(variantType);
			return ler;
		}
Esempio n. 10
0
		/// <summary>
		/// Find a LexEntryRef matching the given targetComponent (exlusively), and variantEntryType.
		/// If we can't match on variantEntryType, we'll just return the reference with the matching component.
		/// </summary>
		/// <param name="targetComponent">match on the LexEntryRef that contains this, and only this component.</param>
		/// <param name="variantEntryType"></param>
		/// <returns></returns>
		public ILexEntryRef FindMatchingVariantEntryRef(IVariantComponentLexeme targetComponent, ILexEntryType variantEntryType)
		{
			ILexEntryRef matchingEntryRef = null;
			foreach (ILexEntryRef ler in EntryRefsOS)
			{
				if (ler.RefType == LexEntryRef.krtVariant &&
					ler.ComponentLexemesRS.Count == 1 &&
					ler.ComponentLexemesRS.Contains(targetComponent))
				{
					matchingEntryRef = ler;
					// next see if we can also match against the type, we'll just 'use' that one.
					// otherwise keep going just in case we can find one that does match.
					if (variantEntryType != null && ler.VariantEntryTypesRS.Contains(variantEntryType))
						break;
				}
			}
			return matchingEntryRef;
		}
Esempio n. 11
0
		private void cbComplexFormType_SelectedIndexChanged(object sender, EventArgs e)
		{
			m_complexType = cbComplexFormType.SelectedItem as ILexEntryType;
			m_fComplexForm = m_complexType != null;
			if (!m_fComplexForm)
			{
				DummyEntryType dum = cbComplexFormType.SelectedItem as DummyEntryType;
				Debug.Assert(dum != null);
				m_fComplexForm = dum.IsComplexForm;
			}
		}
Esempio n. 12
0
		/// <summary>
		/// creates a variant entry from this (main) entry using its lexemeForm information,
		/// and links the variant to the given componentLexeme entry via
		/// EntryRefs.ComponentLexemes
		/// </summary>
		/// <param name="variantType">the type of the new variant</param>
		/// <param name="componentLexeme">the entry or sense of which the new variant entry is a variant</param>
		/// <param name="tssVariantLexemeForm">the lexeme form of the new variant</param>
		/// <returns>the new variant entry reference</returns>
		internal ILexEntryRef CreateVariantEntryAndBackRef(IVariantComponentLexeme componentLexeme, ILexEntryType variantType, ITsString tssVariantLexemeForm)
		{
			using (new UndoRedoTaskHelper(Cache, Strings.ksUndoCreateVariantEntry, Strings.ksRedoCreateVariantEntry))
			{
				ILexEntry variantEntry = new LexEntry();
				Cache.LangProject.LexDbOA.EntriesOC.Add(variantEntry);
				if (this.LexemeFormOA is IMoAffixAllomorph)
					variantEntry.LexemeFormOA = new MoAffixAllomorph();
				else
					variantEntry.LexemeFormOA = new MoStemAllomorph();
				if (this.LexemeFormOA != null)
					variantEntry.LexemeFormOA.MorphTypeRAHvo = this.LexemeFormOA.MorphTypeRAHvo;
				if (tssVariantLexemeForm != null)
					variantEntry.LexemeFormOA.FormMinusReservedMarkers = tssVariantLexemeForm;
				(variantEntry as LexEntry).UpdateHomographNumbersAccountingForNewEntry();
				return (variantEntry as LexEntry).MakeVariantOf(componentLexeme, variantType);
			}
		}
Esempio n. 13
0
        private static ILexEntryRef CreateComplexForm(LcmCache cache, ICmObject main, ILexEntry complexForm, bool subentry, ILexEntryType complexEntryType)
        {
            var complexEntryRef = cache.ServiceLocator.GetInstance <ILexEntryRefFactory>().Create();

            complexForm.EntryRefsOS.Add(complexEntryRef);
            var complexEntryTypeAbbrText = complexEntryType.Abbreviation.BestAnalysisAlternative.Text;
            var complexEntryTypeRevAbbr  = complexEntryType.ReverseAbbr;

            // If there is no reverseAbbr, generate one from the forward abbr (e.g. "comp. of") by trimming the trailing " of"
            if (complexEntryTypeRevAbbr.BestAnalysisAlternative.Equals(complexEntryTypeRevAbbr.NotFoundTss))
            {
                complexEntryTypeRevAbbr.SetAnalysisDefaultWritingSystem(complexEntryTypeAbbrText.Substring(0, complexEntryTypeAbbrText.Length - 3));
            }
            complexEntryRef.ComplexEntryTypesRS.Add(complexEntryType);
            complexEntryRef.RefType = LexEntryRefTags.krtComplexForm;
            complexEntryRef.ComponentLexemesRS.Add(main);
            if (subentry)
            {
                complexEntryRef.PrimaryLexemesRS.Add(main);
            }
            else
            {
                complexEntryRef.ShowComplexFormsInRS.Add(main);
            }
            return(complexEntryRef);
        }
		private ILexEntryRef FindMatchingEntryRef(ILexEntry variant, IVariantComponentLexeme componentLexeme, ILexEntryType selectedEntryType)
		{
			ILexEntryRef matchingEntryRef = null;
			if (variant != null)
			{
				// see if the starting entry has the SelectedID already as a ComponentLexeme
				matchingEntryRef = (variant as LexEntry).FindMatchingVariantEntryRef(componentLexeme,
					selectedEntryType);
			}
			else
			{
				// determine whether the selected entry or sense is already
				// linked to an existing variant with the given lexeme form.
				matchingEntryRef = LexEntry.FindMatchingVariantEntryBackRef(componentLexeme,
					selectedEntryType, m_tssVariantLexemeForm);
			}
			return matchingEntryRef;
		}
Esempio n. 15
0
			/// <summary>
			/// create a variant and link it to the given leMain entry
			/// and confirm this analysis on the given (monomorphemic) cba.
			/// </summary>
			/// <param name="iSegment"></param>
			/// <param name="iSegForm"></param>
			/// <param name="leMain"></param>
			/// <param name="variantType"></param>
			/// <returns>hvo of the resulting LexEntryRef</returns>
			virtual public ILexEntryRef SetVariantOf(int iSegment, int iSegForm, ILexEntry leMain, ILexEntryType variantType)
			{
				if (variantType == null)
					throw new ArgumentNullException("requires non-null variantType parameter.");
				// for now, just create the variant entry and the variant of target, treating the wordform as monomorphemic.
				ITsString tssVariantLexemeForm = GetBaselineText(iSegment, iSegForm);
				ILexEntryRef ler = leMain.CreateVariantEntryAndBackRef(variantType, tssVariantLexemeForm);
				ILexEntry variant = ler.Owner as ILexEntry;
				ArrayList morphs = new ArrayList(1);
				morphs.Add(variant.LexemeFormOA);
				BreakIntoMorphs(iSegment, iSegForm, morphs);
				ILexEntry mainEntry;
				ILexSense mainSense;
				MorphServices.GetMainEntryAndSenseStack(ler.ComponentLexemesRS.First() as IVariantComponentLexeme, out mainEntry, out mainSense);
				SetMorphSense(iSegment, iSegForm, 0, mainSense);
				return ler;
			}
Esempio n. 16
0
 private void ExportLexEntryTypeFields(TextWriter w, ILexEntryType item)
 {
     if (item != null)
         ExportMultiUnicode(w, item.ReverseAbbr);
 }
Esempio n. 17
0
        private ILexEntryRef FindMatchingEntryRef(ILexEntry variant, IVariantComponentLexeme componentLexeme, ILexEntryType selectedEntryType)
        {
            ILexEntryRef matchingEntryRef;

            if (variant != null)
            {
                // see if the starting entry has the SelectedID already as a ComponentLexeme
                matchingEntryRef = variant.FindMatchingVariantEntryRef(componentLexeme,
                                                                       selectedEntryType);
            }
            else
            {
                // determine whether the selected entry or sense is already
                // linked to an existing variant with the given lexeme form.
                matchingEntryRef = componentLexeme.FindMatchingVariantEntryBackRef(selectedEntryType, m_tssVariantLexemeForm);
            }
            return(matchingEntryRef);
        }
Esempio n. 18
0
 /// <summary>
 /// extracts the variant and component from the dialog, depending upon whether we're
 /// called from an "Insert Variant" or "Variant Of..." context.
 /// </summary>
 /// <param name="variant">The variant.</param>
 /// <param name="componentLexeme">The component lexeme.</param>
 /// <param name="selectedEntryType">Type of the selected entry.</param>
 private void GetVariantAndComponentAndSelectedEntryType(out ILexEntry variant, out IVariantComponentLexeme componentLexeme, out ILexEntryType selectedEntryType)
 {
     if (m_fBackRefToVariant)
     {
         // in "Insert Variant" contexts,
         // we're calling the dialog from the component lexeme, so consider SelectedID as the variant.
         componentLexeme = m_startingEntry;
         variant         = SelectedObject as ILexEntry;
     }
     else
     {
         // in "Variant of..." contexts,
         // we're calling the dialog from the variant, so consider SelectedID the componentLexeme.
         variant         = m_startingEntry;
         componentLexeme = SelectedObject as IVariantComponentLexeme;
     }
     selectedEntryType = m_fGetVariantEntryTypeFromTreeCombo
                         ? m_cache.ServiceLocator.GetInstance <ILexEntryTypeRepository>().GetObject(SelectedVariantEntryTypeHvo) : null;
 }
		/// <summary>
		/// extracts the variant and component from the dialog, depending upon whether we're
		/// called from an "Insert Variant" or "Variant Of..." context.
		/// </summary>
		/// <param name="variant">The variant.</param>
		/// <param name="componentLexeme">The component lexeme.</param>
		/// <param name="selectedEntryType">Type of the selected entry.</param>
		private void GetVariantAndComponentAndSelectedEntryType(out ILexEntry variant, out IVariantComponentLexeme componentLexeme, out ILexEntryType selectedEntryType)
		{
			if (m_fBackRefToVariant)
			{
				// in "Insert Variant" contexts,
				// we're calling the dialog from the component lexeme, so consider SelectedID as the variant.
				componentLexeme = m_startingEntry;
				variant = SelectedObject as ILexEntry;
			}
			else
			{
				// in "Variant of..." contexts,
				// we're calling the dialog from the variant, so consider SelectedID the componentLexeme.
				variant = m_startingEntry;
				componentLexeme = SelectedObject as IVariantComponentLexeme;
			}
			selectedEntryType = m_fGetVariantEntryTypeFromTreeCombo
				? m_cache.ServiceLocator.GetInstance<ILexEntryTypeRepository>().GetObject(SelectedVariantEntryTypeHvo) : null;
		}
Esempio n. 20
0
		/// <summary>
		/// creates a variant entry from this (main) entry,
		/// and links the variant to this (main) entry via
		/// EntryRefs.ComponentLexemes
		/// </summary>
		/// <param name="variantType">the type of the new variant</param>
		/// <param name="tssVariantLexemeForm">the lexeme form of the new variant</param>
		/// <returns>the new variant entry reference</returns>
		public ILexEntryRef CreateVariantEntryAndBackRef(ILexEntryType variantType, ITsString tssVariantLexemeForm)
		{
			return CreateVariantEntryAndBackRef(this, variantType, tssVariantLexemeForm);
		}
Esempio n. 21
0
 /// <summary>
 /// extracts the variant and component from the dialog, depending upon whether we're
 /// called from an "Insert Variant" or "Variant Of..." context.
 /// </summary>
 /// <param name="variant"></param>
 /// <param name="componentLexeme"></param>
 private void GetVariantAndComponentAndSelectedEntryType(out ILexEntry variant, out IVariantComponentLexeme componentLexeme, out ILexEntryType selectedEntryType)
 {
     variant         = null;
     componentLexeme = null;
     if (m_fBackRefToVariant)
     {
         // in "Insert Variant" contexts,
         // we're calling the dialog from the component lexeme, so consider SelectedID as the variant.
         componentLexeme = m_startingEntry;
         variant         = LexEntry.CreateFromDBObject(m_cache, SelectedID);
     }
     else
     {
         // in "Variant of..." contexts,
         // we're calling the dialog from the variant, so consider SelectedID the componentLexeme.
         variant         = m_startingEntry;
         componentLexeme = CmObject.CreateFromDBObject(m_cache, SelectedID) as IVariantComponentLexeme;
     }
     if (m_fGetVariantEntryTypeFromTreeCombo)
     {
         selectedEntryType = LexEntryType.CreateFromDBObject(m_cache, SelectedVariantEntryTypeHvo);
     }
     else
     {
         selectedEntryType = null;
     }
 }