Esempio n. 1
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Appends all the alternatives from the source multi string to the alternatives of
 /// this here one.
 /// </summary>
 /// <param name="src">The source.</param>
 /// <param name="fPreventDuplication"><c>true</c> to avoid appending a string that is
 /// identical that matches the end of the existing string.</param>
 /// ------------------------------------------------------------------------------------
 public void AppendAlternatives(IMultiStringAccessor src, bool fPreventDuplication)
 {
     foreach (int ws in src.AvailableWritingSystemIds)
     {
         ITsString sourceStr = src.get_String(ws);
         if (sourceStr.Length == 0)
         {
             continue;
         }
         ITsString originalDest = get_String(ws);
         if (originalDest.Length == 0)
         {
             // There is no translation in the destination string, so just replace the
             // empty string with the source
             set_String(ws, sourceStr);
         }
         else
         {
             // There is existing translation in the destination string, so we need to merge
             // the translations. This should happen only for the first moved translation
             if (!originalDest.Text.EndsWith(sourceStr.Text, StringComparison.Ordinal))
             {
                 set_String(ws, originalDest.ConcatenateWithSpaceIfNeeded(sourceStr));
             }
         }
     }
 }
Esempio n. 2
0
 /// <summary>
 /// Merge two MultiUnicodeAccessor objects.
 /// These cases are handled:
 ///		1. If an alternative exists in both objects, nothing is merged.
 ///		2. If the main object (this) is missing an alternative, and the 'source' has it, then add it to 'this'.
 ///		3. If the main object has an alternative, then do nothing.
 /// </summary>
 /// <param name="source"></param>
 /// <param name="fConcatenateIfBoth"></param>
 /// <param name="sep">separator to use if concatenating</param>
 public void MergeAlternatives(IMultiStringAccessor source, bool fConcatenateIfBoth, string sep)
 {
     if (source == null)
     {
         return;                 // Nothing to do.
     }
     foreach (var lws in m_object.Services.WritingSystemManager.LocalWritingSystems)
     {
         var ws     = lws.Handle;
         var myAlt  = get_String(ws);
         var srcAlt = source.get_String(ws);
         if ((myAlt == null || myAlt.Length == 0) &&
             (srcAlt != null && srcAlt.Length != 0))
         {
             set_String(ws, srcAlt);
         }
         else if (!fConcatenateIfBoth)
         {
             continue;
         }
         else if (myAlt != null && myAlt.Length != 0 &&
                  srcAlt != null && srcAlt.Length != 0 &&
                  !myAlt.Equals(srcAlt))
         {
             var newBldr = m_object.Cache.TsStrFactory.GetIncBldr();
             newBldr.AppendTsString(get_String(ws));
             newBldr.Append(sep);
             newBldr.AppendTsString(source.get_String(ws));
             set_String(ws, newBldr.GetString());
         }
     }
 }
Esempio n. 3
0
        private static void CheckMSA(string expectedText, int expectedWs, IMultiStringAccessor actual)
        {
            var actualText = TsStringUtils.NormalizeToNFC(actual.GetAlternativeOrBestTss(expectedWs, out var actualWs).Text);

            Assert.AreEqual(expectedText, actualText, $"WS Handle\n{expectedWs} requested\n{actualWs} returned");
            Assert.AreEqual(expectedWs, actualWs, expectedText);
        }
Esempio n. 4
0
        private static ITsString GetTssGloss(IMultiStringAccessor gloss, CoreWritingSystemDefinition wsGloss)
        {
            int wsActual;
            var tssGloss = gloss.GetAlternativeOrBestTss(wsGloss.Handle, out wsActual);

            if (tssGloss == null || tssGloss.Length == 0)
            {
                tssGloss = gloss.NotFoundTss;
            }
            return(tssGloss);
        }
Esempio n. 5
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Copy all writing system alternatives from the given source into this multi-string
        /// accessor overwriting any that already exist. Will not change/remove pre-existing
        /// alternatives missing in the source (i.e., result will be a superset).
        /// </summary>
        /// <param name="source">The source to copy from</param>
        /// <param name="fIgnoreEmptySourceStrings"><c>True</c> to ignore any source alternatives
        /// that are empty, keeping the current alternaltive.</param>
        /// ------------------------------------------------------------------------------------
        public void CopyAlternatives(IMultiStringAccessor source, bool fIgnoreEmptySourceStrings)
        {
            if (source == null)
            {
                return;                 // Nothing to do.
            }
            int cnt = source.StringCount;

            for (int i = 0; i < cnt; i++)
            {
                int       ws;
                ITsString tss = source.GetStringFromIndex(i, out ws);
                if (!fIgnoreEmptySourceStrings || tss.Length > 0)
                {
                    set_String(ws, tss);
                }
            }
        }
Esempio n. 6
0
        ///<summary>
        ///</summary>
        ///<param name="gloss"></param>
        ///<param name="wsGloss"></param>
        ///<param name="variantEntryTypes"></param>
        ///<returns></returns>
        public static ITsString MakeGlossWithReverseAbbrs(IMultiStringAccessor gloss, CoreWritingSystemDefinition wsGloss, IList <ILexEntryType> variantEntryTypes)
        {
            if (variantEntryTypes == null || variantEntryTypes.Count() == 0 || variantEntryTypes.First() == null)
            {
                return(GetTssGloss(gloss, wsGloss));
            }
            var cache  = variantEntryTypes.First().Cache;
            var wsUser = cache.ServiceLocator.WritingSystemManager.UserWritingSystem;
            IList <IMultiUnicode> reverseAbbrs = (from variantType in variantEntryTypes
                                                  select variantType.ReverseAbbr).ToList();
            ITsIncStrBldr sb = TsStringUtils.MakeIncStrBldr();

            AddGloss(sb, gloss, wsGloss);
            const string sBeginSeparator = kDefaultBeginSeparatorLexEntryTypeReverseAbbr;

            if (reverseAbbrs.Count() > 0)
            {
                sb.AppendTsString(TsStringUtils.MakeString(sBeginSeparator, wsUser.Handle));
            }
            AddVariantTypeGlossInfo(sb, wsGloss, reverseAbbrs, wsUser);
            return(sb.Text.Length > 0 ? sb.GetString() : null);
        }
Esempio n. 7
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Appends all the alternatives from the source multi string to the alternatives of
 /// this here one.
 /// </summary>
 /// <param name="src">The source.</param>
 /// ------------------------------------------------------------------------------------
 public void AppendAlternatives(IMultiStringAccessor src)
 {
     AppendAlternatives(src, false);
 }
Esempio n. 8
0
 /// <summary>
 /// Default uses space to separate.
 /// </summary>
 public void MergeAlternatives(IMultiStringAccessor source, bool fConcatenateIfBoth)
 {
     MergeAlternatives(source, fConcatenateIfBoth, " ");
 }
Esempio n. 9
0
 /// <summary>
 /// Merge two MultiAccessor objects.
 /// These cases are handled:
 ///		1. If an alternative exists in both objects, nothing is merged.
 ///		2. If the main object (this) is missing an alternative, and the 'source' has it, then add it to 'this'.
 ///		3. If the main object has an alternative, then do nothing.
 /// </summary>
 /// <param name="source"></param>
 public void MergeAlternatives(IMultiStringAccessor source)
 {
     MergeAlternatives(source, false);
 }
Esempio n. 10
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Copy all writing system alternatives from the given source into this multi-string
 /// accessor overwriting any that already exist. Note that this can replace a non-empty
 /// alternative with an empty alternative. Will not change/remove pre-existing
 /// alternatives missing in the source (i.e., result will be a superset).
 /// </summary>
 /// <param name="source">The source to copy from</param>
 /// ------------------------------------------------------------------------------------
 public void CopyAlternatives(IMultiStringAccessor source)
 {
     CopyAlternatives(source, false);
 }
Esempio n. 11
0
        private static void AddGloss(ITsIncStrBldr sb, IMultiStringAccessor gloss, CoreWritingSystemDefinition wsGloss)
        {
            ITsString tssGloss = GetTssGloss(gloss, wsGloss);

            sb.AppendTsString(tssGloss);
        }
Esempio n. 12
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());
        }
Esempio n. 13
0
		/// <summary>
		/// Return a set of writing systems that have data for this accessor.
		/// </summary>
		/// <param name="msa"></param>
		/// <returns></returns>
		HashSet<int> GetWssWithData(IMultiStringAccessor msa)
		{
			Debug.Assert(msa != null);
			var result = new HashSet<int>();
			for (int i = 0; i < msa.StringCount; ++i)
			{
				int ws;
				ITsString tss = msa.GetStringFromIndex(i, out ws);
				result.Add(ws);
			}
			Debug.Assert(result.Count == msa.StringCount);
			return result;
		}
Esempio n. 14
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Export the back translation of a picture caption
		/// </summary>
		/// <param name="caption">caption to export</param>
		/// ------------------------------------------------------------------------------------
		private void ExportPictureBT(IMultiStringAccessor caption)
		{
			string pictureMarker = GetMarkerForStyle(ScrStyleNames.Figure, @"\figcap");
			string marker = kBackTransMarkerPrefix + pictureMarker.Substring(1);

			for (int i = 0; i < m_requestedAnalWS.Length; i++)
			{
				int ws = m_requestedAnalWS[i];
				string captionText = caption.get_String(ws).Text;
				if (captionText != null && captionText != string.Empty)
				{
					// make sure the pic starts on a new line
					m_file.WriteLine();
					m_file.WriteLine(marker + GetIcuSuffix(i) + " " + captionText);
				}
			}
		}