1. Go to this page and download the library: Download szyku/php-nltk-client 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/ */
szyku / php-nltk-client example snippets
use GuzzleHttp\Psr7\Uri;
use Szyku\NLTK\Client;
use GuzzleHttp\Client as Guzzle;
$uri = new Uri("http://localhost:5000");
$guzzle = new Guzzle(['base_uri' => $uri]);
// or just $guzzle = new Guzzle(['base_uri' => 'http://localhost:5000']);
$nltkClient = new Client($guzzle);
use Szyku\NLTK\Request\Dictionary\DefinitionLookupRequest;
use Szyku\NLTK\Request\Dictionary\SimilarLookupRequest;
use Szyku\NLTK\Request\Lemma\LemmatizationRequestBuilder as Builder;
use Szyku\NLTK\Request\Tagger\TaggingRequestBuilder as TaggerBuilder;
$similarWordsToCastle = SimilarLookupRequest::noun('castle');
$definitionsForRA = DefinitionLookupRequest::noun('rheumatoid arthritis');
$sentenceTagging = TaggerBuilder::create()
->add('He is a cunning man.')
->addMany(['Before and after.', 'Ups and downs'])
->build();
$lemmatizeSentence = Builder::create()
->adjective('biggest')
->noun('dogs')
->verb('fought')
->adverb('loudly')
->findAllFor('at')
->build();
// results are hydrated to objects like WordLookupResponse or LemmatizationResponse
$castleResult = $nltkClient->dictionary($similarWordsToCastle);
$raResult = $nltkClient->dictionary($definitionsForRA);
$lemmatizationResult = $nltkClient->lemmatization($lemmatizeSentence);
$taggingResult = $nltkClient->tagging($sentenceTagging);
// easy to consume
echo "Time taken in seconds: " . $castleResult->lookupTime();
echo "Searched for: " . $castleResult->queriedPhrase();
foreach ($castleResult->results() as $result) {
echo $result->phrase() . ": " . $result->definition();
}
// prints "palace: A large and stately mansion"