diff --git a/lib/pangea/constants/language_constants.dart b/lib/pangea/constants/language_constants.dart index 73137a300..a0aec4e7d 100644 --- a/lib/pangea/constants/language_constants.dart +++ b/lib/pangea/constants/language_constants.dart @@ -20,5 +20,3 @@ final LanguageDetection unknownLanguageDetection = LanguageDetection( langCode: LanguageKeys.unknownLanguage, confidence: 0.5, ); - -const double languageDetectionConfidenceThreshold = 0.95; diff --git a/lib/pangea/controllers/language_detection_controller.dart b/lib/pangea/controllers/language_detection_controller.dart index 51d7c973a..7214bdd51 100644 --- a/lib/pangea/controllers/language_detection_controller.dart +++ b/lib/pangea/controllers/language_detection_controller.dart @@ -61,7 +61,7 @@ class LanguageDetectionResponse { factory LanguageDetectionResponse.fromJson(Map json) { return LanguageDetectionResponse( detections: List.from( - json['detections'].map( + (json['detections'] as Iterable).map( (e) => LanguageDetection.fromJson(e), ), ), @@ -71,7 +71,7 @@ class LanguageDetectionResponse { Map 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. diff --git a/lib/pangea/models/igc_text_data_model.dart b/lib/pangea/models/igc_text_data_model.dart index d95210388..b2e05d0b0 100644 --- a/lib/pangea/models/igc_text_data_model.dart +++ b/lib/pangea/models/igc_text_data_model.dart @@ -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