ParserResult
in package
Immutable result from a parser containing sentences and tokens.
This class encapsulates the output of text parsing, providing structured access to both the sentence boundaries and individual tokens (words and non-words).
Tags
Table of Contents
Properties
- $sentences : array<string|int, mixed>
- $tokens : array<string|int, mixed>
Methods
- __construct() : mixed
- Create a new parser result.
- empty() : self
- Create an empty result.
- getSentenceCount() : int
- Get count of sentences.
- getSentences() : array<string|int, string>
- Get all sentences as strings.
- getTokenCount() : int
- Get count of all tokens.
- getTokens() : array<string|int, Token>
- Get all tokens.
- getTokensForSentence() : array<string|int, Token>
- Get tokens for a specific sentence.
- getWordCount() : int
- Get count of word tokens only.
- getWords() : array<string|int, Token>
- Get only word tokens (excluding punctuation/whitespace).
- isEmpty() : bool
- Check if the result is empty (no sentences parsed).
Properties
$sentences
private
array<string|int, mixed>
$sentences
$tokens
private
array<string|int, mixed>
$tokens
Methods
__construct()
Create a new parser result.
public
__construct(array<string|int, string> $sentences, array<string|int, Token> $tokens) : mixed
Parameters
- $sentences : array<string|int, string>
-
Array of sentence strings
- $tokens : array<string|int, Token>
-
Array of Token objects
Tags
empty()
Create an empty result.
public
static empty() : self
Return values
self —Empty parser result
getSentenceCount()
Get count of sentences.
public
getSentenceCount() : int
Return values
int —Number of sentences
getSentences()
Get all sentences as strings.
public
getSentences() : array<string|int, string>
Tags
Return values
array<string|int, string> —Array of sentence strings
getTokenCount()
Get count of all tokens.
public
getTokenCount() : int
Return values
int —Number of tokens
getTokens()
Get all tokens.
public
getTokens() : array<string|int, Token>
Tags
Return values
array<string|int, Token> —Array of Token objects
getTokensForSentence()
Get tokens for a specific sentence.
public
getTokensForSentence(int $sentenceIndex) : array<string|int, Token>
Parameters
- $sentenceIndex : int
-
Sentence index (0-based)
Tags
Return values
array<string|int, Token> —Tokens belonging to the specified sentence
getWordCount()
Get count of word tokens only.
public
getWordCount() : int
Return values
int —Number of words
getWords()
Get only word tokens (excluding punctuation/whitespace).
public
getWords() : array<string|int, Token>
Tags
Return values
array<string|int, Token> —Array of word tokens only
isEmpty()
Check if the result is empty (no sentences parsed).
public
isEmpty() : bool
Return values
bool —True if no sentences were parsed