Skip to content

Commit bf59650

Browse files
committed
google translate update
1 parent 2fc3e66 commit bf59650

File tree

2 files changed

+52
-27
lines changed

2 files changed

+52
-27
lines changed

README.md

+51-26
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,39 @@
66

77
A simple wrapper for the [PHP-NLP-Client](https://github.com/web64/php-nlp-client) library for accessing Python and Java NLP libraries and external NLP APIs.
88

9-
109
## Installation
10+
1111
```bash
1212
$ composer require web64/laravel-nlp
13-
14-
# Install nlp.php config file
15-
$ php artisan vendor:publish --provider="Web64\LaravelNlp\NlpServiceProvider"
1613
```
1714

1815
Plese follow the instructions here to install the NLP Server and CoreNLP server:
19-
* https://github.com/web64/nlpserver
20-
* https://github.com/web64/php-nlp-client
2116

22-
If you want to use Opencalais, get a token by registering [here](http://www.opencalais.com/) and read their [terms of service](http://www.opencalais.com/open-calais-terms-of-service/)
17+
- https://github.com/web64/nlpserver
18+
- https://github.com/web64/php-nlp-client
19+
20+
If you want to use Opencalais, get a token by registering [here](http://www.opencalais.com/) and read their [terms of service](http://www.opencalais.com/open-calais-terms-of-service/)
2321

2422
## Configuration
23+
2524
Add `NLPSERVER_URL` to your `.env` file to specify the location of where the NLP Server is running.
2625
If you want to use [CoreNLP](https://stanfordnlp.github.io/CoreNLP/download.html) or [Opencalais](http://www.opencalais.com/) also fill inn those details in .env.
2726

28-
Alternatively, update the nlp.php configuration file.
2927
```
3028
NLPSERVER_URL="http://localhost:6400/"
3129
CORENLP_HOST="http://localhost:9000/"
3230
OPENCALAIS_KEY=
3331
```
3432

33+
Alternatively, update the nlp.php configuration file.
34+
35+
```bash
36+
# Publish nlp.php config file
37+
$ php artisan vendor:publish --provider="Web64\LaravelNlp\NlpServiceProvider"
38+
```
39+
3540
## Quick Start
41+
3642
```php
3743
use Web64\LaravelNlp\Facades\NLP;
3844

@@ -53,32 +59,38 @@ $translated_text = NLP::translate($text, null, 'pt');
5359
```
5460

5561
## NLP Server
62+
5663
This package requires a running instance of the NLP Server (https://github.com/web64/nlpserver) for most of the functionality to work.
5764
See the documentation for installation instructions of the NLP Server.
5865

5966
## Included NLP Tools
60-
* [Language Detection](#language-detection)
61-
* [Article Extraction](#article-extraction)
62-
* [Entity Extraction (Named Entity Recognition)](#entity-extraction-with-polyglot)
63-
* [Sentiment Analysis](#sentiment-analysis)
64-
* [Summarization](#summarization)
65-
* [Translation](#translation)
66-
* [Neighbouring Words](#neighbouring-words)
67-
* [Concepts](#concepts)
67+
68+
- [Language Detection](#language-detection)
69+
- [Article Extraction](#article-extraction)
70+
- [Entity Extraction (Named Entity Recognition)](#entity-extraction-with-polyglot)
71+
- [Sentiment Analysis](#sentiment-analysis)
72+
- [Summarization](#summarization)
73+
- [Translation](#translation)
74+
- [Neighbouring Words](#neighbouring-words)
75+
- [Concepts](#concepts)
6876

6977
## Usage
78+
7079
Include the class to use the NLP facade.
80+
7181
```php
7282
use Web64\LaravelNlp\Facades\NLP;
7383
```
7484

7585
### Language Detection
86+
7687
```php
7788
$lang = NLP::language("What language is this?");
7889
// 'en'
7990
```
8091

8192
### Article Extraction
93+
8294
```php
8395
$article = NLP::article("https://medium.com/@taylorotwell/wildcard-letsencrypt-certificates-on-forge-d3bdec43692a");
8496
dump($article);
@@ -98,10 +110,12 @@ dump($article);
98110
```
99111

100112
### Entity Extraction with Polyglot
113+
101114
This function uses the [Polyglot](https://polyglot.readthedocs.io/en/latest/Installation.html) library which supports entity extraction for 40 languages.
102115
Make sure you have downloaded the language models for the languages you are using.
103116

104117
For English and other major European languages use [Spacy](https://spacy.io/usage/) or [CoreNLP](https://stanfordnlp.github.io/CoreNLP/download.html) for best results.
118+
105119
```php
106120
$text = "Barack Hussein Obama is an American politician who served as the 44th President of the United States from January 20, 2009 to January 20, 2017. Before that, he served in the Illinois State Senate from 1997 until 2004.";
107121

@@ -118,9 +132,11 @@ Array
118132
```
119133

120134
## Entity Extraction with Spacy
135+
121136
A running NLP Server provides access to Spacy's entity extraction.
122137

123138
Spacy has language models for English, German, Spanish, Portuguese, French, Italian and Dutch.
139+
124140
```php
125141
$entities = NLP::spacy_entities($text, 'en' );
126142
/*
@@ -145,6 +161,7 @@ array:4 [
145161
```
146162

147163
### Entitiy extraction with CoreNLP
164+
148165
[CoreNLP](https://github.com/web64/php-nlp-client#corenlp---entity-extraction-ner) provides very good entoty extraction for English texts.
149166

150167
To use this function you need a running instance of the CoreNLP server. [See installation inststructions](https://github.com/web64/php-nlp-client#corenlp---entity-extraction-ner)
@@ -179,8 +196,8 @@ array:6 [
179196
```
180197

181198
### Sentiment Analysis
182-
This will return a value ranging from -1 to +1, where > 0 is considered to have a positive sentiment and everython < 0 has a negative sentiment.
183199

200+
This will return a value ranging from -1 to +1, where > 0 is considered to have a positive sentiment and everython < 0 has a negative sentiment.
184201

185202
Provide the language code as the second parameter to specify the language of the text. (default='en').
186203

@@ -191,15 +208,20 @@ $sentiment = NLP::sentiment( "This is great!" );
191208
$sentiment = NLP::sentiment( "I hate this product", 'en' );
192209
// -1
193210
```
211+
194212
### Summarization
213+
195214
This will take a long text and return a summary of what is considered to be the most important sentences.
196215
An optional max. number of words can be speficied.
216+
197217
```php
198218
$summary = NLP::summarize($long_text);
199219
$summary = NLP::summarize($long_text, $max_word_count) ;
200220

201221
```
222+
202223
### Translation
224+
203225
Second parameter is the source language. Language will be automatically detected if left as NULL
204226

205227
```php
@@ -210,7 +232,9 @@ $translated_text = NLP::translate("Mange er opprørt etter avsløringene om at p
210232
```
211233

212234
### Neighbouring Words
235+
213236
This uses word embeddings to find related words from the one given.
237+
214238
```php
215239
$words = NLP::neighbours( 'president');
216240
dump( $words );
@@ -220,8 +244,8 @@ array:10 [
220244
1 => "vice-president"
221245
2 => "President"
222246
3 => "Chairman"
223-
4 => "Vice-President"
224-
]
247+
4 => "Vice-President"
248+
]
225249
*/
226250

227251
// ensure polyglot language model is installed: polyglot download LANG:no
@@ -238,9 +262,11 @@ array:10 [
238262
```
239263

240264
### Concepts
265+
241266
This uses Microsoft Concept Graph For Short Text Understanding: https://concept.research.microsoft.com/
242267

243268
An array of related concepts will be returned.
269+
244270
```php
245271
$concepts = NLP::concepts( 'php' );
246272

@@ -254,19 +280,18 @@ array:10 [
254280
"server side language" => 0.044201768070723
255281
"web technology" => 0.031201248049922
256282
"server-side language" => 0.027561102444098
257-
]
283+
]
258284
*/
259285
```
260286

261-
262-
263287
## More
264288

265289
For other Laravel NLP packages, check out:
266-
- https://github.com/AntoineAugusti/laravel-sentiment-analysis
267-
- https://github.com/michaeljhopkins/Laravel-Aylien-Wrapper
268-
- https://github.com/findbrok/laravel-personality-insights
269290

291+
- https://github.com/AntoineAugusti/laravel-sentiment-analysis
292+
- https://github.com/michaeljhopkins/Laravel-Aylien-Wrapper
293+
- https://github.com/findbrok/laravel-personality-insights
270294

271295
## Contribute
272-
Get in touch if you have any feedback or ideas on how to improve this package or the documentation.
296+
297+
Get in touch if you have any feedback or ideas on how to improve this package or the documentation.

src/LaravelNlp/LaravelNlp.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function article( $url )
3131

3232
public function translate($text, $source_lang = null, $target_lang = null)
3333
{
34-
$translator = new \Stichoza\GoogleTranslate\TranslateClient;
34+
$translator = new \Stichoza\GoogleTranslate\GoogleTranslate;
3535

3636
if ( $source_lang )
3737
$translator->setSource($source_lang);

0 commit comments

Comments
 (0)