guess grammar category when missing, saving form when available
This commit is contained in:
parent
2d2f063ba9
commit
b37074459e
8 changed files with 240 additions and 37 deletions
|
|
@ -4158,7 +4158,9 @@
|
|||
"goToSpace": "Go to space: {space}",
|
||||
"@goToSpace": {
|
||||
"type": "text",
|
||||
"space": {}
|
||||
"placeholders": {
|
||||
"space": {}
|
||||
}
|
||||
},
|
||||
"markAsUnread": "Mark as unread",
|
||||
"userLevel": "{level} - User",
|
||||
|
|
|
|||
167
lib/pangea/constants/morph_categories_and_labels.dart
Normal file
167
lib/pangea/constants/morph_categories_and_labels.dart
Normal file
|
|
@ -0,0 +1,167 @@
|
|||
const Map<String, List<String>> morphCategoriesAndLabels = {
|
||||
"Pos": [
|
||||
"ADJ",
|
||||
"ADP",
|
||||
"ADV",
|
||||
"AFFIX",
|
||||
"AUX",
|
||||
"CCONJ",
|
||||
"DET",
|
||||
"INTJ",
|
||||
"NOUN",
|
||||
"NUM",
|
||||
"PART",
|
||||
"PRON",
|
||||
"PROPN",
|
||||
"PUNCT",
|
||||
"SCONJ",
|
||||
"SPACE",
|
||||
"SYM",
|
||||
"VERB",
|
||||
"X",
|
||||
],
|
||||
"AdvType": ["Adverbial", "Tim"],
|
||||
"Aspect": [
|
||||
"Imp",
|
||||
"Perf",
|
||||
"Prog",
|
||||
"Hab",
|
||||
],
|
||||
"Case": [
|
||||
"Nom",
|
||||
"Acc",
|
||||
"Dat",
|
||||
"Gen",
|
||||
"Voc",
|
||||
"Abl",
|
||||
"Loc",
|
||||
"All",
|
||||
"Ins",
|
||||
"Ess",
|
||||
"Tra",
|
||||
"Com",
|
||||
"Par",
|
||||
"Adv",
|
||||
"Ref",
|
||||
"Rel",
|
||||
"Equ",
|
||||
"Dis",
|
||||
"Abs",
|
||||
"Erg",
|
||||
"Cau",
|
||||
"Ben",
|
||||
"Sub",
|
||||
"Sup",
|
||||
"Tem",
|
||||
"Obl",
|
||||
"Acc,Dat",
|
||||
"Acc,Nom",
|
||||
"Pre",
|
||||
],
|
||||
"ConjType": ["Coord", "Sub", "Cmp"],
|
||||
"Definite": ["Def", "Ind", "Cons"],
|
||||
"Degree": [
|
||||
"Pos",
|
||||
"Cmp",
|
||||
"Sup",
|
||||
"Abs",
|
||||
],
|
||||
"Evident": ["Fh", "Nfh"],
|
||||
"Foreign": ["Yes"],
|
||||
"Gender": ["Masc", "Fem", "Neut", "Com"],
|
||||
"Mood": [
|
||||
"Ind",
|
||||
"Imp",
|
||||
"Sub",
|
||||
"Cnd",
|
||||
"Opt",
|
||||
"Jus",
|
||||
"Adm",
|
||||
"Des",
|
||||
"Nec",
|
||||
"Pot",
|
||||
"Prp",
|
||||
"Qot",
|
||||
"Int",
|
||||
],
|
||||
"NounType": ["Prop", "Comm", "Not_proper"],
|
||||
"NumForm": [
|
||||
"Digit",
|
||||
"Word",
|
||||
"Roman",
|
||||
"Letter",
|
||||
],
|
||||
"NumType": [
|
||||
"Card",
|
||||
"Ord",
|
||||
"Mult",
|
||||
"Frac",
|
||||
"Sets",
|
||||
"Range",
|
||||
"Dist",
|
||||
],
|
||||
"Number": [
|
||||
"Sing",
|
||||
"Plur",
|
||||
"Dual",
|
||||
"Tri",
|
||||
"Pauc",
|
||||
"Grpa",
|
||||
"Grpl",
|
||||
"Inv",
|
||||
],
|
||||
"Number[psor]": ["Sing", "Plur", "Dual"],
|
||||
"Person": [
|
||||
"0",
|
||||
"1",
|
||||
"2",
|
||||
"3",
|
||||
"4",
|
||||
],
|
||||
"Polarity": ["Pos", "Neg"],
|
||||
"Polite": ["Infm", "Form", "Elev", "Humb"],
|
||||
"Poss": ["Yes"],
|
||||
"PrepCase": ["Npr"],
|
||||
"PronType": [
|
||||
"Prs",
|
||||
"Int",
|
||||
"Rel",
|
||||
"Dem",
|
||||
"Tot",
|
||||
"Neg",
|
||||
"Art",
|
||||
"Emp",
|
||||
"Exc",
|
||||
"Ind",
|
||||
"Rcp",
|
||||
"Int,Rel",
|
||||
],
|
||||
"PunctSide": ["Ini", "Fin"],
|
||||
"PunctType": [
|
||||
"Brck",
|
||||
"Dash",
|
||||
"Excl",
|
||||
"Peri",
|
||||
"Qest",
|
||||
"Quot",
|
||||
"Semi",
|
||||
"Colo",
|
||||
"Comm",
|
||||
],
|
||||
"Reflex": ["Yes"],
|
||||
"Tense": ["Pres", "Past", "Fut", "Imp", "Pqp", "Aor", "Eps", "Prosp"],
|
||||
"VerbForm": [
|
||||
"Fin",
|
||||
"Inf",
|
||||
"Sup",
|
||||
"Part",
|
||||
"Conv",
|
||||
"Vnoun",
|
||||
"Ger",
|
||||
"Adn",
|
||||
"Lng",
|
||||
],
|
||||
"VerbType": ["Mod", "Caus"],
|
||||
"Voice": ["Act", "Mid", "Pass", "Antip", "Cau", "Dir", "Inv", "Rcp", "Caus"],
|
||||
"X": ["X"],
|
||||
};
|
||||
|
|
@ -189,6 +189,7 @@ class PutAnalyticsController extends BaseController<AnalyticsStream> {
|
|||
OneConstructUse(
|
||||
useType: useType,
|
||||
lemma: entry.value,
|
||||
form: token.text.content,
|
||||
category: entry.key,
|
||||
constructType: ConstructTypeEnum.morph,
|
||||
metadata: metadata,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import 'dart:developer';
|
||||
|
||||
import 'package:fluffychat/pangea/constants/morph_categories_and_labels.dart';
|
||||
import 'package:fluffychat/pangea/enum/construct_use_type_enum.dart';
|
||||
import 'package:fluffychat/pangea/models/practice_activities.dart/practice_activity_model.dart';
|
||||
import 'package:fluffychat/pangea/utils/error_handler.dart';
|
||||
|
|
@ -49,12 +50,15 @@ class ConstructAnalyticsModel {
|
|||
}
|
||||
|
||||
class OneConstructUse {
|
||||
String? lemma;
|
||||
String lemma;
|
||||
|
||||
// practice activities do not currently include form in the target_construct info
|
||||
// for that, this is nullable
|
||||
String? form;
|
||||
|
||||
/// For vocab constructs, this is the POS. For morph
|
||||
/// constructs, this is the morphological category.
|
||||
String? category;
|
||||
String category;
|
||||
|
||||
ConstructTypeEnum constructType;
|
||||
ConstructUseTypeEnum useType;
|
||||
|
|
@ -70,8 +74,8 @@ class OneConstructUse {
|
|||
required this.lemma,
|
||||
required this.constructType,
|
||||
required this.metadata,
|
||||
this.category,
|
||||
this.form,
|
||||
required this.category,
|
||||
required this.form,
|
||||
this.id,
|
||||
});
|
||||
|
||||
|
|
@ -80,27 +84,20 @@ class OneConstructUse {
|
|||
DateTime get timeStamp => metadata.timeStamp;
|
||||
|
||||
factory OneConstructUse.fromJson(Map<String, dynamic> json) {
|
||||
final constructType = json['constructType'] != null
|
||||
? ConstructTypeUtil.fromString(json['constructType'])
|
||||
: null;
|
||||
debugger(when: kDebugMode && constructType == null);
|
||||
debugger(when: kDebugMode && json['constructType'] == null);
|
||||
|
||||
final categoryEntry = json['cat'] ?? json['categories'];
|
||||
String? category;
|
||||
if (categoryEntry != null) {
|
||||
if ((categoryEntry is List) && categoryEntry.isNotEmpty) {
|
||||
category = categoryEntry.first;
|
||||
} else if (categoryEntry is String) {
|
||||
category = categoryEntry;
|
||||
}
|
||||
}
|
||||
final ConstructTypeEnum constructType = json['constructType'] != null
|
||||
? ConstructTypeUtil.fromString(json['constructType'])
|
||||
: ConstructTypeEnum.vocab;
|
||||
|
||||
return OneConstructUse(
|
||||
useType: ConstructUseTypeUtil.fromString(json['useType']),
|
||||
lemma: json['lemma'],
|
||||
form: json['form'],
|
||||
category: category,
|
||||
constructType: constructType ?? ConstructTypeEnum.vocab,
|
||||
category: constructType == ConstructTypeEnum.morph
|
||||
? getCategory(json)
|
||||
: "Other",
|
||||
constructType: constructType,
|
||||
id: json['id'],
|
||||
metadata: ConstructUseMetaData(
|
||||
eventId: json['msgId'],
|
||||
|
|
@ -110,21 +107,52 @@ class OneConstructUse {
|
|||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final Map<String, dynamic> data = {
|
||||
'useType': useType.string,
|
||||
'chatId': metadata.roomId,
|
||||
'timeStamp': metadata.timeStamp.toIso8601String(),
|
||||
'form': form,
|
||||
'msgId': metadata.eventId,
|
||||
};
|
||||
Map<String, dynamic> toJson() => {
|
||||
'useType': useType.string,
|
||||
'chatId': metadata.roomId,
|
||||
'timeStamp': metadata.timeStamp.toIso8601String(),
|
||||
'form': form,
|
||||
'msgId': metadata.eventId,
|
||||
'lemma': lemma,
|
||||
'constructType': constructType.string,
|
||||
'categories': category,
|
||||
'id': id,
|
||||
};
|
||||
|
||||
data['lemma'] = lemma!;
|
||||
data['constructType'] = constructType.string;
|
||||
static String getCategory(Map<String, dynamic> json) {
|
||||
final categoryEntry = json['cat'] ?? json['categories'];
|
||||
|
||||
if (id != null) data['id'] = id;
|
||||
data['categories'] = category;
|
||||
return data;
|
||||
if (categoryEntry == null) {
|
||||
return _guessGrammarCategory(json["lemma"]);
|
||||
}
|
||||
|
||||
if ((categoryEntry is List)) {
|
||||
if (categoryEntry.isEmpty) {
|
||||
return _guessGrammarCategory(json["lemma"]);
|
||||
}
|
||||
return categoryEntry.first;
|
||||
} else if (categoryEntry is String) {
|
||||
return categoryEntry;
|
||||
}
|
||||
|
||||
debugPrint(
|
||||
"Category entry is not a list or string -${json['cat'] ?? json['categories']}-",
|
||||
);
|
||||
return _guessGrammarCategory(json["lemma"]);
|
||||
}
|
||||
|
||||
static String _guessGrammarCategory(String morphLemma) {
|
||||
for (final String category in morphCategoriesAndLabels.keys) {
|
||||
if (morphCategoriesAndLabels[category]!.contains(morphLemma)) {
|
||||
debugPrint(
|
||||
"found missing construct category for $morphLemma: $category");
|
||||
return category;
|
||||
}
|
||||
}
|
||||
ErrorHandler.logError(
|
||||
m: "Morph construct lemma $morphLemma not found in morph categories and labels",
|
||||
);
|
||||
return "Other";
|
||||
}
|
||||
|
||||
Room? getRoom(Client client) {
|
||||
|
|
@ -140,9 +168,9 @@ class OneConstructUse {
|
|||
int get pointValue => useType.pointValue;
|
||||
|
||||
ConstructIdentifier get identifier => ConstructIdentifier(
|
||||
lemma: lemma!,
|
||||
lemma: lemma,
|
||||
type: constructType,
|
||||
category: category ?? "",
|
||||
category: category,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -143,6 +143,8 @@ class ActivityRecordResponse {
|
|||
.map(
|
||||
(construct) => OneConstructUse(
|
||||
lemma: construct.lemma,
|
||||
// TODO - add form to practiceActivity target_construct data somehow
|
||||
form: null,
|
||||
constructType: construct.type,
|
||||
useType: useType,
|
||||
metadata: metadata,
|
||||
|
|
|
|||
|
|
@ -159,6 +159,7 @@ class PangeaRepresentation {
|
|||
OneConstructUse(
|
||||
useType: useType,
|
||||
lemma: entry.value,
|
||||
form: token.text.content,
|
||||
category: entry.key,
|
||||
constructType: ConstructTypeEnum.morph,
|
||||
metadata: metadata,
|
||||
|
|
@ -210,6 +211,7 @@ class PangeaRepresentation {
|
|||
OneConstructUse(
|
||||
useType: ConstructUseTypeEnum.ga,
|
||||
lemma: entry.value,
|
||||
form: token.text.content,
|
||||
category: entry.key,
|
||||
constructType: ConstructTypeEnum.morph,
|
||||
metadata: metadata,
|
||||
|
|
@ -227,6 +229,7 @@ class PangeaRepresentation {
|
|||
OneConstructUse(
|
||||
useType: ConstructUseTypeEnum.wa,
|
||||
lemma: entry.value,
|
||||
form: token.text.content,
|
||||
category: entry.key,
|
||||
constructType: ConstructTypeEnum.morph,
|
||||
metadata: metadata,
|
||||
|
|
|
|||
|
|
@ -458,6 +458,6 @@ String? getGrammarCopy({
|
|||
'context': context,
|
||||
},
|
||||
);
|
||||
return key; // Fallback to the key itself if no match is found
|
||||
return lemma; // Fallback to the lemma itself if no match is found
|
||||
}
|
||||
}
|
||||
|
|
@ -2,7 +2,7 @@ import 'package:fluffychat/config/app_config.dart';
|
|||
import 'package:fluffychat/pangea/enum/construct_type_enum.dart';
|
||||
import 'package:fluffychat/pangea/enum/progress_indicators_enum.dart';
|
||||
import 'package:fluffychat/pangea/models/analytics/construct_list_model.dart';
|
||||
import 'package:fluffychat/pangea/utils/get_grammar_copy.dart';
|
||||
import 'package:fluffychat/pangea/utils/grammar/get_grammar_copy.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class ConstructUsesXPTile extends StatelessWidget {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue