SentenceService
in package
Service class for sentence operations.
Tags
Table of Contents
Properties
Methods
- __construct() : mixed
- Constructor - initialize dependencies.
- buildSentencesContainingWordQuery() : array{sql: string, params: array}
- Build a prepared statement query to find sentences containing a word.
- findSentencesFromWord() : array<int, array<string, mixed>>
- Perform a SQL query to find sentences containing a word.
- formatSentence() : array<string|int, string>
- Format the sentence(s) $seid containing $wordlc highlighting $wordlc.
- get20Sentences() : string
- Show 20 sentences containing $wordlc.
- getSentenceAtPosition() : string|null
- Get the sentence text at a specific position in a text.
- getSentencesWithWord() : array<string|int, array<string|int, string>>
- Return sentences containing a word.
- getSentenceText() : string|null
- Get the formatted text of a sentence by its ID.
- renderExampleSentencesArea() : string
- Render the area for example sentences of a word.
- convertZwsToSpacing() : string
- Convert zero-width space (ZWS) markers to proper spacing.
- executeSentencesContainingWordQuery() : array<int, array<string, mixed>>
- Execute a SQL query to find sentences containing a word (complex search).
- extractCenteredPortion() : string
- Extract a centered portion of text.
- extractPortionAroundWord() : string
- Extract a portion of text centered around a specific word.
Properties
$textParsingService
private
TextParsingService
$textParsingService
Methods
__construct()
Constructor - initialize dependencies.
public
__construct([TextParsingService|null $textParsingService = null ]) : mixed
Parameters
- $textParsingService : TextParsingService|null = null
-
Text parsing service (optional for BC)
buildSentencesContainingWordQuery()
Build a prepared statement query to find sentences containing a word.
public
buildSentencesContainingWordQuery(string $wordlc, int $lid) : array{sql: string, params: array}
Use executeSentencesContainingWordQuery() for direct execution
Returns an array with 'sql' (with placeholders) and 'params' for use with prepared statements.
Parameters
- $wordlc : string
-
Word to look for in lowercase
- $lid : int
-
Language ID
Return values
array{sql: string, params: array} —Query SQL and parameters
findSentencesFromWord()
Perform a SQL query to find sentences containing a word.
public
findSentencesFromWord(int|null $wid, string $wordlc, int $lid[, int $limit = -1 ]) : array<int, array<string, mixed>>
Parameters
- $wid : int|null
-
Word ID or mode
- null: use $wordlc instead, simple search
- -1: use $wordlc with a more complex search
- 0 or above: sentences containing $wid
- $wordlc : string
-
Word to look for in lowercase
- $lid : int
-
Language ID
- $limit : int = -1
-
Maximum number of sentences to return
Return values
array<int, array<string, mixed>> —Query result rows
formatSentence()
Format the sentence(s) $seid containing $wordlc highlighting $wordlc.
public
formatSentence(int $seid, string $wordlc, int $mode) : array<string|int, string>
Parameters
- $seid : int
-
Sentence ID
- $wordlc : string
-
Term text in lower case
- $mode : int
-
- Up to 1: return only the current sentence
- Above 1: return previous sentence and current sentence
- Above 2: return previous, current and next sentence
Return values
array<string|int, string> —[0]=html, word in bold, [1]=text, word in }
get20Sentences()
Show 20 sentences containing $wordlc.
public
get20Sentences(int $lang, string $wordlc, int|null $wid, string $targetCtlId, int $mode) : string
Parameters
- $lang : int
-
Language ID
- $wordlc : string
-
Term in lower case.
- $wid : int|null
-
Word ID
- $targetCtlId : string
-
ID of the target textarea element
- $mode : int
-
- Up to 1: return only the current sentence
- Above 1: return previous and current sentence * Above 2: return previous, current and next sentence
Return values
string —HTML-formatted string of which elements are candidate sentences to use.
getSentenceAtPosition()
Get the sentence text at a specific position in a text.
public
getSentenceAtPosition(int $textId, int $position) : string|null
This method extracts the sentence containing the word at the given position. It handles cases where texts weren't properly split into sentences during parsing by finding sentence boundaries (punctuation) around the target position.
Parameters
- $textId : int
-
Text ID
- $position : int
-
Word position (Ti2Order)
Return values
string|null —The sentence containing the word, or null if not found
getSentencesWithWord()
Return sentences containing a word.
public
getSentencesWithWord(int $lang, string $wordlc, int|null $wid[, int|null $mode = 0 ][, int $limit = 20 ]) : array<string|int, array<string|int, string>>
Parameters
- $lang : int
-
Language ID
- $wordlc : string
-
Word to look for in lowercase
- $wid : int|null
-
Word ID
- null: use $wordlc instead, simple search
- -1: use $wordlc with a more complex search
- 0 or above: find sentences containing $wid
- $mode : int|null = 0
-
Sentences to get:
- Up to 1 is 1 sentence,
- 2 is previous and current sentence,
- 3 is previous, current and next one
- $limit : int = 20
-
Maximum number of sentences to return
Return values
array<string|int, array<string|int, string>> —Array of sentences found
getSentenceText()
Get the formatted text of a sentence by its ID.
public
getSentenceText(int $seid) : string|null
Reconstructs the sentence from word_occurrences table with proper spacing. Use this instead of reading SeText directly from sentences table.
Parameters
- $seid : int
-
Sentence ID
Return values
string|null —Formatted sentence text, or null if not found
renderExampleSentencesArea()
Render the area for example sentences of a word.
public
renderExampleSentencesArea(int $lang, string $termlc, string $targetCtlId, int $wid) : string
Parameters
- $lang : int
-
Language ID
- $termlc : string
-
Term text in lowercase
- $targetCtlId : string
-
ID of the target textarea element
- $wid : int
-
Word ID
Return values
string —HTML output
convertZwsToSpacing()
Convert zero-width space (ZWS) markers to proper spacing.
private
convertZwsToSpacing(string $text, string $termchar) : string
For languages that use spaces between words (LgRemoveSpaces = 0), this method converts ZWS markers in the text to actual spaces where appropriate (between words and after punctuation).
Parameters
- $text : string
-
Text with ZWS markers between tokens
- $termchar : string
-
Language's word character regex pattern
Return values
string —Text with proper spacing
executeSentencesContainingWordQuery()
Execute a SQL query to find sentences containing a word (complex search).
private
executeSentencesContainingWordQuery(string $wordlc, int $lid[, int $limit = -1 ]) : array<int, array<string, mixed>>
Parameters
- $wordlc : string
-
Word to look for in lowercase
- $lid : int
-
Language ID
- $limit : int = -1
-
Maximum number of sentences to return
Return values
array<int, array<string, mixed>> —Query result rows
extractCenteredPortion()
Extract a centered portion of text.
private
extractCenteredPortion(string $text, int $maxLength) : string
Parameters
- $text : string
-
The text to extract from
- $maxLength : int
-
Maximum length of the result
Return values
string —The extracted portion
extractPortionAroundWord()
Extract a portion of text centered around a specific word.
private
extractPortionAroundWord(string $text, string $word, int $maxLength) : string
Parameters
- $text : string
-
The text to extract from
- $word : string
-
The word to center around
- $maxLength : int
-
Maximum characters on each side of the word
Return values
string —The extracted portion