fluffychat/lib/pangea/lemmas/lemma.dart
ggurdin 354e3a14d1
4919 further optimizing message info (#5033)
* remove original sent from message content

* don't add null fields to message content JSON
2026-01-02 14:30:05 -05:00

46 lines
1.1 KiB
Dart

/// Represents a lemma object
class Lemma {
/// [text] ex "ir" - text of the lemma of the word
String text;
/// [form] ex "vamos" - conjugated form of the lemma and as it appeared in some original text
final String form;
/// [saveVocab] true - whether to save the lemma to the user's vocabulary
/// vocab that are not saved: emails, urls, numbers, punctuation, etc.
/// server handles this determination
final bool saveVocab;
Lemma({
required this.text,
required this.saveVocab,
required this.form,
});
factory Lemma.fromJson(Map<String, dynamic> json) {
return Lemma(
text: json['text'],
saveVocab: json['save_vocab'] ?? json['saveVocab'] ?? false,
form: json["form"] ?? json['text'],
);
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = {
'text': text,
};
if (saveVocab) {
data['save_vocab'] = saveVocab;
}
if (text != form) {
data['form'] = form;
}
return data;
}
static Lemma create(String form) =>
Lemma(text: '', saveVocab: true, form: form);
}