Camspiers\StatisticalClassifier\Classifier\SVM::prepareDocument PHP Method

prepareDocument() protected method

Formats the document for use in \SVMModel
protected prepareDocument ( string $document, SVMModel $model ) : array
$document string
$model Camspiers\StatisticalClassifier\Model\SVMModel
return array
    protected function prepareDocument($document, SVMModel $model)
    {
        $tokenMap = $model->getTokenMap();
        $data = array();
        if ($this->documentNormalizer) {
            $document = $this->documentNormalizer->normalize($document);
        }
        $tokens = $this->tokenizer->tokenize($document);
        if ($this->tokenNormalizer) {
            $tokens = $this->tokenNormalizer->normalize($tokens);
        }
        $tokenCounts = array_count_values($tokens);
        foreach ($tokenCounts as $token => $value) {
            if (isset($tokenMap[$token])) {
                $data[$tokenMap[$token]] = $value;
            }
        }
        ksort($data, SORT_NUMERIC);
        return $data;
    }