crodas\TextRank\SummaryPageRank::getGraph PHP Method

getGraph() protected method

protected getGraph ( array $sentences )
$sentences array
    protected function getGraph(array $sentences)
    {
        $outlinks = array();
        $graph = array();
        $values = array();
        $index = [];
        foreach ($sentences as $id => $words) {
            foreach ($words as $word) {
                if (empty($index[$word])) {
                    $index[$word] = [];
                }
                $index[$word][] = $id;
            }
        }
        foreach ($index as $word => $ids) {
            $ids = array_unique($ids);
            if (count($ids) == 1) {
                continue;
            }
            foreach ($ids as $source) {
                foreach ($ids as $target) {
                    if ($source != $target) {
                        if (empty($outlinks[$source])) {
                            $outlinks[$source] = 0;
                        }
                        if (empty($graph[$target])) {
                            $graph[$target] = array();
                        }
                        $outlinks[$source]++;
                        $graph[$target][] = $source;
                        $values[$target] = 0.15;
                    }
                }
            }
        }
        return compact('graph', 'values', 'outlinks');
    }
SummaryPageRank