PHPackages                             darrynten/google-natural-language-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. darrynten/google-natural-language-php

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

darrynten/google-natural-language-php
=====================================

PHP Google Natural Language Client with Extras

v1.0.6(8y ago)775.5k12[2 issues](https://github.com/darrynten/google-natural-language-php/issues)[2 PRs](https://github.com/darrynten/google-natural-language-php/pulls)PHPPHP ^5.5.9 || ^7.0

Since Feb 12Pushed 5y ago7 watchersCompare

[ Source](https://github.com/darrynten/google-natural-language-php)[ Packagist](https://packagist.org/packages/darrynten/google-natural-language-php)[ RSS](/packages/darrynten-google-natural-language-php/feed)WikiDiscussions dev Synced yesterday

READMEChangelog (7)Dependencies (5)Versions (11)Used By (0)

google-natural-language-php
---------------------------

[](#google-natural-language-php)

[![Travis Build Status](https://camo.githubusercontent.com/cfec8714804e745e65584a03d586986076e28d5b7ad33b0309b33376f7c7ec5f/68747470733a2f2f7472617669732d63692e6f72672f64617272796e74656e2f676f6f676c652d6e61747572616c2d6c616e67756167652d7068702e7376673f6272616e63683d6d6173746572)](https://camo.githubusercontent.com/cfec8714804e745e65584a03d586986076e28d5b7ad33b0309b33376f7c7ec5f/68747470733a2f2f7472617669732d63692e6f72672f64617272796e74656e2f676f6f676c652d6e61747572616c2d6c616e67756167652d7068702e7376673f6272616e63683d6d6173746572)[![StyleCI Status](https://camo.githubusercontent.com/c4eedd889a201c43b2387529eaca40eacd937bcae34f89ead190a1f9f68ff30f/68747470733a2f2f7374796c6563692e696f2f7265706f732f38313638373331302f736869656c643f6272616e63683d6d6173746572)](https://camo.githubusercontent.com/c4eedd889a201c43b2387529eaca40eacd937bcae34f89ead190a1f9f68ff30f/68747470733a2f2f7374796c6563692e696f2f7265706f732f38313638373331302f736869656c643f6272616e63683d6d6173746572)[![codecov](https://camo.githubusercontent.com/aeb37c3cd32f1f5811bfc43d6e2326bb1120f567c703e45362c4765b7c2a94b2/68747470733a2f2f636f6465636f762e696f2f67682f64617272796e74656e2f676f6f676c652d6e61747572616c2d6c616e67756167652d7068702f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/darrynten/google-natural-language-php)[![Packagist Version](https://camo.githubusercontent.com/c5df4f173e4a17a75bb07dd39cae85935b30d16613ca9d83f7d0ea75679c870f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f64617272796e74656e2f676f6f676c652d6e61747572616c2d6c616e67756167652d7068702e737667)](https://camo.githubusercontent.com/c5df4f173e4a17a75bb07dd39cae85935b30d16613ca9d83f7d0ea75679c870f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f64617272796e74656e2f676f6f676c652d6e61747572616c2d6c616e67756167652d7068702e737667)[![MIT License](https://camo.githubusercontent.com/8d552119c531d56bea0e7212b16ccadfa69331d183b0f1fc6045a71cb66f1d20/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f64617272796e74656e2f676f6f676c652d6e61747572616c2d6c616e67756167652d7068702e737667)](https://camo.githubusercontent.com/8d552119c531d56bea0e7212b16ccadfa69331d183b0f1fc6045a71cb66f1d20/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f64617272796e74656e2f676f6f676c652d6e61747572616c2d6c616e67756167652d7068702e737667)

An unofficial, fully unit tested Google Natural Language PHP client with extra sugar.

Why not just use the official one?
----------------------------------

[](#why-not-just-use-the-official-one)

The official one is great, and we actually use it in this package, it just doesn't quite have the sort of features we needed, so we wrapped it up with some extra bits.

What extra features?
--------------------

[](#what-extra-features)

### Cost Cutters

[](#cost-cutters)

The Google Natural Language API costs money. If you're doing anything with it at scale, you're going to have to keep an eye on your calls to make sure things aren't running away with you. I learnt this the hard way. It can get expensive.

That's why we introduced some cost cutting features.

#### Caching Requests

[](#caching-requests)

By default this package caches your requests, something you would have to usually do yourself.

It caches using a framework-agnostic approach, whereby it leverages any host frameworks caching mechanism, and falls back to a temporary cache if there is no cache available.

The supported frameworks are detailed in the [AnyCache](https://github.com/darrynten/any-cache) project.

Examples include Laravel, Symfony, Doctrine, Psr6 and more.

This feature is on by default and can easily be disabled.

#### Cheapskate Mode

[](#cheapskate-mode)

While not immediately clear, the Google Natural Language API charges per 1000 characters.

We've added "cheapskate mode" that, if set, automatically truncates the desired text, saving you another credit.

This feature is on by default and can easily be disabled.

### Conveniences

[](#conveniences)

There are a few other conveniences like being able to set the type, language, encoding etc.

One use case would be running a single instance of text through multiple language attempts.

Usage
-----

[](#usage)

```
use DarrynTen\GoogleNaturalLanguagePhp\GoogleNaturalLanguage;

// Config options
$config = [
  'projectId' => 'my-awesome-project'  // At the very least
];

// Make a processor
$language = new GoogleNaturalLanguage($config);

// Set text
$text = 'Google Natural Language processing is awesome!';
$language->setText($text);

// Get stuff
$language->getEntities();
$language->getSyntax();
$language->getSentiment();

// Get all stuff
$language->getAll();

// Set optional things
$language->setType('HTML');
$language->setLanguage('en');
$language->setEncodingType('UTF16');

// Extra features
$language->setCaching(false);
$language->setCheapskate(false);

// Full config options
$config = [
  'projectId' => 'my-awesome-project',     // required
  'authCache' => \CacheItemPoolInterface,  // stores access tokens
  'authCacheOptions' => $array,            // cache config
  'authHttpHandler' => callable(),         // psr-7 auth handler
  'httpHandler' => callable(),             // psr-7 rest handler
  'keyFile' => $json,                      // content
  'keyFilePath' => $string,                // path
  'retries' => 3,                          // default is 3
  'scopes' => $array,                      // app scopes
  'cache' => $boolean,                     // cache
  'cheapskate' => $boolean                 // limit text to 1000 chars
];

// authCache, authCacheOptions, authHttpHandler and httpHandler are not
// currently implemented.
```

See [The Google Cloud Docs](https://googlecloudplatform.github.io/google-cloud-php/#/docs/v0.20.2/naturallanguage/naturallanguageclient)for more on these options and their usage.

Options
-------

[](#options)

- `setType($type)` - Either `PLAIN_TEXT` (default) or `HTML`
- `setEncodingType($type)` - Either `UTF8` (default) `UTF16`, `UTF32` or `NONE`
- `setLanguage($language)` - Either ISO (`en`, `es`) or BCP-47 (`en-ZA`, `en-GB`).

If no language is provided then it is autodetected from the text and is returned with the response.

Missing Features
----------------

[](#missing-features)

Feel free to open a PR!

Usage of Google\\Cloud\\Storage\\StorageObject is presently not possible.

- Custom `authCache` and `authCacheOptions`
- Custom `httpHandler` and `authHttpHandler`

Entity Sentiment
----------------

[](#entity-sentiment)

You can retrieve the sentiment of some text

```
$instance = new GoogleNaturalLanguage($config);
$instance->setText('A duck and a cat in a field at night');
$sentiment = $instance->getEntitySentiment();

```

Roadmap
-------

[](#roadmap)

- - Get Entities of Type - Will allow the ability to retrieve, for example, only the People, or only the Locations
- - Sentiment shortcuts (is positive etc)
- - Check for types, has location etc
- - And more!

Acknowledgements
----------------

[](#acknowledgements)

- [Dmitry Semenov](https://github.com/mxnr) for being such a legend.
- [Bradley Weston](https://github.com/bweston92) for coming out of nowhere.
- [blaisedufrain](https://github.com/blaisedufrain) for the sentiment analysis.
- Open a PR and put yourself here :)

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity33

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 90.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~79 days

Recently: every ~119 days

Total

7

Last Release

2948d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/3657251?v=4)[Darryn Ten](/maintainers/darrynten)[@darrynten](https://github.com/darrynten)

---

Top Contributors

[![darrynten](https://avatars.githubusercontent.com/u/3657251?v=4)](https://github.com/darrynten "darrynten (40 commits)")[![mxnr](https://avatars.githubusercontent.com/u/1383089?v=4)](https://github.com/mxnr "mxnr (3 commits)")[![joaojoyce](https://avatars.githubusercontent.com/u/5451182?v=4)](https://github.com/joaojoyce "joaojoyce (1 commits)")

---

Tags

aiapi-clientartificial-intelligenceclientgooglegoogle-cloud-platformmachine-learningnatural-language-processingphp

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/darrynten-google-natural-language-php/health.svg)

```
[![Health](https://phpackages.com/badges/darrynten-google-natural-language-php/health.svg)](https://phpackages.com/packages/darrynten-google-natural-language-php)
```

###  Alternatives

[neuron-core/neuron-ai

The PHP Agentic Framework.

2.0k496.1k34](/packages/neuron-core-neuron-ai)[tencentcloud/tencentcloud-sdk-php

TencentCloudApi php sdk

3661.2M46](/packages/tencentcloud-tencentcloud-sdk-php)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

751284.3k37](/packages/civicrm-civicrm-core)[roundcube/roundcubemail

The Roundcube Webmail suite

7.0k1.4k3](/packages/roundcube-roundcubemail)[spatie/laravel-export

Create a static site bundle from a Laravel app

672139.5k6](/packages/spatie-laravel-export)[nfse-nacional/nfse-php

This is my package nfse

1533.1k](/packages/nfse-nacional-nfse-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
