LanguageDetector\Sort\PageRank::getGraph PHP Method

getGraph() protected method

}}}
protected getGraph ( array $ngrams )
$ngrams array
    protected function getGraph(array $ngrams)
    {
        $outlinks = array();
        $graph = array();
        $values = array();
        $total = count($ngrams);
        for ($i = 0; $i < $total; $i++) {
            if (ctype_punct($ngrams[$i])) {
                continue;
            }
            for ($e = $i; $e < $total && $e <= $i + 5; $e++) {
                if ($i > $total || $e > $total) {
                    continue;
                }
                if ($ngrams[$e] == $ngrams[$i]) {
                    continue;
                }
                if (ctype_punct($ngrams[$e])) {
                    break;
                }
                foreach (array($i, $e) as $id) {
                    if (empty($outlinks[$ngrams[$id]])) {
                        $outlinks[$ngrams[$id]] = 0;
                    }
                    if (empty($graph[$ngrams[$id]])) {
                        $graph[$ngrams[$id]] = array();
                    }
                    $outlinks[$ngrams[$id]]++;
                    /* increment outlink counter */
                    $values[$ngrams[$id]] = 0.15;
                    /* initial value */
                }
                $graph[$ngrams[$e]][] = $ngrams[$i];
                $graph[$ngrams[$i]][] = $ngrams[$e];
            }
        }
        return compact('graph', 'values', 'outlinks');
    }