All Projects → darrynten → google-natural-language-php

darrynten / google-natural-language-php

Licence: MIT license
PHP Client for Google Natural Language with Extras

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to google-natural-language-php

Awesome Podcasts
🎙 A collection of awesome engineering podcasts! ARCHIVED in favor of https://github.com/rShetty/awesome-podcasts
Stars: ✭ 184 (+142.11%)
Mutual labels:  google-cloud-platform
kube-cloud-build
Specify container builds inside your Kubernetes manifests.
Stars: ✭ 26 (-65.79%)
Mutual labels:  google-cloud-platform
spannerz
Google Cloud Spanner Query Planner Visualizer
Stars: ✭ 60 (-21.05%)
Mutual labels:  google-cloud-platform
Goth
Elixir package for Oauth authentication via Google Cloud APIs
Stars: ✭ 191 (+151.32%)
Mutual labels:  google-cloud-platform
Flysystem Google Cloud Storage
Flysystem Adapter for Google Cloud Storage
Stars: ✭ 237 (+211.84%)
Mutual labels:  google-cloud-platform
auth
A GitHub Action for authenticating to Google Cloud.
Stars: ✭ 567 (+646.05%)
Mutual labels:  google-cloud-platform
Kubernetes Series
kubernetes series code
Stars: ✭ 158 (+107.89%)
Mutual labels:  google-cloud-platform
cloudenvoy
Cross-application messaging for Ruby and Rails using Google Cloud Pub/Sub
Stars: ✭ 31 (-59.21%)
Mutual labels:  google-cloud-platform
GCP
All files containing commands which can be used to complete GCP quests and challenge labs
Stars: ✭ 46 (-39.47%)
Mutual labels:  google-cloud-platform
dialogflow ros
A ROS wrapper for Google's NLP platform Dialogflow
Stars: ✭ 17 (-77.63%)
Mutual labels:  google-cloud-platform
Sc17
SuperComputing 2017 Deep Learning Tutorial
Stars: ✭ 211 (+177.63%)
Mutual labels:  google-cloud-platform
Google Cloud Cpp
C++ Client Libraries for Google Cloud Services
Stars: ✭ 233 (+206.58%)
Mutual labels:  google-cloud-platform
angular-scaffolding
🔥 A seed project to help us get up & running with Progressive Web Apps, Google Analytics, Angular Universal, and be able to deploy to App Engine & GitHub Pages
Stars: ✭ 12 (-84.21%)
Mutual labels:  google-cloud-platform
Bigquery Grafana
Google BigQuery Datasource Plugin for Grafana.
Stars: ✭ 188 (+147.37%)
Mutual labels:  google-cloud-platform
deploy-appengine
A GitHub Action that deploys source code to Google App Engine.
Stars: ✭ 184 (+142.11%)
Mutual labels:  google-cloud-platform
Googlecloudarchitectprofessional
Resources to prepare for Google Certified Cloud Architect Professional Exam - 2017
Stars: ✭ 177 (+132.89%)
Mutual labels:  google-cloud-platform
cloudtasker
Background jobs for Ruby using Google Cloud Tasks
Stars: ✭ 122 (+60.53%)
Mutual labels:  google-cloud-platform
cloud-speech-and-vision-demos
A set of demo applications that make use of google speech, nlp and vision apis based in angular2
Stars: ✭ 35 (-53.95%)
Mutual labels:  google-cloud-platform
gcp auth
Minimal authentication library for Google Cloud Platform (GCP)
Stars: ✭ 42 (-44.74%)
Mutual labels:  google-cloud-platform
era5 in gee
Functions and Python scripts to ingest ERA5 data into Google Earth Engine
Stars: ✭ 63 (-17.11%)
Mutual labels:  google-cloud-platform

google-natural-language-php

Travis Build Status StyleCI Status codecov Packagist Version MIT License

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

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?

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

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 project.

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

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

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

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

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 for more on these options and their usage.

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

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

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

  • - 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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].