https://github.com/cable8mm/sentence-to-keywords

네이버 검색 엔진을 이용해서 검색어나 문장에서 키워드를 추출하고 오타를 교정

개인 프로젝트에서 검색 관련이나 오타 수정이 필요한 경우에 유용할 것으로 보임

public function __construct(string $sentence)
{
    $encodedSentence = urlencode($sentence);
    $realUrl = str_replace('{ENCODED_KEYWORD}', $encodedSentence, $this->fetchUrl);
    $this->html = file_get_contents($realUrl);
    $this->rank();
}
private function rank()
{
    $matches = [];
    preg_match_all('/<mark>([^<]+)<\\/mark>/', $this->html, $matches);
    $countMatches = array_count_values($matches[1]);
    arsort($countMatches);

    $google_replace_string = '';
    $google_match_count = '';
    foreach ($countMatches as $k => $countMatch) {
        if (preg_match('/^[0-9\\.]+$/', $k) || $countMatch < self::THRESHOLD) {
            continue;
        }
        $this->result[] = $k;
        $google_replace_string .= $k.'||';
        $google_match_count .= $countMatch.'||';
    }

    $this->replaceStrings = preg_replace('/\\|\\|$/', '', $google_replace_string);
    $this->matchCount = preg_replace('/\\|\\|$/', '', $google_match_count);
}