/** * In order to use this you must set the {@link #ngramExtractor} first. */ public LanguageProfileBuilder addText(CharSequence text) { if (ngramExtractor==null) { throw new IllegalStateException("NgramExtractor has not been set yet!"); } for (Map.Entry<String, Integer> entry : ngramExtractor.extractCountedGrams(text).entrySet()) { addGram(entry.getKey(), entry.getValue()); } return this; }
/** * In order to use this you must set the {@link #ngramExtractor} first. */ public LanguageProfileBuilder addText(CharSequence text) { if (ngramExtractor==null) { throw new IllegalStateException("NgramExtractor has not been set yet!"); } for (Map.Entry<String, Integer> entry : ngramExtractor.extractCountedGrams(text).entrySet()) { addGram(entry.getKey(), entry.getValue()); } return this; }
/** * @return null if there are no "features" in the text (just noise). */ @Nullable private double[] detectBlock(CharSequence text) { if (text.length() <= shortTextAlgorithm) { Map<String, Integer> ngrams = ngramExtractor.extractCountedGrams(text); if (ngrams.isEmpty()) return null; return detectBlockShortText(ngrams); } else { List<String> strings = ngramExtractor.extractGrams(text); if (strings.isEmpty()) return null; return detectBlockLongText(strings); } }
/** * @return null if there are no "features" in the text (just noise). */ @Nullable private double[] detectBlock(CharSequence text) { if (text.length() <= shortTextAlgorithm) { Map<String, Integer> ngrams = ngramExtractor.extractCountedGrams(text); if (ngrams.isEmpty()) return null; return detectBlockShortText(ngrams); } else { List<String> strings = ngramExtractor.extractGrams(text); if (strings.isEmpty()) return null; return detectBlockLongText(strings); } }