classifyText method

  1. @override
Future<Map<String, double>> classifyText(
  1. String text, {
  2. String? sessionId,
  3. List<String>? categories,
})
override

Implementation

@override
Future<Map<String, double>> classifyText(
  String text, {
  String? sessionId,
  List<String>? categories,
}) async {
  if (text.trim().isEmpty) {
    throw AppleFoundationException(
      'Text cannot be empty',
      code: 'INVALID_TEXT',
    );
  }

  try {
    final Map<dynamic, dynamic>? result =
        await _invokeMethodWithTimeout<Map<dynamic, dynamic>>(
          'classifyText',
          {
            'text': text,
            if (sessionId != null) 'sessionId': sessionId,
            if (categories != null && categories.isNotEmpty)
              'categories': categories,
          },
        );

    if (result == null) {
      throw AppleFoundationException(
        'Received null response from native layer',
        code: 'NULL_RESPONSE',
      );
    }

    return Map<String, double>.from(result);
  } catch (e) {
    _logError('classifyText', e);
    throw AppleFoundationException(
      'Failed to classify text: ${e.toString()}',
      code: 'CLASSIFY_TEXT_FAILED',
      details: {'sessionId': sessionId, 'categories': categories},
    );
  }
}