{"id":13563004,"url":"https://github.com/darrynten/google-natural-language-php","last_synced_at":"2025-05-09T01:44:08.553Z","repository":{"id":52421958,"uuid":"81687310","full_name":"darrynten/google-natural-language-php","owner":"darrynten","description":"PHP Client for Google Natural Language with Extras","archived":false,"fork":false,"pushed_at":"2021-04-29T19:13:40.000Z","size":38,"stargazers_count":77,"open_issues_count":4,"forks_count":12,"subscribers_count":7,"default_branch":"dev","last_synced_at":"2025-03-31T20:46:17.286Z","etag":null,"topics":["ai","api-client","artificial-intelligence","client","google","google-cloud-platform","machine-learning","natural-language-processing","php"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/darrynten.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-02-11T22:38:46.000Z","updated_at":"2024-04-07T10:06:39.000Z","dependencies_parsed_at":"2022-08-21T05:40:27.548Z","dependency_job_id":null,"html_url":"https://github.com/darrynten/google-natural-language-php","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darrynten%2Fgoogle-natural-language-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darrynten%2Fgoogle-natural-language-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darrynten%2Fgoogle-natural-language-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/darrynten%2Fgoogle-natural-language-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/darrynten","download_url":"https://codeload.github.com/darrynten/google-natural-language-php/tar.gz/refs/heads/dev","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253176439,"owners_count":21866141,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","api-client","artificial-intelligence","client","google","google-cloud-platform","machine-learning","natural-language-processing","php"],"created_at":"2024-08-01T13:01:14.156Z","updated_at":"2025-05-09T01:44:08.531Z","avatar_url":"https://github.com/darrynten.png","language":"PHP","funding_links":[],"categories":["PHP"],"sub_categories":[],"readme":"## google-natural-language-php\n\n![Travis Build Status](https://travis-ci.org/darrynten/google-natural-language-php.svg?branch=master)\n![StyleCI Status](https://styleci.io/repos/81687310/shield?branch=master)\n[![codecov](https://codecov.io/gh/darrynten/google-natural-language-php/branch/master/graph/badge.svg)](https://codecov.io/gh/darrynten/google-natural-language-php)\n![Packagist Version](https://img.shields.io/packagist/v/darrynten/google-natural-language-php.svg)\n![MIT License](https://img.shields.io/github/license/darrynten/google-natural-language-php.svg)\n\nAn unofficial, fully unit tested Google Natural Language PHP client with \nextra sugar.\n\n## Why not just use the official one?\n\nThe official one is great, and we actually use it in this package, it\njust doesn't quite have the sort of features we needed, so we wrapped\nit up with some extra bits.\n\n## What extra features?\n\n### Cost Cutters\n\nThe Google Natural Language API costs money. If you're doing anything\nwith it at scale, you're going to have to keep an eye on your calls to\nmake sure things aren't running away with you. I learnt this the hard\nway. It can get expensive.\n\nThat's why we introduced some cost cutting features.\n\n#### Caching Requests\n\nBy default this package caches your requests, something you would have\nto usually do yourself.\n\nIt caches using a framework-agnostic approach, whereby it leverages any\nhost frameworks caching mechanism, and falls back to a temporary cache\nif there is no cache available.\n\nThe supported frameworks are detailed in the [AnyCache](https://github.com/darrynten/any-cache) project.\n\nExamples include Laravel, Symfony, Doctrine, Psr6 and more.\n\nThis feature is on by default and can easily be disabled.\n\n#### Cheapskate Mode\n\nWhile not immediately clear, the Google Natural Language API charges per 1000 characters.\n\nWe've added \"cheapskate mode\" that, if set, automatically truncates the \ndesired text, saving you another credit.\n\nThis feature is on by default and can easily be disabled.\n\n### Conveniences\n\nThere are a few other conveniences like being able to set the type,\nlanguage, encoding etc.\n\nOne use case would be running a single instance of text through\nmultiple language attempts.\n\n## Usage\n\n```php\nuse DarrynTen\\GoogleNaturalLanguagePhp\\GoogleNaturalLanguage;\n\n// Config options\n$config = [\n  'projectId' =\u003e 'my-awesome-project'  // At the very least\n];\n\n// Make a processor\n$language = new GoogleNaturalLanguage($config);\n\n// Set text\n$text = 'Google Natural Language processing is awesome!';\n$language-\u003esetText($text);\n\n// Get stuff\n$language-\u003egetEntities();\n$language-\u003egetSyntax();\n$language-\u003egetSentiment();\n\n// Get all stuff\n$language-\u003egetAll();\n\n// Set optional things\n$language-\u003esetType('HTML');\n$language-\u003esetLanguage('en');\n$language-\u003esetEncodingType('UTF16');\n\n// Extra features\n$language-\u003esetCaching(false);\n$language-\u003esetCheapskate(false);\n\n// Full config options\n$config = [\n  'projectId' =\u003e 'my-awesome-project',     // required\n  'authCache' =\u003e \\CacheItemPoolInterface,  // stores access tokens\n  'authCacheOptions' =\u003e $array,            // cache config\n  'authHttpHandler' =\u003e callable(),         // psr-7 auth handler\n  'httpHandler' =\u003e callable(),             // psr-7 rest handler\n  'keyFile' =\u003e $json,                      // content\n  'keyFilePath' =\u003e $string,                // path\n  'retries' =\u003e 3,                          // default is 3\n  'scopes' =\u003e $array,                      // app scopes\n  'cache' =\u003e $boolean,                     // cache\n  'cheapskate' =\u003e $boolean                 // limit text to 1000 chars\n];\n\n// authCache, authCacheOptions, authHttpHandler and httpHandler are not\n// currently implemented.\n```\n\nSee [The Google Cloud Docs](https://googlecloudplatform.github.io/google-cloud-php/#/docs/v0.20.2/naturallanguage/naturallanguageclient)\nfor more on these options and their usage.\n\n## Options\n\n* `setType($type)` - Either `PLAIN_TEXT` (default) or `HTML`\n* `setEncodingType($type)` - Either `UTF8` (default) `UTF16`, `UTF32` or `NONE`\n* `setLanguage($language)` - Either ISO (`en`, `es`) or BCP-47 (`en-ZA`, `en-GB`).\n\nIf no language is provided then it is autodetected from the text and\nis returned with the response.\n\n## Missing Features\n\nFeel free to open a PR!\n\nUsage of Google\\Cloud\\Storage\\StorageObject is presently not possible.\n\n* Custom `authCache` and `authCacheOptions`\n* Custom `httpHandler` and `authHttpHandler`\n\n## Entity Sentiment\n\nYou can retrieve the sentiment of some text\n\n```\n$instance = new GoogleNaturalLanguage($config);\n$instance-\u003esetText('A duck and a cat in a field at night');\n$sentiment = $instance-\u003egetEntitySentiment();\n```\n\n## Roadmap\n\n- [ ] - Get Entities of Type - Will allow the ability to retrieve, for\nexample, only the People, or only the Locations\n- [ ] - Sentiment shortcuts (is positive etc)\n- [ ] - Check for types, has location etc\n- [ ] - And more!\n\n## Acknowledgements\n\n* [Dmitry Semenov](https://github.com/mxnr) for being such a legend.\n* [Bradley Weston](https://github.com/bweston92) for coming out of nowhere.\n* [blaisedufrain](https://github.com/blaisedufrain) for the sentiment analysis.\n\n* Open a PR and put yourself here :)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdarrynten%2Fgoogle-natural-language-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdarrynten%2Fgoogle-natural-language-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdarrynten%2Fgoogle-natural-language-php/lists"}