File tree Expand file tree Collapse file tree 3 files changed +24
-1
lines changed Expand file tree Collapse file tree 3 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,10 @@ A simple wrapper for PHP-NLP-Client and OpenCalais NLP tools.
3
3
4
4
## Installation
5
5
6
+ ```
7
+ $ composer require web64/laravel-nlp
8
+ ```
9
+
6
10
## Requirements
7
11
8
12
## Included Tools
@@ -18,13 +22,15 @@ A simple wrapper for PHP-NLP-Client and OpenCalais NLP tools.
18
22
### Language Detection
19
23
``` php
20
24
use Web64\LaravelNlp\Facades\NLP;
25
+
21
26
$lang = NLP::language("What language is this?");
22
27
// 'en'
23
28
```
24
29
25
30
### Article Extraction
26
31
``` php
27
32
use Web64\LaravelNlp\Facades\NLP;
33
+
28
34
$article = NLP::article("https://medium.com/@taylorotwell/wildcard-letsencrypt-certificates-on-forge-d3bdec43692a");
29
35
print_r($article);
30
36
/*
@@ -54,6 +60,7 @@ print_r($article);
54
60
For other Laravel NLP packages, check out:
55
61
- https://github.com/AntoineAugusti/laravel-sentiment-analysis
56
62
- https://github.com/michaeljhopkins/Laravel-Aylien-Wrapper
63
+ - https://github.com/findbrok/laravel-personality-insights
57
64
58
65
59
66
## Contribute
Original file line number Diff line number Diff line change 4
4
"type" : " library" ,
5
5
"require" : {
6
6
"web64/php-nlp-client" : " ^0.30" ,
7
- "lsmonki/php-open-calais" : " ^2.1"
7
+ "lsmonki/php-open-calais" : " ^2.1" ,
8
+ "stichoza/google-translate-php" : " ~3.2"
8
9
},
9
10
"license" : " MIT" ,
10
11
"authors" : [
Original file line number Diff line number Diff line change 2
2
3
3
namespace Web64 \LaravelNlp ;
4
4
5
+
6
+
5
7
class LaravelNlp extends \Web64 \Nlp \NlpClient
6
8
{
7
9
private $ opencalais_key ;
@@ -24,6 +26,19 @@ public function article( $url )
24
26
return $ this ->newspaperUrl ( $ url );
25
27
}
26
28
29
+ public function translate ($ text , $ source_lang = null , $ target_lang = null )
30
+ {
31
+ $ translator = new \Stichoza \GoogleTranslate \TranslateClient ;
32
+
33
+ if ( $ source_lang )
34
+ $ translator ->setSource ($ source_lang );
35
+
36
+ if ( $ target_lang )
37
+ $ translator ->setTarget ($ target_lang );
38
+
39
+ return $ translator ->translate ( $ text );
40
+ }
41
+
27
42
public function sentiment ( $ text , $ language = 'en ' )
28
43
{
29
44
$ response = $ this ->polyglot ($ text , $ language );
You can’t perform that action at this time.
0 commit comments