/** * @throws LangDetectException * */ private void detectBlock() throws LangDetectException { cleaningText(); ArrayList<String> ngrams = extractNGrams(); if (ngrams.size()==0) throw new LangDetectException(ErrorCode.CantDetectError, "no features in text"); langprob = new double[langlist.size()]; Random rand = new Random(); if (seed != null) rand.setSeed(seed); for (int t = 0; t < n_trial; ++t) { double[] prob = initProbability(); double alpha = this.alpha + rand.nextGaussian() * ALPHA_WIDTH; for (int i = 0;; ++i) { int r = rand.nextInt(ngrams.size()); updateLangProb(prob, ngrams.get(r), alpha); if (i % 5 == 0) { if (normalizeProb(prob) > CONV_THRESHOLD || i>=ITERATION_LIMIT) break; if (verbose) System.out.println("> " + sortProbability(prob)); } } for(int j=0;j<langprob.length;++j) langprob[j] += prob[j] / n_trial; if (verbose) System.out.println("==> " + sortProbability(prob)); } }