jsut use the top detection (#1070)
This commit is contained in:
parent
e9f8483704
commit
5bea087353
3 changed files with 12 additions and 9 deletions
|
|
@ -20,5 +20,3 @@ final LanguageDetection unknownLanguageDetection = LanguageDetection(
|
|||
langCode: LanguageKeys.unknownLanguage,
|
||||
confidence: 0.5,
|
||||
);
|
||||
|
||||
const double languageDetectionConfidenceThreshold = 0.95;
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue