preprocessSentence function
Implementation
Vector preprocessSentence(String sentence, Map<String, int> vocabulary, int maxLength) {
String cleaned = sentence.toLowerCase().replaceAll(RegExp(r'[^\w\s]+'), '');
List<double> tokens = [];
for (String word in cleaned.split(' ')) {
if (vocabulary.containsKey(word)) {
tokens.add(vocabulary[word]!.toDouble());
}
}
while (tokens.length < maxLength) {
tokens.add(0.0);
}
return tokens.sublist(0, maxLength);
}