Click or drag to resize
Segment Class
Represents a segment, which is a sequence of SegmentElements, in a particular language.
Inheritance Hierarchy
SystemObject
  Sdl.LanguagePlatform.CoreSegment

Namespace: Sdl.LanguagePlatform.Core
Assembly: Sdl.LanguagePlatform.Core (in Sdl.LanguagePlatform.Core.dll) Version: 1.6.0.0 (1.7.3164.0)
Syntax
public class Segment

The Segment type exposes the following members.

Constructors
  NameDescription
Public methodSegment
Initializes a new instance with the InvariantCulture, and an empty list of elements.
Public methodSegment(CultureInfo)
Initializes a new instance with the specified culture, and an empty list of elements.
Top
Properties
  NameDescription
Public propertyCulture
Gets or sets the culture for this segment.
Public propertyCultureName
Gets or sets the culture name for this segment. The culture name must be resolvable through GetCultureInfo(string), or an exception will be thrown.
Public propertyElements
Gets or sets the collection of elements in this segment.
Public propertyHasPairedTags
Gets a value which indicates whether this segment contains any paired tags. Only start tags are checked, it is assumed that the tag structure is valid.
Public propertyHasPlaceables
Gets a bool value which indicates whether this segment contains any placeables. Note that the return value is only valid if the segment is tokenized.
Public propertyHasTags
Gets a value which indicates whether this segment contains any tags.
Public propertyIsEmpty
Gets a value indicating whether this instance contains any elements (false) or not (true).
Public propertyLastElement
Gets or sets the last element of this segment.
Public propertyTokens
Gets or sets the collection of tokens in this segment.
Top
Methods
  NameDescription
Public methodAdd(String)
Adds the provided string as a new text element to the segment's list of elements. If the last segment element is a Text element as well, they will be merged.
Public methodAdd(SegmentElement)
Adds the provided segment element to the segment's list of elements. When adding a text element, and the last segment element is a text element as well, they will be merged.
Public methodAddRange
Adds all segment elements in the collection to this segment.
Public methodAnchorDanglingTags
Sets the anchor for any tags which are not yet anchored (including standalone/placeholder tags). Does not modify tag IDs or alignment anchors.
Public methodClear
Empties the list of segment elements.
Public methodDeleteEmptyTagPairs
Deletes empty tag pairs (a start tag directly followed by the end tag with the same tag anchor) from the segment.
Public methodDeleteTags
Removes all tags from the segment, applying the DeleteAll tag deletion mode.
Public methodDeleteTags(SegmentDeleteTagsAction)
Removes all tags from the segment, applying the specified tag deletion mode.
Public methodDuplicate
Creates a new instance that is a deep copy of this instance.
Public methodEquals(Object)
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Public methodEquals(Segment)
Compares this instance to another Segment object.
Public methodFillUnmatchedStartAndEndTags
Inserts corresponding start and end tags for unmatched end and start tags to the segment. For unmatched end tags, the corresponding start tags are inserted at the beginning of the segment. Corresponding end tags for unmatched start tags are added at the end. In certain cases, not all dangling tags can be filled, and in order to obtain a valid segment without any unmatched tags, RemoveUnmatchedStartAndEndTags(Boolean) should be called after calling this method. Note that only the tag type is checked, not whether there are start or end tags without a corresponding tag having the same tag anchor.

The method will discontinue if the tag pairing structure is incorrect (i.e. if there are overlapping tags).

Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodFindTag
Finds and returns the tag with the provided type and the provided tag anchor, or null if no such tag exists in the segment.
Public methodGetHashCode (Overrides ObjectGetHashCode.)
Public methodGetMaxTagAnchor
Returns the highest tag anchor used in the segment, or 0 if no tags are present.
Public methodGetMinMaxTagAnchor
Returns the smallest and largest tag anchor used in the segment. Both default to 0.
Public methodGetTagCount
Returns the number of tags in the segment. Paired tags are counted only once.
Public methodGetTagIDGroups
Computes a mapping from the start tag token index to that tag's tag ID. Only start and standalone/placeholder tags are included in the mapping. The mapping may be n:1. The segment must be tokenized, or an exception is thrown.
Public methodGetTagPairings
Returns a dictionary of paired tag token indices, mapping from the start tag's token index to the end tag's token index. The segment must be tokenized, or an exception is thrown.
Public methodGetTokenIndex
Returns the index of the token at the specified position.
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodGetWeakHashCode
Returns a hash code which does not depend on tag anchors in the segment. This can be used for translation tracking in bilingual documents.
Public methodHasPeripheralWhitespace
Determines whether the segment starts or ends with at least one whitespace character.
Public methodHasTokenBundles
Returns true if any of the segment's tokens is a TokenBundle (i.e. an ambigous tokenization), and false otherwise. Token bundles should only be used inside the TM Kernel and not be returned through the TM API.
Public methodHasUnmatchedStartOrEndTags
Determines whether the segment has any unmatched start or end tags. Note that this method only tests the tag type, and does not handle paired tags where the start or end tag are missing.
Public methodIsValid
Determines if this segment is valid.
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodMergeAdjacentTextRuns
Merges adjacent text runs.
Public methodRemoveTokenBundles
Replaces token bundles with the "best" token in that bundle. Returns true if any replacement has been done, and false otherwise.
Public methodRemoveUnmatchedStartAndEndTags
Deletes all tags from the segment which have a tag type of UnmatchedStart or UnmatchedEnd. Note that this method only tests the tag type, and does not handle paired tags where the start or end tag are missing.
Public methodRemoveUnmatchedStartAndEndTags(Boolean)
Deletes all tags from the segment which have a tag type of UnmatchedStart or UnmatchedEnd, if these tags occur in peripheral positions, which means that dangling end tags are only removed if they appear at the start of the segment, and dangling start tags are only removed if they appear at the end of the segment, with no other tags or text preceding the tag (in case of segment-initial dangling end tags), or following the tag (for segment-trailing dangling start tags).

Note that this method only tests the tag type, and does not handle paired tags where the start or end tag are missing.

Public methodRenumberTagAnchors(Int32)
Renumbers tag anchors so that they start at 1 and are consecutive. Although tag anchors have no semantics for standalone tags, they are also anchored in the same manner. Errors in tag numbering will be ignored (but preserved, i.e. invalid tag anchors will be mapped to potentially new, also invalid tag anchors).
Public methodRenumberTagAnchors(Int32, Int32)
Renumbers tag anchors, starting at nextTagAnchor, in a consecutive manner. Although tag anchors have no semantics for standalone tags, they are also anchored in the same manner. Errors in tag numbering will be ignored (but preserved, i.e. invalid tag anchors will be mapped to potentially new, also invalid tag anchors).
Public methodToPlain
Returns a string containing only the plain text in this segment. Note that text placeholders will be replaced with their text equivalent.
Public methodToPlain(SegmentRange)
Computes the plain-text version of the part of the segment specified by the provided range.
Public methodToPlain(Int32, Int32)
Returns a string containing only the plain text in this segment, covering the given token range. An exception will be thrown if the segment's tokens are not set or the token range is outside the bounds.
Public methodToPlain(Boolean, Boolean, ListSegmentPosition)
Computes the plain-text version of the segment and returns, in the ranges list, the segment range of each character of the result string. The number of elements in that collection will be equal to the length of the string in characters.
Public methodToString (Overrides ObjectToString.)
Public methodTrim
Removes leading whitespace from the first segment element, if that is a text element, and trailing whitespace from the last segment element, if that is a text element. If the first/last segment element is not a text element, it will not be altered. Also, leading (trailing) whitespace will not be removed from a text element if it is preceded (followed) only by non-text elements. Also deletes any null elements.
Public methodTrimEnd
Removes trailing whitespace from the last segment element, if that is a text element. If the last segment element is not a text element, nothing will happen. Hence, trailing whitespace will not be removed from a text element if it is followed by non-text elements. The number of elements may be altered by this method. Empty (null) elements will also be removed.
Public methodTrimStart
Removes leading whitespace from the first segment element, if that is a text element. If the first segment element is not a text element, nothing will happen. Hence, leading whitespace will not be removed from a text element if it is preceded by non-text elements. The number of elements may be altered by this method. Empty (null) elements will also be removed.
Public methodUpdateFromTokenIndices
Updates the segment's text from the tokens, and adjusts span indices accordingly. An exception is thrown if the segment is not tokenized.
Public methodValidate
Validates the current instance, with the ReportAllErrors validation mode.
Public methodValidate(SegmentValidationMode)
Performs validation checks on this instance, applying the specified validation mode.
Public methodVerifyTokenSpans
Verifies whether the spans of the segment's tokens are correct and reflect the segment's text. Note that the segment should be tokenized. If not, true is returned.
Public methodWeakEquals
Computes weak equality with another segment.

Weak equality does not check culture compatibility and tag anchors do not need to be identical, but text elements must match, as well as the order of tags (element similarity must not be None)

Top
See Also
Community
Edit

Be the first to Edit the community content of this topic.
Comments