jsut use the top detection (#1070)

This commit is contained in:
wcjord 2024-11-19 17:16:07 -05:00 committed by GitHub
parent e9f8483704
commit 5bea087353
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 12 additions and 9 deletions

View file

@ -20,5 +20,3 @@ final LanguageDetection unknownLanguageDetection = LanguageDetection(
langCode: LanguageKeys.unknownLanguage,
confidence: 0.5,
);
const double languageDetectionConfidenceThreshold = 0.95;

View file

@ -61,7 +61,7 @@ class LanguageDetectionResponse {
factory LanguageDetectionResponse.fromJson(Map<String, dynamic> json) {
return LanguageDetectionResponse(
detections: List<LanguageDetection>.from(
json['detections'].map(
(json['detections'] as Iterable).map(
(e) => LanguageDetection.fromJson(e),
),
),
@ -71,7 +71,7 @@ class LanguageDetectionResponse {
Map<String, dynamic> toJson() {
return {
'detections': detections,
'detections': detections.map((e) => e.toJson()).toList(),
'full_text': fullText,
};
}
@ -83,6 +83,8 @@ class LanguageDetectionResponse {
return detections.firstOrNull ?? unknownLanguageDetection;
}
static const double languageDetectionConfidenceThreshold = 0.95;
/// Returns the highest validated detection based on the confidence threshold.
/// If the highest confidence detection is below the threshold, the unknown language
/// detection is returned.

View file

@ -1,6 +1,7 @@
import 'dart:developer';
import 'package:collection/collection.dart';
import 'package:fluffychat/pangea/constants/language_constants.dart';
import 'package:fluffychat/pangea/controllers/language_detection_controller.dart';
import 'package:fluffychat/pangea/models/pangea_match_model.dart';
import 'package:fluffychat/pangea/models/pangea_token_model.dart';
@ -101,11 +102,13 @@ class IGCTextData {
/// if we have run igc/it and there are no matches, we can relax the threshold
/// and use the highest confidence detection
String get detectedLanguage {
if (!(enableIGC && enableIT) || matches.isNotEmpty) {
return detections.highestValidatedDetection().langCode;
} else {
return detections.highestConfidenceDetection.langCode;
}
return detections.detections.firstOrNull?.langCode ??
LanguageKeys.unknownLanguage;
// if (!(enableIGC && enableIT) || matches.isNotEmpty) {
// return detections.highestValidatedDetection().langCode;
// } else {
// return detections.highestConfidenceDetection.langCode;
// }
}
// reconstruct fullText based on accepted match