getWordCollection method
Returns the word collection as a FileContents object.
If saveToMemory is enabled and the collection is already loaded, returns the cached version. Otherwise, reads from the file.
Throws an Exception if the utility is not initialized.
Implementation
Future<FileContents> getWordCollection() async {
if (isInitialized) {
FileContents? collectionFromMemory = getCollectionFromMemory;
if (saveToMemory && collectionFromMemory != null) {
return collectionFromMemory;
} else {
var result = await readFile(_collectionPath!);
if (saveToMemory) {
_collection = result;
}
return result;
}
} else {
throw Exception('Not Initialized');
}
}