TextScore
in package
Value object representing a text's difficulty score.
Contains comprehensibility metrics based on comparing the text's vocabulary against the user's known words.
Tags
Table of Contents
Properties
- $knownWords : int
- $learningWords : int
- $textId : int
- $totalUniqueWords : int
- $unknownWords : int
- $unknownWordsList : array<string|int, mixed>
Methods
- __construct() : mixed
- comprehensibility() : float
- Calculate the comprehensibility percentage.
- comprehensibilityPercent() : float
- Calculate the comprehensibility as a percentage (0-100).
- difficultyLabel() : string
- Get a difficulty label based on comprehensibility.
- isOptimal() : bool
- Check if the text is at an optimal difficulty level.
- newWordsToLearn() : int
- Get the number of new words to learn from this text.
- toArray() : array<string, mixed>
- Convert to array for API responses.
Properties
$knownWords
public
int
$knownWords
$learningWords
public
int
$learningWords
$textId
public
int
$textId
$totalUniqueWords
public
int
$totalUniqueWords
$unknownWords
public
int
$unknownWords
$unknownWordsList
public
array<string|int, mixed>
$unknownWordsList
= []
Methods
__construct()
public
__construct(int $textId, int $totalUniqueWords, int $knownWords, int $learningWords, int $unknownWords[, array<string|int, string> $unknownWordsList = [] ]) : mixed
Parameters
- $textId : int
-
The text ID
- $totalUniqueWords : int
-
Total unique single words in text
- $knownWords : int
-
Words with status 5 or 99
- $learningWords : int
-
Words with status 1-4
- $unknownWords : int
-
Words not in user's vocabulary
- $unknownWordsList : array<string|int, string> = []
-
List of unknown word texts (for preview)
comprehensibility()
Calculate the comprehensibility percentage.
public
comprehensibility() : float
This represents the percentage of words the user already knows. A value of 0.95 means 95% of words are known.
Return values
float —Value between 0.0 and 1.0
comprehensibilityPercent()
Calculate the comprehensibility as a percentage (0-100).
public
comprehensibilityPercent() : float
Return values
float —Value between 0.0 and 100.0
difficultyLabel()
Get a difficulty label based on comprehensibility.
public
difficultyLabel() : string
Based on research suggesting 95-98% comprehension is optimal for language acquisition (Krashen's i+1 hypothesis).
Return values
string —One of: 'too_easy', 'optimal', 'challenging', 'difficult', 'too_hard'
isOptimal()
Check if the text is at an optimal difficulty level.
public
isOptimal() : bool
Optimal is defined as 95-98% comprehensibility.
Return values
boolnewWordsToLearn()
Get the number of new words to learn from this text.
public
newWordsToLearn() : int
Return values
inttoArray()
Convert to array for API responses.
public
toArray() : array<string, mixed>