loadJsonProfile method

void loadJsonProfile(
  1. List<String> jsonProfiles
)

Implementation

void loadJsonProfile(List<String> jsonProfiles) {
  int langSize = jsonProfiles.length;
  int index = 0;
  if (langSize < 2) {
    throw LangDetectException(
        ErrorCode.needLoadProfileError, 'Need more than 2 profiles.');
  }

  for (String jsonProfile in jsonProfiles) {
    try {
      final jsonData = jsonDecode(jsonProfile);
      LangProfile profile = LangProfile(
          name: jsonData['name'],
          freq: (jsonData['freq'] as Map<String, dynamic>)
              .map((key, value) => MapEntry(key, value.toInt())),
          nWords: (jsonData['n_words'].cast<int>() as List<int>));
      addProfile(profile, index, langSize);
      index += 1;
    } catch (e) {
      throw LangDetectException(
          ErrorCode.formatError, 'Profile format error.$jsonProfile');
    }
  }
}