예제 #1
0
        public ISegmentPair GetSegmentPair(string segmentId, string sourceText, string targetText)
        {
            var segmentPairProperties = _segmentBuilder.CreateSegmentPairProperties();

            segmentPairProperties.Id = new SegmentId(segmentId);

            var sourceSegment = _segmentBuilder.CreateSegment(segmentPairProperties);

            sourceSegment.Properties = segmentPairProperties;
            sourceSegment.Add(_segmentBuilder.Text(sourceText));

            var targetSegment = _segmentBuilder.CreateSegment(segmentPairProperties);

            targetSegment.Properties = segmentPairProperties;
            targetSegment.Add(_segmentBuilder.Text(targetText));

            var segmentPair = _segmentBuilder.CreateSegmentPair(sourceSegment, targetSegment);

            return(segmentPair);
        }
예제 #2
0
        private ISegmentPairProperties ReadSdlSeg(XmlReader xmlReader)
        {
            var properties = _segmentBuilder.CreateSegmentPairProperties();

            var index = 0;

            while (xmlReader.Read())
            {
                switch (xmlReader.NodeType)
                {
                case XmlNodeType.Element:
                    if (index == 0 && string.Compare(xmlReader.Name, NsPrefix + ":seg", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        index++;
                        while (xmlReader.MoveToNextAttribute())
                        {
                            if (string.Compare(xmlReader.Name, "id", StringComparison.OrdinalIgnoreCase) == 0)
                            {
                                properties.Id = new SegmentId(xmlReader.Value);
                            }
                            if (string.Compare(xmlReader.Name, "conf", StringComparison.OrdinalIgnoreCase) == 0)
                            {
                                var success = Enum.TryParse <ConfirmationLevel>(xmlReader.Value, true, out var value);
                                properties.ConfirmationLevel = success ? value : ConfirmationLevel.Unspecified;
                            }
                            if (string.Compare(xmlReader.Name, "locked", StringComparison.OrdinalIgnoreCase) == 0)
                            {
                                var success = bool.TryParse(xmlReader.Value, out var result);
                                properties.IsLocked = success && result;
                            }
                            if (string.Compare(xmlReader.Name, "origin", StringComparison.OrdinalIgnoreCase) == 0)
                            {
                                properties.TranslationOrigin.OriginType = xmlReader.Value;
                            }
                            if (string.Compare(xmlReader.Name, "origin-system", StringComparison.OrdinalIgnoreCase) == 0)
                            {
                                properties.TranslationOrigin.OriginSystem = xmlReader.Value;
                            }
                            if (string.Compare(xmlReader.Name, "percent", StringComparison.OrdinalIgnoreCase) == 0)
                            {
                                var success = byte.TryParse(xmlReader.Value, out var result);
                                properties.TranslationOrigin.MatchPercent = success ? result : (byte)0;
                            }
                            if (string.Compare(xmlReader.Name, "struct-match", StringComparison.OrdinalIgnoreCase) == 0)
                            {
                                var success = bool.TryParse(xmlReader.Value, out var result);
                                properties.TranslationOrigin.IsStructureContextMatch = success && result;
                            }
                            if (string.Compare(xmlReader.Name, "text-match", StringComparison.OrdinalIgnoreCase) == 0)
                            {
                                var success = Enum.TryParse <TextContextMatchLevel>(xmlReader.Value, true, out var result);
                                properties.TranslationOrigin.TextContextMatchLevel = success ? result : TextContextMatchLevel.None;
                            }
                        }
                    }
                    if (string.Compare(xmlReader.Name, NsPrefix + ":prev-origin", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        var xmlReaderSub = xmlReader.ReadSubtree();
                        properties.TranslationOrigin.OriginBeforeAdaptation = ReadPreviousTranslationOrigin(xmlReaderSub);
                        xmlReaderSub.Close();
                    }

                    break;
                }
            }

            return(properties);
        }