public function save(AbstractFormat $output)
{
if (empty($this->samples)) {
throw new \Exception("You need to provide samples");
}
$sort = $this->config->getSortObject();
$max = $this->config->maxNGram();
$parser = $this->config->getParser();
$callback = $this->callback;
foreach ($this->samples as $lang => $texts) {
if (!empty($this->output[$lang])) {
continue;
}
if ($callback) {
$callback($lang, 'start');
}
$text = implode("\n", $texts);
$pos = 0;
$data = array();
$sorted = $sort->sort($parser->get($text));
foreach (array_splice($sorted, 0, $max) as $ngram => $score) {
$data[$ngram] = array('pos' => $pos++, 'score' => $score);
}
$this->output[$lang] = $data;
if ($callback) {
$callback($lang, 'end');
}
}
$output->dump(array('config' => $this->config, 'data' => $this->output));
}