String lang = (String) (alllanguages.nextElement());
InputStream is = this.getClass().getResourceAsStream("_resources/" + lang + "." + NGramProfile.FILE_EXTENSION);
if (is != null) {
NGramProfile profile = new NGramProfile(lang, minLength, maxLength);
try {
profile.load(is);
languages.add(profile);
supportedLanguages.add(lang);
List<NGramEntry> ngrams = profile.getSorted();
for (int i=0; i<ngrams.size(); i++) {
NGramEntry entry = ngrams.get(i);
List<NGramEntry> registered = tmpIdx.get(entry);
if (registered == null) {
registered = new ArrayList<NGramEntry>();
tmpIdx.put(entry, registered);
}
registered.add(entry);
entry.setProfile(profile);
}
list.append(" " + lang + "(" + ngrams.size() + ")");
is.close();
} catch (IOException e1) {
log.error("", e1);
}
}
}
// transform all ngrams lists to arrays for performances
Iterator<NGramEntry> keys = tmpIdx.keySet().iterator();
while (keys.hasNext()) {
NGramEntry entry = keys.next();
List<NGramEntry> l = tmpIdx.get(entry);
if (l != null) {
NGramEntry[] array = l.toArray(new NGramEntry[l.size()]);
ngramsIdx.put(entry.getSeq(), array);
}
}
log.info(list.toString());
// Create the suspect profile
suspect = new NGramProfile("suspect", minLength, maxLength);
} catch (Exception e) {
log.error("", e);
}
}