TextScoringService
in package
Service for calculating text difficulty scores.
Analyzes texts against the user's known vocabulary to determine comprehensibility - useful for recommending appropriate reading material.
Tags
Table of Contents
Methods
- getRecommendedTexts() : array<string|int, TextScore>
- Get texts recommended for reading based on comprehensibility.
- scoreText() : TextScore
- Calculate the difficulty score for a single text.
- scoreTexts() : array<int, TextScore>
- Score multiple texts at once (for listing/recommendations).
- calculateVocabularyStats() : array{total: int, known: int, learning: int, unknown: int}
- Calculate vocabulary statistics for a single text.
- calculateVocabularyStatsForTexts() : array<int, array{total: int, known: int, learning: int, unknown: int}>
- Calculate vocabulary statistics for multiple texts.
- getUnknownWords() : array<string|int, string>
- Get the list of unknown words in a text.
Methods
getRecommendedTexts()
Get texts recommended for reading based on comprehensibility.
public
getRecommendedTexts(int $languageId[, float $targetComprehensibility = 0.95 ][, int $limit = 10 ]) : array<string|int, TextScore>
Returns texts ordered by proximity to optimal comprehensibility (95%).
Parameters
- $languageId : int
-
The language to filter by
- $targetComprehensibility : float = 0.95
-
Target comprehensibility (default 0.95)
- $limit : int = 10
-
Maximum number of texts to return
Return values
array<string|int, TextScore> —Array of TextScore objects, best matches first
scoreText()
Calculate the difficulty score for a single text.
public
scoreText(int $textId[, int $unknownWordsLimit = 20 ]) : TextScore
Parameters
- $textId : int
-
The text ID to score
- $unknownWordsLimit : int = 20
-
Maximum unknown words to return in preview
Return values
TextScore —The calculated score
scoreTexts()
Score multiple texts at once (for listing/recommendations).
public
scoreTexts(array<string|int, int> $textIds) : array<int, TextScore>
Parameters
- $textIds : array<string|int, int>
-
Array of text IDs to score
Return values
array<int, TextScore> —Map of textId => TextScore
calculateVocabularyStats()
Calculate vocabulary statistics for a single text.
private
calculateVocabularyStats(int $textId) : array{total: int, known: int, learning: int, unknown: int}
Parameters
- $textId : int
-
The text ID
Return values
array{total: int, known: int, learning: int, unknown: int}calculateVocabularyStatsForTexts()
Calculate vocabulary statistics for multiple texts.
private
calculateVocabularyStatsForTexts(array<string|int, int> $textIds) : array<int, array{total: int, known: int, learning: int, unknown: int}>
Parameters
- $textIds : array<string|int, int>
-
Array of text IDs
Return values
array<int, array{total: int, known: int, learning: int, unknown: int}>getUnknownWords()
Get the list of unknown words in a text.
private
getUnknownWords(int $textId, int $limit) : array<string|int, string>
Parameters
- $textId : int
-
The text ID
- $limit : int
-
Maximum number of words to return
Return values
array<string|int, string> —Array of unknown word texts