Class SegmentationContext
A segmentation context consists of a context which should precede the match, and a context which should follow a match. For performance reasons, it may also contain a list of trigger characters which, if specified, are used to determine whether a specific context is probed for matching or not.
A null context matches every position. Therefore, if the preceding context is null, the segmentation context matches at each position which is not excluded by the following context. If the following context is also null, the segmentation context will match everywhere in the input string.
If the trigger characters are specified, they should consist of all characters which may appear at the end of the preceding context. If the trigger characters are specified, but the preceding context is null, the rule will only be tested for those positions in the string where one of the trigger characters is found. In that case, as the preceding context is null, the rule will "fire" at each of the positions of any trigger character.
Inheritance
Implements
Inherited Members
Namespace: Sdl.LanguagePlatform.Core.Segmentation
Assembly: Sdl.LanguagePlatform.Core.dll
Syntax
public class SegmentationContext : ICloneable
Constructors
SegmentationContext()
Initializes a new instance with default values. This constructor is required for XML deserialization and should not be used directly.
Declaration
public SegmentationContext()
SegmentationContext(SegmentationContext)
Initializes a new instance with the values of another instance, creating a deep copy.
Declaration
public SegmentationContext(SegmentationContext other)
Parameters
Type | Name | Description |
---|---|---|
SegmentationContext | other | The other instance |
SegmentationContext(String, String, Context, Context)
Initializes a new instance with the specified values.
Declaration
public SegmentationContext(string description, string triggerChars, Context precedingContext, Context followingContext)
Parameters
Type | Name | Description |
---|---|---|
System.String | description | A description of the context, for UI purposes. |
System.String | triggerChars | If specified, a string which contains the characters which
can occur at the start of a matching text. If the current start character is not in this
list, no match will be computed, which may improve performance. If |
Context | precedingContext | The pre-break context |
Context | followingContext | The post-break context |
Properties
ContextType
Gets or sets the context type.
Declaration
public ContextType ContextType { get; set; }
Property Value
Type | Description |
---|---|
ContextType |
Description
Gets or sets the description of this context.
Declaration
public LocalizedString Description { get; set; }
Property Value
Type | Description |
---|---|
LocalizedString |
FollowingContext
The break context which directly follows the break. The following context usually contains any post-break whitespace in the pattern. If null, the context "matches" any position.
Declaration
public Context FollowingContext { get; set; }
Property Value
Type | Description |
---|---|
Context |
IsEnabled
Gets or sets a flag to control whether this context is currently enabled. Note that not all clients evaluate this flag yet, and all contexts (whether enabled or not) may be used during segmentation.
Declaration
public bool IsEnabled { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
PrecedingContext
The break context which directly precedes the break. The preceding context typically ends with one or more of the trigger chars. If null, the context matches any position.
Declaration
public Context PrecedingContext { get; set; }
Property Value
Type | Description |
---|---|
Context |
Requires
Gets or sets the name of a language resource required for this match context to be valid. If, at runtime, the required resource cannot be obtained, the match context is invalid and will never be evaluated.
Declaration
public string Requires { get; set; }
Property Value
Type | Description |
---|---|
System.String |
TriggerChars
The characters which trigger this rule. The trigger chars are used to optimize rule evaluation and to avoid more expensive tests (such as regex matches) against the input. If null, the contexts will be checked nevertheless.
If you specify trigger characters, you must take care. For example, if a context has optional trailing parts (as in ".\p{Pe}*" for a full stop followed by an optionally empty sequence of closing punctuation), specifying a trigger character "." will prevent the context from matching any trailing closing punctuation. In this case, you should specify all possible trailing characters.
Declaration
public string TriggerChars { get; set; }
Property Value
Type | Description |
---|---|
System.String |
Methods
Clone()
Declaration
public object Clone()
Returns
Type | Description |
---|---|
System.Object | A new object that is a deep copy of this instance. |
FindAllMatches(String, Int32, Boolean, Boolean)
Finds all matches of the context in the input string, starting at the specified position.
Declaration
public List<int> FindAllMatches(string input, int startOffset, bool assumeEof, bool followedByWordBreak)
Parameters
Type | Name | Description |
---|---|---|
System.String | input | The input string to test |
System.Int32 | startOffset | The zero-based position in the input to start the match process from |
System.Boolean | assumeEof | If true, it is assumed that the end of input has been reached, and end-of-input constraints will match at the end of the input string. If false, any end-of-input constraints will not match. |
System.Boolean | followedByWordBreak | If true, any end-of-word constraints will match at the end of the input string. If false, no end-of-word constraints will match. |
Returns
Type | Description |
---|---|
System.Collections.Generic.List<System.Int32> | A list of positions where the context matches in the input string |
MatchesAt(String, Int32, Boolean, Boolean)
Tests whether the context matches at the specified position. The preceding context, if specified, must match up to the position (not including), and the following context must match from that position onwards. If true, a match is postulated directly before position.
Declaration
public bool MatchesAt(string input, int position, bool assumeEof, bool followedByWordBreak)
Parameters
Type | Name | Description |
---|---|---|
System.String | input | The input string to test |
System.Int32 | position | The position in the input to test for a match |
System.Boolean | assumeEof | If true, it is assumed that the end of input has been reached, and end-of-input constraints will match. If false, any end-of-input constraints will not match. |
System.Boolean | followedByWordBreak | If true, any end-of-word constraints will match. If false, no end-of-word constraints will match. |
Returns
Type | Description |
---|---|
System.Boolean | true iff the preceding context matches up to the specified position (non-inclusive), and the following context matches from that position onwards. |
ToString()
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
System.String | A string representation of the object, for display purposes. |