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.
Implements
Inherited Members
Namespace: SdlSdl.LanguagePlatformCoreSegmentation
Assembly: Sdl.LanguagePlatform.Core.dll
Syntax
[DataContract]
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 |
---|---|---|
string | description | A description of the context, for UI purposes. |
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
[DataMember]
public ContextType ContextType { get; set; }
Property Value
Type | Description |
---|---|
ContextType |
Description
Gets or sets the description of this context.
Declaration
[DataMember]
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
[DataMember]
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
[DataMember]
public bool IsEnabled { get; set; }
Property Value
Type | Description |
---|---|
bool |
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
[DataMember]
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
[DataMember]
public string Requires { get; set; }
Property Value
Type | Description |
---|---|
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
[DataMember]
public string TriggerChars { get; set; }
Property Value
Type | Description |
---|---|
string |
Methods
Clone()
Declaration
public object Clone()
Returns
Type | Description |
---|---|
object | A new object that is a deep copy of this instance. |
FindAllMatches(string, int, bool, bool)
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 |
---|---|---|
string | input | The input string to test |
int | startOffset | The zero-based position in the input to start the match process from |
bool | 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. |
bool | 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 |
---|---|
Listint | A list of positions where the context matches in the input string |
MatchesAt(string, int, bool, bool)
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 |
---|---|---|
string | input | The input string to test |
int | position | The position in the input to test for a match |
bool | 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. |
bool | followedByWordBreak | If true, any end-of-word constraints will match. If false, no end-of-word constraints will match. |
Returns
Type | Description |
---|---|
bool | 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 |
---|---|
string | A string representation of the object, for display purposes. |