Esempio n. 1
0
        public override void ProcessParagraphUnit(IParagraphUnit paragraphUnit)
        {
            var sourceResult = new List <IndexData>();
            var targetResult = new List <IndexData>();

            if (!paragraphUnit.IsStructure)
            {
                foreach (var item in paragraphUnit.SegmentPairs)
                {
                    var itemStatus = item.Properties.ConfirmationLevel;

                    // extract text and tags from Segment
                    var sourceSegment = item.Source;
                    _dataExtractor.Process(sourceSegment);
                    var sourceTags = _dataExtractor.Tags;
                    //we need to add a space before the soft return so the soft return is highlightable when searching for it
                    var sourceText     = _dataExtractor.PlainText.ToString().Replace("\n", " \n");
                    var sourceLContent = _dataExtractor.LockedContent;

                    var targetSegment = item.Target;
                    _dataExtractor.Process(targetSegment);
                    //we need to add a space before the soft return so the soft return is highlightable when searching for it
                    var targetText     = _dataExtractor.PlainText.ToString().Replace("\n", " \n");
                    var targetTags     = _dataExtractor.Tags;
                    var targetLContent = _dataExtractor.LockedContent;

                    // perform search
                    if (_searcher.CheckSegment(item.Properties.IsLocked, item.Properties.ConfirmationLevel))
                    {
                        if (_searchSettings.SearchInSource && (sourceText.Length > 0 || sourceTags.Count > 0))
                        {
                            _searcher.SearchInSegment(sourceText, sourceTags, sourceLContent);
                            sourceResult = _searcher.ResultsInText;
                            sourceTags   = _searcher.ResultsInTags;
                        }

                        if (_searchSettings.SearchInTarget && (targetText.Length > 0 || targetTags.Count > 0))
                        {
                            _searcher.SearchInSegment(targetText, targetTags, targetLContent);
                            targetResult = _searcher.ResultsInText;
                            targetTags   = _searcher.ResultsInTags;
                        }

                        // collect results
                        if (SegmentHelper.ContainMatches(sourceResult, sourceTags) || SegmentHelper.ContainMatches(targetResult, targetTags))
                        {
                            CollectResults(item.Properties.Id.Id, sourceText, itemStatus, sourceSegment, sourceResult, sourceTags, true);
                            CollectResults(item.Properties.Id.Id, targetText, itemStatus, targetSegment, targetResult, targetTags, false);
                        }
                    }
                }
            }
        }
        public override void ProcessParagraphUnit(IParagraphUnit paragraphUnit)
        {
            ISegment sourceSegment;
            string   sourceText;

            ISegment         targetSegment;
            string           targetText;
            List <IndexData> targetLContent;
            SegmentData      segmentSearch;

            ConfirmationLevel itemStatus;

            if (paragraphUnit.IsStructure)
            {
                base.ProcessParagraphUnit(paragraphUnit);
                return;
            }

            foreach (ISegmentPair item in paragraphUnit.SegmentPairs)
            {
                sourceSegment = item.Source;
                targetSegment = item.Target;
                itemStatus    = item.Properties.ConfirmationLevel;
                if (_searcher.checkSegment(item.Properties.IsLocked, itemStatus))
                {
                    _dataExtractor.Process(targetSegment);
                    targetText     = _dataExtractor.PlainText.ToString();
                    targetLContent = _dataExtractor.LockedContent;
                    if (targetText.Length > 0)
                    {
                        // do search & save found results
                        _searcher.SearchInSegment(targetText, targetLContent);

                        // if matches in target were found
                        if (SegmentHelper.ContainMatches(_searcher.resultsInText))
                        {
                            #region extract source text
                            _dataExtractor.Process(sourceSegment);
                            sourceText = _dataExtractor.PlainText.ToString();
                            #endregion
                            CollectResults(item.Properties.Id.Id, sourceText, itemStatus, sourceSegment, null, true);
                            CollectResults(item.Properties.Id.Id, targetText, itemStatus, targetSegment, _searcher.resultsInText, false);

                            segmentSearch = _resultTrg[_resultTrg.Count - 1];

                            ISegment originalSegment = (ISegment)targetSegment.Clone();
                            // unlock selections
                            if (_searchSettings.UnlockContent)
                            {
                                StatusUpdateHelper.UnlockContent(targetSegment, ItemFactory, PropertiesFactory);
                            }

                            #region REPLACE Logic
                            int textLoc = 0;
                            int cnt     = 0;
                            int status  = 0;
                            for (int i = segmentSearch.SearchResults.Count - 1; i >= 0; i--)
                            {
                                // add warning - cannot be replaced
                                if (segmentSearch.SearchResults[i].IsIndexOverlap)
                                {
                                    status = -4;
                                    _resultWarnings.Add(new WarningData(segmentSearch.Sid,
                                                                        segmentSearch.SearchResults[i],
                                                                        WarningData.WarningType.IndexOverlap));
                                }
                                else
                                {
                                    // DO REPLACE - success
                                    status = PerformReplace(targetSegment, segmentSearch.SearchResults[i], ref textLoc);
                                    #region report warning - fail
                                    if (status != 0)
                                    {
                                        if (status == -1)
                                        {
                                            _resultWarnings.Add(new WarningData(segmentSearch.Sid,
                                                                                segmentSearch.SearchResults[i],
                                                                                WarningData.WarningType.TagFound,
                                                                                segmentSearch.SearchResults[i].Length + textLoc));
                                        }
                                        else if (status == -2)
                                        {
                                            _resultWarnings.Add(new WarningData(segmentSearch.Sid,
                                                                                segmentSearch.SearchResults[i],
                                                                                WarningData.WarningType.ContainLContent,
                                                                                segmentSearch.SearchResults[i].Length + textLoc));
                                        }
                                        else if (status == -3)
                                        {
                                            _resultWarnings.Add(new WarningData(segmentSearch.Sid,
                                                                                segmentSearch.SearchResults[i],
                                                                                WarningData.WarningType.ContainComment,
                                                                                segmentSearch.SearchResults[i].Length + textLoc));
                                        }
                                        else
                                        {
                                            _resultWarnings.Add(new WarningData(segmentSearch.Sid,
                                                                                segmentSearch.SearchResults[i],
                                                                                WarningData.WarningType.Other));
                                        }
                                    }
                                    #endregion
                                }

                                if (i == segmentSearch.SearchResults.Count - 1)
                                {
                                    // collect results
                                    _resultReplace.Add(new SegmentData(_resultReplace.Count,
                                                                       segmentSearch.SegmentId,
                                                                       segmentSearch.SegmentText,
                                                                       segmentSearch.SegmentStatus,
                                                                       segmentSearch.SegmentContent));
                                    _resultReplace[_resultReplace.Count - 1].SearchResults = new List <IndexData>();
                                }

                                // if replace was successful
                                if (status == 0)
                                {
                                    _resultReplace[_resultReplace.Count - 1].SearchResults.Add(segmentSearch.SearchResults[i]);
                                    _resultReplace[_resultReplace.Count - 1].SearchResults[cnt++].RealStartIndex = textLoc;
                                }
                            }
                            #endregion

                            #region UPDATE STATUSES Logic
                            // if replace occured
                            if (_resultReplace[_resultReplace.Count - 1].IndexMatchesCount > 0)
                            {
                                // update segment properties
                                StatusUpdateHelper.UpdateSegmentProperties(item, _searchSettings);
                            }
                            else
                            {
                                item.Target.Clear();
                                originalSegment.MoveAllItemsTo(item.Target);
                            }
                            #endregion
                        }
                    }
                }
            }

            base.ProcessParagraphUnit(paragraphUnit);
        }
        public override void ProcessParagraphUnit(IParagraphUnit paragraphUnit)
        {
            ISegment         sourceSegment;
            string           sourceText;
            List <TagData>   sourceTags;
            List <IndexData> sourceLContent;
            List <IndexData> sourceResult;

            ISegment         targetSegment;
            string           targetText;
            List <TagData>   targetTags;
            List <IndexData> targetLContent;
            List <IndexData> targetResult;

            ConfirmationLevel itemStatus;

            if (!paragraphUnit.IsStructure)
            {
                foreach (ISegmentPair item in paragraphUnit.SegmentPairs)
                {
                    itemStatus   = item.Properties.ConfirmationLevel;
                    sourceTags   = null;
                    sourceResult = null;
                    targetTags   = null;
                    targetResult = null;

                    // extract text and tags from Segment
                    sourceSegment = item.Source;
                    _dataExtractor.Process(sourceSegment);
                    sourceTags     = _dataExtractor.Tags;
                    sourceText     = _dataExtractor.PlainText.ToString();
                    sourceLContent = _dataExtractor.LockedContent;

                    targetSegment = item.Target;
                    _dataExtractor.Process(targetSegment);
                    targetText     = _dataExtractor.PlainText.ToString();
                    targetTags     = _dataExtractor.Tags;
                    targetLContent = _dataExtractor.LockedContent;

                    // perform search
                    if (_searcher.checkSegment(item.Properties.IsLocked, item.Properties.ConfirmationLevel))
                    {
                        if (_searchSettings.SearchInSource && (sourceText.Length > 0 || sourceTags.Count > 0))
                        {
                            _searcher.SearchInSegment(sourceText, sourceTags, sourceLContent);
                            sourceResult = _searcher.resultsInText;
                            sourceTags   = _searcher.resultsInTags;
                        }

                        if (_searchSettings.SearchInTarget && (targetText.Length > 0 || targetTags.Count > 0))
                        {
                            _searcher.SearchInSegment(targetText, targetTags, targetLContent);
                            targetResult = _searcher.resultsInText;
                            targetTags   = _searcher.resultsInTags;
                        }

                        // collect results
                        if (SegmentHelper.ContainMatches(sourceResult, sourceTags) || SegmentHelper.ContainMatches(targetResult, targetTags))
                        {
                            CollectResults(item.Properties.Id.Id, sourceText, itemStatus, sourceSegment, sourceResult, sourceTags, true);
                            CollectResults(item.Properties.Id.Id, targetText, itemStatus, targetSegment, targetResult, targetTags, false);
                        }
                    }

                    // TODO - REMOVE
                    //// process source
                    //if (_searchSettings.SearchInSource)
                    //{
                    //    sSegment = item.Source;
                    //    if (_searcher.checkSegment(sSegment.Properties.IsLocked, sSegment.Properties.ConfirmationLevel))
                    //    {
                    //        _dataExtractor.Process(sSegment, _searchSettings.SearchInLocked);
                    //        sText = _dataExtractor.PlainText.ToString();
                    //        sTags = _dataExtractor.Tags;
                    //        if (sText.Length > 0 || sTags.Count > 0)
                    //        {
                    //            _searcher.SearchInSegment(sText, sTags);
                    //            sResult = _searcher.resultsInText;
                    //            sTags = _searcher.resultsInTags;
                    //            CollectResults(sSegment.Properties.Id.Id, sText, sSegment, sResult, sTags, true);
                    //        }
                    //    }
                    //}

                    //// process target
                    //if (_searchSettings.SearchInTarget)
                    //{
                    //    sSegment = item.Target;
                    //    if (_searcher.checkSegment(sSegment.Properties.IsLocked, sSegment.Properties.ConfirmationLevel))
                    //    {
                    //        _dataExtractor.Process(sSegment, _searchSettings.SearchInLocked);
                    //        sText = _dataExtractor.PlainText.ToString();
                    //        sTags = _dataExtractor.Tags;
                    //        if (sText.Length > 0 || sTags.Count > 0)
                    //        {
                    //            _searcher.SearchInSegment(sText, sTags);
                    //            sResult = _searcher.resultsInText;
                    //            sTags = _searcher.resultsInTags;
                    //            CollectResults(sSegment.Properties.Id.Id, sText, sSegment, sResult, sTags, false);
                    //        }
                    //    }
                    //}
                }
            }
        }
Esempio n. 4
0
        public override void ProcessParagraphUnit(IParagraphUnit paragraphUnit)
        {
            ISegment         sourceSegment;
            string           sourceText;
            List <TagData>   sourceTags;
            List <IndexData> sourceLContent;
            List <IndexData> sourceResult;

            ISegment         targetSegment;
            string           targetText;
            List <TagData>   targetTags;
            List <IndexData> targetLContent;
            List <IndexData> targetResult;

            ConfirmationLevel itemStatus;

            if (!paragraphUnit.IsStructure)
            {
                foreach (ISegmentPair item in paragraphUnit.SegmentPairs)
                {
                    sourceTags   = null;
                    sourceResult = null;
                    targetTags   = null;
                    targetResult = null;

                    // extract text and tags from Segment
                    sourceSegment = item.Source;
                    _dataExtractor.Process(sourceSegment);
                    sourceText     = _dataExtractor.PlainText.ToString();
                    sourceTags     = _dataExtractor.Tags;
                    sourceLContent = _dataExtractor.LockedContent;

                    targetSegment = item.Target;
                    _dataExtractor.Process(targetSegment);
                    targetText     = _dataExtractor.PlainText.ToString();
                    targetTags     = _dataExtractor.Tags;
                    targetLContent = _dataExtractor.LockedContent;

                    // perform search
                    if (_searcher.checkSegment(item.Properties.IsLocked, item.Properties.ConfirmationLevel))
                    {
                        if (_searchSettings.SearchInSource && (sourceText.Length > 0 || sourceTags.Count > 0))
                        {
                            _searcher.SearchInSegment(sourceText, sourceTags, sourceLContent);
                            sourceResult = _searcher.resultsInText;
                            sourceTags   = _searcher.resultsInTags;
                        }

                        if (_searchSettings.SearchInTarget && (targetText.Length > 0 || targetTags.Count > 0))
                        {
                            _searcher.SearchInSegment(targetText, targetTags, targetLContent);
                            targetResult = _searcher.resultsInText;
                            targetTags   = _searcher.resultsInTags;
                        }

                        // collect results
                        if (SegmentHelper.ContainMatches(sourceResult, sourceTags) || SegmentHelper.ContainMatches(targetResult, targetTags))
                        {
                            itemStatus = (_searchSettings.UpdateStatus ? _searchSettings.NewStatus : item.Properties.ConfirmationLevel);

                            CollectResults(item.Properties.Id.Id, sourceText, itemStatus, sourceSegment, sourceResult, sourceTags, true);
                            CollectResults(item.Properties.Id.Id, targetText, itemStatus, targetSegment, targetResult, targetTags, false);

                            // unlock selections
                            if (_searchSettings.UnlockContent)
                            {
                                StatusUpdateHelper.UnlockContent(targetSegment, ItemFactory, PropertiesFactory);
                            }

                            // update segment properties
                            StatusUpdateHelper.UpdateSegmentProperties(item, _searchSettings);
                        }
                    }
                }
            }

            base.ProcessParagraphUnit(paragraphUnit);
        }