convert choreo record into morph GA uses on send

This commit is contained in:
ggurdin 2024-11-07 12:47:43 -05:00
parent 1f5d66e203
commit 4a2a8bf7bd
No known key found for this signature in database
GPG key ID: A01CB41737CBB478
4 changed files with 67 additions and 7 deletions

View file

@ -683,11 +683,18 @@ class ChatController extends State<ChatPageWithRoom>
AnalyticsStream(
eventId: msgEventId,
roomId: room.id,
constructs: originalSent!.vocabUses(
choreo: choreo,
tokens: tokensSent!.tokens,
metadata: metadata,
),
constructs: [
...originalSent!.vocabUses(
choreo: choreo,
tokens: tokensSent!.tokens,
metadata: metadata,
),
...originalSent.morphConstructUses(
choreo: choreo,
tokens: tokensSent.tokens,
metadata: metadata,
),
],
origin: AnalyticsUpdateOrigin.sendMessage,
),
);

View file

@ -100,7 +100,6 @@ extension ConstructUseTypeExtension on ConstructUseTypeEnum {
case ConstructUseTypeEnum.corWL:
return 3;
case ConstructUseTypeEnum.ga:
case ConstructUseTypeEnum.corIGC:
return 2;
@ -115,6 +114,9 @@ extension ConstructUseTypeExtension on ConstructUseTypeEnum {
case ConstructUseTypeEnum.nan:
return 0;
case ConstructUseTypeEnum.ga:
return -1;
case ConstructUseTypeEnum.incIt:
case ConstructUseTypeEnum.incIGC:
return -2;

View file

@ -108,7 +108,7 @@ class PangeaMatch {
}
bool isOffsetInMatchSpan(int offset) =>
offset >= match.offset && offset <= match.offset + match.length;
offset >= match.offset && offset < match.offset + match.length;
Color get underlineColor {
switch (match.rule?.id ?? "unknown") {

View file

@ -131,6 +131,57 @@ class PangeaRepresentation {
return uses;
}
List<OneConstructUse> morphConstructUses({
required List<PangeaToken> tokens,
Event? event,
ConstructUseMetaData? metadata,
ChoreoRecord? choreo,
}) {
final List<OneConstructUse> uses = [];
if (event?.roomId == null && metadata?.roomId == null) {
return uses;
}
if (choreo == null) {
return uses;
}
metadata ??= ConstructUseMetaData(
roomId: event!.roomId!,
eventId: event.eventId,
timeStamp: event.originServerTs,
);
for (final step in choreo.choreoSteps) {
if (step.acceptedOrIgnoredMatch?.status == PangeaMatchStatus.accepted) {
final List<PangeaToken> tokensForMatch = [];
for (final token in tokens) {
if (step.acceptedOrIgnoredMatch!.isOffsetInMatchSpan(
token.text.offset,
)) {
tokensForMatch.add(token);
}
}
for (final token in tokensForMatch) {
token.morph.forEach((key, value) {
uses.add(
OneConstructUse(
useType: ConstructUseTypeEnum.ga,
lemma: value,
categories: [key],
constructType: ConstructTypeEnum.morph,
metadata: metadata!,
),
);
});
}
}
}
return uses;
}
/// Returns a [OneConstructUse] for the given [token]
/// If there is no [choreo], the [token] is
/// considered to be a [ConstructUseTypeEnum.wa] as long as it matches the target language.