Class Span

Namespace
NOpenNLP.Tools.Util
Assembly
NOpenNLP.Tools.dll

Class for storing start and end integer offsets.

public class Span : IComparable<Span>
Inheritance
Span
Implements
Derived
Inherited Members

Constructors

Span(Span, double)

Creates a new immutable span based on an existing span, where the existing span did not include the prob

public Span(Span span, double prob)

Parameters

span Span

the span that has no prob or the prob is incorrect and a new Span must be generated

prob double

the probability of the span

Span(Span, int)

Initializes a new Span object with an existing Span which is shifted by an offset.

public Span(Span span, int offset)

Parameters

span Span
offset int

Span(int, int)

Initializes a new Span Object. Sets the prob to 0 as default

public Span(int s, int e)

Parameters

s int

start of span.

e int

end of span.

Span(int, int, double)

public Span(int s, int e, double prob)

Parameters

s int

the start of the span (the token index, not the char index)

e int

the end of the span (the token index, not the char index)

prob double

Span(int, int, string?)

Initializes a new Span Object. Sets the prob to 0 as default.

public Span(int s, int e, string? type)

Parameters

s int

start of span.

e int

end of span, which is +1 more than the last element in the span.

type string

the type of the span

Span(int, int, string?, double)

Initializes a new Span Object.

public Span(int s, int e, string? type, double prob)

Parameters

s int

start of span.

e int

end of span, which is +1 more than the last element in the span.

type string

the type of the span

prob double

probability of span.

Properties

End

Return the end of a span.

Note: that the returned index is one past the actual end of the span in the text, or the first element past the end of the span.

public virtual int End { get; }

Property Value

int

the end of a span.

Length

Returns the length of this span.

public virtual int Length { get; }

Property Value

int

the length of the span.

Prob

public virtual double Prob { get; }

Property Value

double

Start

Return the start of a span.

public virtual int Start { get; }

Property Value

int

the start of a span.

Type

Retrieves the type of the span.

public virtual string? Type { get; }

Property Value

string

the type or null if not set

Methods

CompareTo(Span)

Compares the specified span to the current span.

public virtual int CompareTo(Span s)

Parameters

s Span

Returns

int

Contains(Span)

Returns true if the specified span is contained by this span. Identical spans are considered to contain each other.

public virtual bool Contains(Span s)

Parameters

s Span

The span to compare with this span.

Returns

bool

true is the specified span is contained by this span; false otherwise.

Contains(int)

Returns true if the specified index is contained inside this span. An index with the value of end is considered outside the span.

public virtual bool Contains(int index)

Parameters

index int

the index to test with this span.

Returns

bool

true if the span contains this specified index; false otherwise.

Crosses(Span)

Returns true is the specified span crosses this span.

public virtual bool Crosses(Span s)

Parameters

s Span

The span to compare with this span.

Returns

bool

true is the specified span overlaps this span and contains a non-overlapping section; false otherwise.

Equals(object?)

Checks if the specified span is equal to the current span.

public override bool Equals(object? o)

Parameters

o object

Returns

bool

GetCoveredText(ICharSequence)

Retrieves the string covered by the current span of the specified text.

public virtual ICharSequence GetCoveredText(ICharSequence text)

Parameters

text ICharSequence

Returns

ICharSequence

the substring covered by the current span

GetHashCode()

Generates a hash code of the current span.

public override int GetHashCode()

Returns

int

Intersects(Span)

Returns true if the specified span intersects with this span.

public virtual bool Intersects(Span s)

Parameters

s Span

The span to compare with this span.

Returns

bool

true is the spans overlap; false otherwise.

SpansToStrings(Span[], ICharSequence)

Converts an array of Spans to an array of strings.

public static string[] SpansToStrings(Span[] spans, ICharSequence s)

Parameters

spans Span[]
s ICharSequence

Returns

string[]

the strings

SpansToStrings(Span[], string[])

public static string[] SpansToStrings(Span[] spans, string[] tokens)

Parameters

spans Span[]
tokens string[]

Returns

string[]

StartsWith(Span)

Returns true if the specified span is the begin of this span and the specified span is contained in this span.

public virtual bool StartsWith(Span s)

Parameters

s Span

The span to compare with this span.

Returns

bool

true if the specified span starts with this span and is contained in this span; false otherwise

ToString()

Generates a human readable string.

public override string ToString()

Returns

string

Trim(ICharSequence)

Return a copy of this span with leading and trailing white spaces removed.

public virtual Span Trim(ICharSequence text)

Parameters

text ICharSequence

Returns

Span

the trimmed span or the same object if already trimmed