Ejemplo n.º 1
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Create an allomorph.
		/// </summary>
		/// <param name="entry">The entry.</param>
		/// <param name="msa">The msa.</param>
		/// <param name="tssform">The tssform.</param>
		/// <param name="morphType">Type of the morph.</param>
		/// <param name="fLexemeForm">set to <c>true</c> to create a lexeme form.</param>
		/// <returns></returns>
		/// ------------------------------------------------------------------------------------
		internal static IMoForm CreateAllomorph(ILexEntry entry, IMoMorphSynAnalysis msa,
											  ITsString tssform, IMoMorphType morphType, bool fLexemeForm)
		{
			MoForm allomorph = null;
			switch (morphType.Guid.ToString())
			{
				case MoMorphTypeTags.kMorphProclitic: // Fall through.
				case MoMorphTypeTags.kMorphClitic: // Fall through.
				case MoMorphTypeTags.kMorphEnclitic:
					Debug.Assert(msa is MoStemMsa, "Wrong MSA for a clitic.");
#pragma warning disable 168
					var stemMsa = (IMoStemMsa)msa;
#pragma warning restore 168
					goto case MoMorphTypeTags.kMorphBoundStem;
				case MoMorphTypeTags.kMorphRoot: // Fall through.
				case MoMorphTypeTags.kMorphBoundRoot: // Fall through.
				case MoMorphTypeTags.kMorphStem: // Fall through.
				case MoMorphTypeTags.kMorphParticle: // Fall through.
				case MoMorphTypeTags.kMorphPhrase: // Fall through.
				case MoMorphTypeTags.kMorphDiscontiguousPhrase: // Fall through.
					// AndyB_Yahoo: On particles, (and LT-485), these are always to be
					// roots that never take any affixes
					// AndyB_Yahoo: Therefore, they need to have StemMsas and Stem
					// allomorphs
				case MoMorphTypeTags.kMorphBoundStem:
					allomorph = new MoStemAllomorph();
					break;
				default:
					// All others, which should get an non-stem MSA and an affix allo.
					Debug.Assert(!(msa is IMoStemMsa), "Wrong MSA for a affix.");
					allomorph = new MoAffixAllomorph();
					break;
			}
			if (fLexemeForm)
				entry.LexemeFormOA = allomorph;
			else
				entry.AlternateFormsOS.Add(allomorph);
			allomorph.MorphTypeRA = morphType; // Has to be done before the next call.
			ITsString tssAllomorphForm = tssform;

			allomorph.FormMinusReservedMarkers = tssAllomorphForm;
			if ((morphType.Guid == MoMorphTypeTags.kguidMorphInfix) ||
				(morphType.Guid == MoMorphTypeTags.kguidMorphInfixingInterfix))
			{
				HandleInfix(entry, allomorph);
			}
			return allomorph;
		}
Ejemplo n.º 2
0
		/// <summary>
		/// Create a new circumfix allomorph and add it to the given entry.
		/// </summary>
		/// <param name="entry"></param>
		/// <param name="sense"></param>
		/// <param name="lexemeForm"></param>
		/// <param name="morphType"></param>
		/// <returns></returns>
		public IMoAffixAllomorph CreateCircumfix(ILexEntry entry, ILexSense sense, ITsString lexemeForm, IMoMorphType morphType)
		{
			var lexemeAllo = new MoAffixAllomorph();
			entry.LexemeFormOA = lexemeAllo;
			lexemeAllo.Form.set_String(TsStringUtils.GetWsAtOffset(lexemeForm, 0), lexemeForm);
			lexemeAllo.MorphTypeRA = morphType;
			lexemeAllo.IsAbstract = true;

			// split citation form into left and right parts
			var aSpacePeriod = new[] { ' ', '.' };
			var lexemeFormAsString = lexemeForm.Text;
			var wsVern = TsStringUtils.GetWsAtOffset(lexemeForm, 0);
			var iLeftEnd = lexemeFormAsString.IndexOfAny(aSpacePeriod);
			var sLeftMember = iLeftEnd < 0 ? lexemeFormAsString : lexemeFormAsString.Substring(0, iLeftEnd);
			var iRightBegin = lexemeFormAsString.LastIndexOfAny(aSpacePeriod);
			var sRightMember = iRightBegin < 0 ? lexemeFormAsString : lexemeFormAsString.Substring(iRightBegin + 1);
			// Create left and right allomorphs
			IMoMorphType mmtPrefix;
			IMoMorphType mmtSuffix;
			IMoMorphType mmtInfix;
			MorphServices.GetMajorAffixMorphTypes(m_cache, out mmtPrefix, out mmtSuffix, out mmtInfix);
			int clsidForm;
			var mmt = MorphServices.FindMorphType(m_cache, ref sLeftMember, out clsidForm);
			if ((mmt.Hvo != mmtPrefix.Hvo) &&
				(mmt.Hvo != mmtInfix.Hvo))
				mmt = mmtPrefix; // force a prefix if it's neither a prefix nor an infix
#pragma warning disable 168
			var allomorph = MoForm.CreateAllomorph(entry, sense.MorphoSyntaxAnalysisRA,
												   TsStringUtils.MakeTss(sLeftMember, wsVern), mmt, false);
#pragma warning disable 168
			mmt = MorphServices.FindMorphType(m_cache, ref sRightMember, out clsidForm);
			if ((mmt.Hvo != mmtInfix.Hvo) &&
				(mmt.Hvo != mmtSuffix.Hvo))
				mmt = mmtSuffix; // force a suffix if it's neither a suffix nor an infix
			allomorph = MoForm.CreateAllomorph(entry, sense.MorphoSyntaxAnalysisRA,
											   TsStringUtils.MakeTss(sRightMember, wsVern), mmt, false);

			return lexemeAllo;
		}