Class Span
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
spanSpanthe span that has no prob or the prob is incorrect and a new Span must be generated
probdoublethe 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(int, int)
Initializes a new Span Object. Sets the prob to 0 as default
public Span(int s, int e)
Parameters
Span(int, int, double)
public Span(int s, int e, double prob)
Parameters
sintthe start of the span (the token index, not the char index)
eintthe end of the span (the token index, not the char index)
probdouble
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
sintstart of span.
eintend of span, which is +1 more than the last element in the span.
typestringthe 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
sintstart of span.
eintend of span, which is +1 more than the last element in the span.
typestringthe type of the span
probdoubleprobability 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
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
sSpan
Returns
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
sSpanThe 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
indexintthe 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
sSpanThe 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
oobject
Returns
GetCoveredText(ICharSequence)
Retrieves the string covered by the current span of the specified text.
public virtual ICharSequence GetCoveredText(ICharSequence text)
Parameters
textICharSequence
Returns
- ICharSequence
the substring covered by the current span
GetHashCode()
Generates a hash code of the current span.
public override int GetHashCode()
Returns
Intersects(Span)
Returns true if the specified span intersects with this span.
public virtual bool Intersects(Span s)
Parameters
sSpanThe span to compare with this span.
Returns
- bool
true is the spans overlap; false otherwise.
SpansToStrings(Span[], ICharSequence)
public static string[] SpansToStrings(Span[] spans, ICharSequence s)
Parameters
spansSpan[]sICharSequence
Returns
- string[]
the strings
SpansToStrings(Span[], string[])
public static string[] SpansToStrings(Span[] spans, string[] tokens)
Parameters
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
sSpanThe 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
Trim(ICharSequence)
Return a copy of this span with leading and trailing white spaces removed.
public virtual Span Trim(ICharSequence text)
Parameters
textICharSequence
Returns
- Span
the trimmed span or the same object if already trimmed