/** * @throws IllegalStateException if no LanguageProfile was {@link #withProfile added}. */ public LanguageDetector build() throws IllegalStateException { if (languageProfiles.isEmpty()) throw new IllegalStateException(); return new LanguageDetectorImpl( NgramFrequencyData.create(languageProfiles, ngramExtractor.getGramLengths()), alpha, seed, shortTextAlgorithm, prefixFactor, suffixFactor, probabilityThreshold, minimalConfidence, langWeightingMap, ngramExtractor ); }
/** * @throws IllegalStateException if no LanguageProfile was {@link #withProfile added}. */ public LanguageDetector build() throws IllegalStateException { if (languageProfiles.isEmpty()) throw new IllegalStateException(); return new LanguageDetectorImpl( NgramFrequencyData.create(languageProfiles, ngramExtractor.getGramLengths()), alpha, seed, shortTextAlgorithm, prefixFactor, suffixFactor, probabilityThreshold, minimalConfidence, langWeightingMap, ngramExtractor ); }
/** * @throws IllegalStateException if a profile for the same language was added already (must be a userland bug). */ public LanguageDetectorBuilder withProfile(LanguageProfile languageProfile) throws IllegalStateException { if (langsAdded.contains(languageProfile.getLocale())) { throw new IllegalStateException("A language profile for language "+languageProfile.getLocale()+" was added already!"); } for (Integer gramLength : ngramExtractor.getGramLengths()) { if (!languageProfile.getGramLengths().contains(gramLength)) { throw new IllegalArgumentException("The NgramExtractor is set to handle "+gramLength+"-grams but the given language profile for "+languageProfile.getLocale()+" does not support this!"); } } langsAdded.add(languageProfile.getLocale()); languageProfiles.add(languageProfile); return this; } /**
/** * @throws IllegalStateException if a profile for the same language was added already (must be a userland bug). */ public LanguageDetectorBuilder withProfile(LanguageProfile languageProfile) throws IllegalStateException { if (langsAdded.contains(languageProfile.getLocale())) { throw new IllegalStateException("A language profile for language "+languageProfile.getLocale()+" was added already!"); } for (Integer gramLength : ngramExtractor.getGramLengths()) { if (!languageProfile.getGramLengths().contains(gramLength)) { throw new IllegalArgumentException("The NgramExtractor is set to handle "+gramLength+"-grams but the given language profile for "+languageProfile.getLocale()+" does not support this!"); } } langsAdded.add(languageProfile.getLocale()); languageProfiles.add(languageProfile); return this; } /**