当前位置: 首页>>代码示例>>C#>>正文


C# Segment.Add方法代码示例

本文整理汇总了C#中Segment.Add方法的典型用法代码示例。如果您正苦于以下问题:C# Segment.Add方法的具体用法?C# Segment.Add怎么用?C# Segment.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Segment的用法示例。


在下文中一共展示了Segment.Add方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: getEditedSegment

        /// <summary>
        /// Used to do batch find-replace on a segment with tags.
        /// </summary>
        /// <param name="inSegment"></param>
        /// <param name="fileName"></param>
        /// <returns></returns>
        private Segment getEditedSegment(SegmentEditor editor, Segment inSegment)
        {
            Segment newSeg = new Segment(inSegment.Culture);

            foreach (SegmentElement element in inSegment.Elements)
            {
                System.Type elType = element.GetType();

                if (elType.ToString() != "Sdl.LanguagePlatform.Core.Tag") //if other than tag, make string and edit it
                {
                    string temp = editor.EditText(element.ToString());
                    newSeg.Add(temp); //add edited text to segment
                }
                else
                {
                    newSeg.Add(element); //if tag just add the tag
                }
            }
            return newSeg;
        }
开发者ID:patrickporter,项目名称:MT-Enhanced-Trados-Plugin,代码行数:26,代码来源:MtTranslationProviderLanguageDirection.cs

示例2: GetTaggedSegment

        /// <summary>
        /// Returns a tagged segments from a target string containing markup, where the target string represents the translation of the class instance's source segment
        /// </summary>
        /// <param name="_returnedText"></param>
        /// <returns></returns>
        public Segment GetTaggedSegment(string _returnedText)
        {
            //decode the returned text
            returnedText = DecodeReturnedText(_returnedText);
            //our dictionary, dict, is already built
            Segment segment = new Segment(); //our segment to return
            string[] _targetElements = GetTargetElements();//get our array of elements..it will be array of tagtexts and text in the order received from google
            //build our segment looping through elements

            for (int i = 0; i < _targetElements.Length; i++)
            {
                string text = _targetElements[i]; //the text to be compared/added
                if (dict.ContainsKey(text)) //if our text in question is in the tagtext list
                {
                    try
                    {
                        string padleft = dict[text].padLeft;
                        string padright = dict[text].padRight;
                        if (padleft.Length > 0) segment.Add(padleft); //add leading space if applicable in the source text
                        segment.Add(dict[text].SdlTag); //add the actual tag element after casting it back to a Tag
                        if (padright.Length > 0) segment.Add(padright); //add trailing space if applicable in the source text
                        //segment.Add(" ");//add a space after each tag
                    }
                    catch
                    { }
                }
                else
                {   //if it is not in the list of tagtexts then the element is just the text
                    if (text.Trim().Length > 0) //if the element is something other than whitespace, i.e. some text in addition
                    {
                        text = text.Trim(); //trim out extra spaces, since they are dealt with by associating them with the tags
                        segment.Add(text); //add to the segment
                    }
                }
            }

            //Microsoft sends back closing tags that need to be removed
            segment = RemoveTrailingClosingTags(segment);

            return segment; //this will return a tagged segment
        }
开发者ID:patrickporter,项目名称:MT-Enhanced-Trados-Plugin,代码行数:46,代码来源:MtTranslationProviderTagPlacer.cs

示例3: SearchSegment

        public SearchResults SearchSegment(SearchSettings settings, Segment segment)
        {
            //FUTURE: consider making GT and MT lookup classes static utility classes

            Segment translation = new Segment(_languageDirection.TargetCulture);//this will be the target segment

            #region "SearchResultsObject"
            SearchResults results = new SearchResults();
            results.SourceSegment = segment.Duplicate();

            #endregion

            #region "Confirmation Level"
            if (!_options.ResendDrafts && inputTu.ConfirmationLevel != ConfirmationLevel.Unspecified) //i.e. if it's status is other than untranslated
            { //don't do the lookup, b/c we don't need to pay google to translate text already translated if we edit a segment
                translation.Add(PluginResources.TranslationLookupDraftNotResentMessage);
                //later get these strings from resource file
                results.Add(CreateSearchResult(segment, translation, segment.ToString()));
                return results;
            }
            #endregion

            // Look up the currently selected segment in the collection (normal segment lookup).
            #region "SegmentLookup"
            string sourceLang = SourceLanguage.ToString();
            string targetLang = TargetLanguage.ToString();
            string translatedText = "";
            //a new seg avoids modifying the current segment object
            Segment newseg = segment.Duplicate();

            //do preedit if checked
            bool sendTextOnly = _options.SendPlainTextOnly || !newseg.HasTags;
            if (!sendTextOnly)
            {
                //do preedit with tagged segment
                if (_options.UsePreEdit)
                {
                    if (preLookupSegmentEditor == null) preLookupSegmentEditor = new SegmentEditor(_options.PreLookupFilename);
                    newseg = getEditedSegment(preLookupSegmentEditor, newseg);
                }
                //return our tagged target segment
                MtTranslationProviderTagPlacer tagplacer = new MtTranslationProviderTagPlacer(newseg);
                ////tagplacer is constructed and gives us back a properly marked up source string for google
                if (_options.SelectedProvider == MtTranslationOptions.ProviderType.GoogleTranslate)
                {
                    translatedText = LookupGT(tagplacer.PreparedSourceText, _options, "html");
                }
                else if (_options.SelectedProvider == MtTranslationOptions.ProviderType.MicrosoftTranslator)
                {
                    translatedText = LookupMST(tagplacer.PreparedSourceText, _options, "text/html");
                }
                //now we send the output back to tagplacer for our properly tagged segment
                translation = tagplacer.GetTaggedSegment(translatedText).Duplicate();

                //now do post-edit if that option is checked
                if (_options.UsePostEdit)
                {
                    if (postLookupSegmentEditor == null) postLookupSegmentEditor = new SegmentEditor(_options.PostLookupFilename);
                    translation = getEditedSegment(postLookupSegmentEditor, translation);
                }
            }
            else //only send plain text
            {
                string sourcetext = newseg.ToPlain();
                //do preedit with string
                if (_options.UsePreEdit)
                {
                    if (preLookupSegmentEditor == null) preLookupSegmentEditor = new SegmentEditor(_options.PreLookupFilename);
                    sourcetext = getEditedString(preLookupSegmentEditor, sourcetext);
                    //change our source segment so it gets sent back with modified text to show in translation results window that it was changed before sending
                    newseg.Clear();
                    newseg.Add(sourcetext);
                }

                //now do lookup
                if (_options.SelectedProvider == MtTranslationOptions.ProviderType.GoogleTranslate)
                {
                    translatedText = LookupGT(sourcetext, _options, "html"); //plain??
                }
                else if (_options.SelectedProvider == MtTranslationOptions.ProviderType.MicrosoftTranslator)
                {
                    translatedText = LookupMST(sourcetext, _options, "text/plain");
                }

                //now do post-edit if that option is checked
                if (_options.UsePostEdit)
                {
                    if (postLookupSegmentEditor == null) postLookupSegmentEditor = new SegmentEditor(_options.PostLookupFilename);
                    translatedText = getEditedString(postLookupSegmentEditor, translatedText);
                }
                translation.Add(translatedText);
            }

            results.Add(CreateSearchResult(newseg, translation, newseg.ToPlain()));

            #endregion

            #region "Close"
            return results;
            #endregion
//.........这里部分代码省略.........
开发者ID:patrickporter,项目名称:MT-Enhanced-Trados-Plugin,代码行数:101,代码来源:MtTranslationProviderLanguageDirection.cs

示例4: RemoveTrailingClosingTags

        /// <summary>
        /// Microsoft always adds closing tags, but we don't keep track of our tags that way..so the segments always have garbage text at the end with the closing tag markup...this method removes them
        /// </summary>
        /// <param name="segment"></param>
        /// <returns></returns>
        public Segment RemoveTrailingClosingTags(Segment segment)
        {
            #region RemoveTrailingClosingTags
            SegmentElement element = segment.Elements[segment.Elements.Count - 1]; //get last element
            string str = element.ToString();

            int tagsCount = segment.GetTagCount();
            string pattern = @"\</tg[0-9]*\>"; //we want to find "</tg" + {any number} + ">"
            Regex rgx = new Regex(pattern);
            System.Type elType = element.GetType();
            MatchCollection matches = rgx.Matches(str);
            if (elType.ToString().Equals("Sdl.LanguagePlatform.Core.Text") && matches.Count > 0) //if a text element containing matches
            {
                foreach (Match myMatch in matches)
                {
                    str = str.Replace(myMatch.Value, ""); //puts our separator around tagtexts
                }

                segment.Elements.Remove(element);
                segment.Add(str.TrimStart());
            }
            #endregion

            return segment;
        }
开发者ID:patrickporter,项目名称:MT-Enhanced-Trados-Plugin,代码行数:30,代码来源:MtTranslationProviderTagPlacer.cs


注:本文中的Segment.Add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。