문자열의 언어를 식별하려면 FirebaseLanguageIdentification의 인스턴스를 가져온 후 문자열을 identifyLanguage() 메서드로 전달합니다.
예를 들면 다음과 같습니다.
FirebaseLanguageIdentificationlanguageIdentifier=FirebaseNaturalLanguage.getInstance().getLanguageIdentification();languageIdentifier.identifyLanguage(text).addOnSuccessListener(newOnSuccessListener<String>(){@OverridepublicvoidonSuccess(@NullableStringlanguageCode){if(languageCode!="und"){Log.i(TAG,"Language: "+languageCode);}else{Log.i(TAG,"Can't identify language.");}}}).addOnFailureListener(newOnFailureListener(){@OverridepublicvoidonFailure(@NonNullExceptione){// Model couldn’t be loaded or other internal error.// ...}});
호출이 성공하면 BCP-47 언어 코드가 성공 리스너로 전달되어 텍스트의 언어를 표시합니다. 지원 언어의 전체 목록을 참조하세요. 언어를 확실하게 감지할 수 없는 경우 und(미확인) 코드가 전달됩니다.
기본적으로 ML Kit는 신뢰값이 0.5 이상인 언어를 식별하는 경우에만 und 외의 값을 반환합니다. FirebaseLanguageIdentificationOptions 객체를 getLanguageIdentification()에 전달하여 이 기준을 변경할 수 있습니다.
문자열의 언어일 가능성이 있는 언어의 신뢰도 값을 가져오려면 FirebaseLanguageIdentification의 인스턴스를 가져온 후 문자열을 identifyAllLanguages() 메서드에 전달합니다.
예를 들면 다음과 같습니다.
FirebaseLanguageIdentificationlanguageIdentifier=FirebaseNaturalLanguage.getInstance().getLanguageIdentification();languageIdentifier.identifyAllLanguages(text).addOnSuccessListener(newOnSuccessListener<String>(){@OverridepublicvoidonSuccess(List<IdentifiedLanguage>identifiedLanguages){for(IdentifiedLanguageidentifiedLanguage:identifiedLanguages){Stringlanguage=identifiedLanguage.getLanguageCode();floatconfidence=identifiedLanguage.getConfidence();Log.i(TAG,language+" ("+confidence+")");}}}).addOnFailureListener(newOnFailureListener(){@OverridepublicvoidonFailure(@NonNullExceptione){// Model couldn’t be loaded or other internal error.// ...}});
호출이 성공하면 IdentifiedLanguage 객체 목록이 성공 리스너에 전달됩니다. 각 객체에서 언어의 BCP-47 코드와 문자열이 해당 언어에 있다는 신뢰도를 얻을 수 있습니다. 지원 언어의 전체 목록을 참조하세요. 이 값은 전체 문자열이 지정된 언어임을 나타냅니다. ML Kit는 단일 문자열에서 여러 언어를 식별하지 않습니다.
기본적으로 ML Kit는 신뢰도 값이 0.01 이상인 언어만 반환합니다. FirebaseLanguageIdentificationOptions 객체를 getLanguageIdentification()에 전달하여 이 기준을 변경할 수 있습니다.
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["필요한 정보가 없음","missingTheInformationINeed","thumb-down"],["너무 복잡함/단계 수가 너무 많음","tooComplicatedTooManySteps","thumb-down"],["오래됨","outOfDate","thumb-down"],["번역 문제","translationIssue","thumb-down"],["샘플/코드 문제","samplesCodeIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-09-04(UTC)"],[],[],null,["You can use ML Kit to identify the language of a string of text. You can\nget the string's most likely language or get confidence scores for all of the\nstring's possible languages.\n\nML Kit recognizes text in 103 different languages in their native scripts.\nIn addition, romanized text can be recognized for Arabic, Bulgarian, Chinese,\nGreek, Hindi, Japanese, and Russian.\n\n\u003cbr /\u003e\n\nBefore you begin\n\n1. If you haven't already, [add Firebase to your Android project](/docs/android/setup).\n2. Add the dependencies for the ML Kit Android libraries to your module (app-level) Gradle file (usually `app/build.gradle`): \n\n ```carbon\n apply plugin: 'com.android.application'\n apply plugin: 'com.google.gms.google-services'\n\n dependencies {\n // ...\n\n implementation 'com.google.firebase:firebase-ml-natural-language:22.0.0'\n implementation 'com.google.firebase:firebase-ml-natural-language-language-id-model:20.0.7'\n }\n ```\n\nIdentify the language of a string\n\nTo identify the language of a string, get an instance of\n`FirebaseLanguageIdentification`, and then pass the string to the\n`identifyLanguage()` method.\n\nFor example: \n\n FirebaseLanguageIdentification languageIdentifier =\n FirebaseNaturalLanguage.getInstance().getLanguageIdentification();\n languageIdentifier.identifyLanguage(text)\n .addOnSuccessListener(\n new OnSuccessListener\u003cString\u003e() {\n @Override\n public void onSuccess(@Nullable String languageCode) {\n if (languageCode != \"und\") {\n Log.i(TAG, \"Language: \" + languageCode);\n } else {\n Log.i(TAG, \"Can't identify language.\");\n }\n }\n })\n .addOnFailureListener(\n new OnFailureListener() {\n @Override\n public void onFailure(@NonNull Exception e) {\n // Model couldn't be loaded or other internal error.\n // ...\n }\n });\n\nIf the call succeeds, a\n[BCP-47 language code](//en.wikipedia.org/wiki/IETF_language_tag) is\npassed to the success listener, indicating the language of the text. See the\n[complete list of supported languages](/docs/ml-kit/langid-support). If no\nlanguage could be confidently detected, the code `und` (undetermined) is passed.\n\nBy default, ML Kit returns a value other than `und` only when it identifies\nthe language with a confidence value of at least 0.5. You can change this\nthreshold by passing a `FirebaseLanguageIdentificationOptions` object to\n`getLanguageIdentification()`: \n\n FirebaseLanguageIdentification languageIdentifier = FirebaseNaturalLanguage\n .getInstance()\n .getLanguageIdentification(\n new FirebaseLanguageIdentificationOptions.Builder()\n .setIdentifyLanguageConfidenceThreshold(0.34f)\n .build());\n\nGet the possible languages of a string\n\nTo get the confidence values of a string's most likely languages, get an\ninstance of `FirebaseLanguageIdentification`, and then pass the string to the\n`identifyAllLanguages()` method.\n\nFor example: \n\n FirebaseLanguageIdentification languageIdentifier =\n FirebaseNaturalLanguage.getInstance().getLanguageIdentification();\n languageIdentifier.identifyAllLanguages(text)\n .addOnSuccessListener(\n new OnSuccessListener\u003cString\u003e() {\n @Override\n public void onSuccess(List\u003cIdentifiedLanguage\u003e identifiedLanguages) {\n for (IdentifiedLanguage identifiedLanguage : identifiedLanguages) {\n String language = identifiedLanguage.getLanguageCode();\n float confidence = identifiedLanguage.getConfidence();\n Log.i(TAG, language + \" (\" + confidence + \")\");\n }\n }\n })\n .addOnFailureListener(\n new OnFailureListener() {\n @Override\n public void onFailure(@NonNull Exception e) {\n // Model couldn't be loaded or other internal error.\n // ...\n }\n });\n\nIf the call succeeds, a list of `IdentifiedLanguage` objects is passed to the\nsuccess listener. From each object, you can get the language's BCP-47 code and\nthe confidence that the string is in that language. See the\n[complete list of supported languages](/docs/ml-kit/langid-support). Note that\nthese values indicate the confidence that the entire string is in the given\nlanguage; ML Kit doesn't identify multiple languages in a single string.\n\nBy default, ML Kit returns only languages with confidence values of at least\n0.01. You can change this threshold by passing a\n`FirebaseLanguageIdentificationOptions` object to\n`getLanguageIdentification()`: \n\n FirebaseLanguageIdentification languageIdentifier = FirebaseNaturalLanguage\n .getInstance()\n .getLanguageIdentification(\n new FirebaseLanguageIdentificationOptions.Builder()\n .setIdentifyAllLanguagesConfidenceThreshold(0.5f)\n .build());\n\nIf no language meets this threshold, the list will have one item, with the value\n`und`."]]