Merge branch 'main' into store-construct-list-model

pull/1476/head
ggurdin 1 year ago
commit b63dfa8f6b
No known key found for this signature in database
GPG Key ID: A01CB41737CBB478

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

@ -89,13 +89,13 @@ class PangeaRepresentation {
return data; return data;
} }
/// Get construct uses of type vocab for the message. /// Get construct uses for the message that weren't captured during language assistance.
/// Takes a list of tokens and a choreo record, which is searched /// Takes a list of tokens and a choreo record, which is searched
/// through for each token for its construct use type. /// through for each token for its construct use type.
/// Also takes either an event (typically when the Representation itself is /// Also takes either an event (typically when the Representation itself is
/// available) or construct use metadata (when the event is not available, /// available) or construct use metadata (when the event is not available,
/// i.e. immediately after message send) to create the construct use. /// i.e. immediately after message send) to create the construct use.
List<OneConstructUse> vocabUses({ List<OneConstructUse> vocabAndMorphUses({
required List<PangeaToken> tokens, required List<PangeaToken> tokens,
Event? event, Event? event,
ConstructUseMetaData? metadata, ConstructUseMetaData? metadata,
@ -131,64 +131,15 @@ class PangeaRepresentation {
return uses; 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] /// Returns a [OneConstructUse] for the given [token]
/// If there is no [choreo], the [token] is /// If there is no [choreo], the [token] is
/// considered to be a [ConstructUseTypeEnum.wa] as long as it matches the target language. /// considered to be a [ConstructUseTypeEnum.wa] as long as it matches the target language.
/// Later on, we may want to consider putting it in some category of like 'pending' /// Later on, we may want to consider putting it in some category of like 'pending'
/// If the [token] is in the [choreo.acceptedOrIgnoredMatch], it is considered to be a [ConstructUseTypeEnum.ga]. ///
/// If the [token] is in the [choreo.acceptedOrIgnoredMatch.choices], it is considered to be a [ConstructUseTypeEnum.corIt]. /// For both vocab and morph constructs, we should
/// If the [token] is not included in any choreoStep, it is considered to be a [ConstructUseTypeEnum.wa]. /// 1) give wa if no assistance was used
/// 2) give ga if IGC was used and
/// 3) make no use if IT was used
List<OneConstructUse> _getUsesForToken( List<OneConstructUse> _getUsesForToken(
PangeaToken token, PangeaToken token,
ConstructUseMetaData metadata, { ConstructUseMetaData metadata, {
@ -218,7 +169,7 @@ class PangeaRepresentation {
if (lemma.saveVocab) { if (lemma.saveVocab) {
uses.add( uses.add(
lemma.toVocabUse( lemma.toVocabUse(
inUserL2 ? ConstructUseTypeEnum.wa : ConstructUseTypeEnum.unk, useType,
metadata, metadata,
), ),
); );
@ -231,8 +182,12 @@ class PangeaRepresentation {
/// is in the overall step text, then token was a ga /// is in the overall step text, then token was a ga
final bool isAcceptedMatch = final bool isAcceptedMatch =
step.acceptedOrIgnoredMatch?.status == PangeaMatchStatus.accepted; step.acceptedOrIgnoredMatch?.status == PangeaMatchStatus.accepted;
final bool isITStep = step.itStep != null;
if (!isAcceptedMatch && !isITStep) continue; // if the token was in an IT match, return no uses
if (step.itStep != null) return [];
// if this step was not accepted, continue
if (!isAcceptedMatch) continue;
if (isAcceptedMatch && if (isAcceptedMatch &&
step.acceptedOrIgnoredMatch?.match.choices != null) { step.acceptedOrIgnoredMatch?.match.choices != null) {
@ -240,25 +195,33 @@ class PangeaRepresentation {
final bool stepContainedToken = choices.any( final bool stepContainedToken = choices.any(
(choice) => (choice) =>
// if this choice contains the token's content // if this choice contains the token's content
choice.value.contains(content) && choice.value.contains(content),
// if the complete input text after this step
// contains the choice (why is this here?)
step.text.contains(choice.value),
); );
if (stepContainedToken) { if (stepContainedToken) {
return []; // give ga if IGC was used
} uses.add(
lemma.toVocabUse(
ConstructUseTypeEnum.ga,
metadata,
),
);
for (final entry in token.morph.entries) {
uses.add(
OneConstructUse(
useType: ConstructUseTypeEnum.ga,
lemma: entry.value,
categories: [entry.key],
constructType: ConstructTypeEnum.morph,
metadata: metadata,
),
);
} }
return uses;
if (isITStep && step.itStep?.chosenContinuance != null) {
final bool pickedThroughIT =
step.itStep!.chosenContinuance!.text.contains(content);
if (pickedThroughIT) {
return [];
} }
} }
} }
// the token wasn't found in any IT or IGC step, so it was wa
for (final entry in token.morph.entries) { for (final entry in token.morph.entries) {
uses.add( uses.add(
OneConstructUse( OneConstructUse(

Loading…
Cancel
Save