protected function countTrainingSet(FeatureFactoryInterface $ff, TrainingSet $tset, array &$termcount_per_class, array &$termcount, array &$ndocs_per_class, array &$voc, &$ndocs)
    {
        foreach ($tset as $tdoc) {
            $ndocs++;
            $c = $tdoc->getClass();
            $ndocs_per_class[$c]++;
            $features = $ff->getFeatureArray($c,$tdoc);
            if (is_int(key($features)))
                $features = array_count_values($features);
            foreach ($features as $f=>$fcnt) {
                if (!isset($voc[$f]))
                    $voc[$f] = 0;

                $termcount_per_class[$c]+=$fcnt;
                if (isset($termcount[$c][$f]))
                    $termcount[$c][$f]+=$fcnt;
                else
                    $termcount[$c][$f] = $fcnt;
            }
        }
    }