From 0265019284c5ec6e189a7015f4e4404f055cb51d Mon Sep 17 00:00:00 2001 From: ggurdin Date: Fri, 6 Sep 2024 10:52:13 -0400 Subject: [PATCH] added 'categories' field to construct use model and started saving morph category --- .../controllers/my_analytics_controller.dart | 29 +++++++++---------- .../models/analytics/constructs_model.dart | 11 +++++-- .../models/representation_content_model.dart | 27 ++++++++--------- 3 files changed, 35 insertions(+), 32 deletions(-) diff --git a/lib/pangea/controllers/my_analytics_controller.dart b/lib/pangea/controllers/my_analytics_controller.dart index c24f3391b..15079a515 100644 --- a/lib/pangea/controllers/my_analytics_controller.dart +++ b/lib/pangea/controllers/my_analytics_controller.dart @@ -201,22 +201,19 @@ class MyAnalyticsController extends BaseController { ) .toList(); - final List morphs = tokens - .map((t) => t.morph.values) - .expand((m) => m) - .cast() - .toList(); - - uses.addAll( - morphs.map( - (morph) => OneConstructUse( - useType: useType, - lemma: morph, - constructType: ConstructTypeEnum.morph, - metadata: metadata, - ), - ), - ); + for (final token in tokens) { + for (final entry in token.morph.entries) { + uses.add( + OneConstructUse( + useType: useType, + lemma: entry.value, + categories: [entry.key], + constructType: ConstructTypeEnum.morph, + metadata: metadata, + ), + ); + } + } final level = _pangeaController.analytics.level; addLocalMessage('draft$roomID', uses).then( diff --git a/lib/pangea/models/analytics/constructs_model.dart b/lib/pangea/models/analytics/constructs_model.dart index 045453228..fd9710a80 100644 --- a/lib/pangea/models/analytics/constructs_model.dart +++ b/lib/pangea/models/analytics/constructs_model.dart @@ -74,8 +74,9 @@ class ConstructAnalyticsModel { class OneConstructUse { String? lemma; - ConstructTypeEnum? constructType; String? form; + List categories; + ConstructTypeEnum? constructType; ConstructUseTypeEnum useType; String? id; ConstructUseMetaData metadata; @@ -85,6 +86,7 @@ class OneConstructUse { required this.lemma, required this.constructType, required this.metadata, + this.categories = const [], this.form, this.id, }); @@ -100,6 +102,9 @@ class OneConstructUse { ConstructUseTypeEnum.unk, lemma: json['lemma'], form: json['form'], + categories: json['categories'] != null + ? List.from(json['categories']) + : [], constructType: json['constructType'] != null ? ConstructTypeUtil.fromString(json['constructType']) : null, @@ -113,7 +118,7 @@ class OneConstructUse { } Map toJson([bool condensed = false]) { - final Map data = { + final Map data = { 'useType': useType.string, 'chatId': metadata.roomId, 'timeStamp': metadata.timeStamp.toIso8601String(), @@ -125,7 +130,7 @@ class OneConstructUse { data['constructType'] = constructType!.string; } if (id != null) data['id'] = id; - + data['categories'] = categories; return data; } diff --git a/lib/pangea/models/representation_content_model.dart b/lib/pangea/models/representation_content_model.dart index be68c1195..a318d1831 100644 --- a/lib/pangea/models/representation_content_model.dart +++ b/lib/pangea/models/representation_content_model.dart @@ -146,23 +146,23 @@ class PangeaRepresentation { final List uses = []; final lemma = token.lemma; final content = token.text.content; - final morphs = token.morph.values.toList(); if (choreo == null) { final bool inUserL2 = langCode == MatrixState.pangeaController.languageController.activeL2Code(); final useType = inUserL2 ? ConstructUseTypeEnum.wa : ConstructUseTypeEnum.unk; - uses.addAll( - morphs.map( - (morph) => OneConstructUse( + for (final entry in token.morph.entries) { + uses.add( + OneConstructUse( useType: useType, - lemma: morph, + lemma: entry.value, + categories: [entry.key], constructType: ConstructTypeEnum.morph, metadata: metadata, ), - ), - ); + ); + } uses.add( lemma.toVocabUse( inUserL2 ? ConstructUseTypeEnum.wa : ConstructUseTypeEnum.unk, @@ -205,16 +205,17 @@ class PangeaRepresentation { } } - uses.addAll( - morphs.map( - (morph) => OneConstructUse( + for (final entry in token.morph.entries) { + uses.add( + OneConstructUse( useType: ConstructUseTypeEnum.wa, - lemma: morph, + lemma: entry.value, + categories: [entry.key], constructType: ConstructTypeEnum.morph, metadata: metadata, ), - ), - ); + ); + } uses.add( lemma.toVocabUse( ConstructUseTypeEnum.wa,