PHP code example of yooper / php-text-analysis

1. Go to this page and download the library: Download yooper/php-text-analysis library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

yooper / php-text-analysis example snippets


$tokens = tokenize($text);

$tokens = tokenize($text, \TextAnalysis\Tokenizers\PennTreeBankTokenizer::class);

$normalizedTokens = normalize_tokens(array $tokens); 

$normalizedTokens = normalize_tokens(array $tokens, 'mb_strtolower');

$normalizedTokens = normalize_tokens(array $tokens, function($token){ return mb_strtoupper($token); });

$freqDist = freq_dist(tokenize($text));

$bigrams = ngrams($tokens);

// create trigrams with a pipe delimiter in between each word
$trigrams = ngrams($tokens,3, '|');

$stemmedTokens = stem($tokens);

$stemmedTokens = stem($tokens, \TextAnalysis\Stemmers\MorphStemmer::class);

$rake = rake($tokens, 3);
$results = $rake->getKeywordScores();

$sentimentScores = vader($tokens);

$nb = naive_bayes();
$nb->train('mexican', tokenize('taco nacho enchilada burrito'));        
$nb->train('american', tokenize('hamburger burger fries pop'));  
$nb->predict(tokenize('my favorite food is a burrito'));