Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 687a0d1

Browse files
committed
re-config
1 parent 2d84676 commit 687a0d1

File tree

9 files changed

+19
-20
lines changed

9 files changed

+19
-20
lines changed

‎examples/embeddings.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
'debug' => true,
1111
];
1212

13-
$nlp = new \Web64\Nlp\NlpClient( $nlpserver_config );
13+
$nlp = new \Web64\Nlp\NlpClient( $nlpserver_config['hosts'], $nlpserver_config['debug'] );
1414

1515
$neighbours = $nlp->embeddings('obama', 'no');
1616

‎examples/language_detection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
'debug' => false,
1111
];
1212

13-
$nlp = new \Web64\Nlp\NlpClient( $nlpserver_config );
13+
$nlp = new \Web64\Nlp\NlpClient( $nlpserver_config['hosts'], $nlpserver_config['debug'] );
1414

1515
$texts = [
1616
'en' => "The quick brown fox jumps over the lazy dog",

‎examples/newspaper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
'debug' => true,
1111
];
1212

13-
$nlp = new \Web64\Nlp\NlpClient( $nlpserver_config );
13+
$nlp = new \Web64\Nlp\NlpClient( $nlpserver_config['hosts'], $nlpserver_config['debug'] );
1414

1515
$newspaper = $nlp->newspaperUrl('http://www.bbc.com/news/science-environment-43710766');
1616

‎examples/polyglot.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
'debug' => false,
1010
];
1111

12-
$nlp = new \Web64\Nlp\NlpClient( $nlpserver_config );
12+
$nlp = new \Web64\Nlp\NlpClient( $nlpserver_config['hosts'], $nlpserver_config['debug'] );
1313

1414

1515
$text = "Den har en tykk, sukkulent stamme som blir 1,5–8 m høy. Stammen er bare forgrenet i toppen på eldre planter. Stammen og eventuelle greiner er dekket av lange torner, som er omdannede akselblad. I toppen av planten sitter en rosett med avlange blad. Bladene er olivengrønne på oversiden og lyse under. Etterhvert som planten vokser, faller bladene av nedover stammen, men tornene står parvis igjen i de gamle bladfestene. Blomstene er femtallige og hvite. Arten vokser i torneskogene på sørlige og sørvestlige Madagaskar opptil 750 moh.

‎src/NlpClient.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@ class NlpClient{
1414
public $debug = false;
1515
private $max_retry_count = 3;
1616

17-
function __construct( $config )
17+
function __construct( $hosts, $debug = false )
1818
{
19-
if ( is_array($config['hosts']) )
19+
$this->debug = (bool)$debug;
20+
21+
if ( is_array($hosts) )
2022
{
21-
foreach( $config['hosts'] as $host )
23+
foreach( $hosts as $host )
2224
$this->addHost( $host );
2325
}
2426
else
25-
$this->addHost( $config['hosts'] );
27+
$this->addHost( $hosts );
2628

27-
if ( isset($config['debug']) && $config['debug'] )
28-
$this->debug = true;
2929

3030
// pick random host as default
3131
$this->api_url = $this->api_hosts[

‎tests/Unit/EmbeddingsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class EmbeddingsTest extends TestCase
99
/** @test */
1010
public function get_neighbours()
1111
{
12-
$nlp = new \Web64\Nlp\NlpClient( $this->nlpserver_config );
12+
$nlp = new \Web64\Nlp\NlpClient( $this->nlpserver_config['hosts'], $this->nlpserver_config['debug'] );
1313

1414
$neighbours = $nlp->embeddings('obama', 'no');
1515

‎tests/Unit/LanguageDetectonTest.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function setUp()
2525
/** @test */
2626
public function detect_languages()
2727
{
28-
$nlp = new \Web64\Nlp\NlpClient( $this->nlpserver_config );
28+
$nlp = new \Web64\Nlp\NlpClient( $this->nlpserver_config['hosts'], $this->nlpserver_config['debug'] );
2929

3030
$tests = [
3131
'en' => "The quick brown fox jumps over the lazy dog",
@@ -40,7 +40,6 @@ public function detect_languages()
4040
foreach( $tests as $lang => $text )
4141
{
4242
$detected_lang = $nlp->language( $text );
43-
4443
$this->assertEquals($lang, $detected_lang);
4544
}
4645
}
@@ -50,7 +49,7 @@ public function single_host()
5049
{
5150
$this->nlpserver_config['hosts'] = 'http://localhost:6400/';
5251

53-
$nlp = new \Web64\Nlp\NlpClient( $this->nlpserver_config );
52+
$nlp = new \Web64\Nlp\NlpClient( $this->nlpserver_config['hosts'], $this->nlpserver_config['debug'] );
5453

5554
$detected_lang = $nlp->language( "The quick brown fox jumps over the lazy dog" );
5655

@@ -61,19 +60,19 @@ public function single_host()
6160
/** @test */
6261
public function not_enough_text()
6362
{
64-
$nlp = new \Web64\Nlp\NlpClient( $this->nlpserver_config );
63+
$nlp = new \Web64\Nlp\NlpClient( $this->nlpserver_config['hosts'], $this->nlpserver_config['debug'] );
6564

6665
$detected_lang = $nlp->language( "?" );
67-
echo "Detected: lang:". $detected_lang . PHP_EOL;
66+
$this->msg( "Detected: lang:". $detected_lang );
6867
$this->assertEquals('en', $detected_lang);;
6968
}
7069

7170
/** @test */
7271
public function fail_first_then_retry()
7372
{
74-
$nlp = new \Web64\Nlp\NlpClient( $this->nlpserver_config );
73+
$nlp = new \Web64\Nlp\NlpClient( $this->nlpserver_config['hosts'], $this->nlpserver_config['debug'] );
7574
$nlp->api_url = 'http://localhost:6666/'; // <-- wrong port
76-
print_r( $nlp );
75+
//print_r( $nlp );
7776

7877
$detected_lang = $nlp->language( "The quick brown fox jumps over the lazy dog" );
7978

‎tests/Unit/NewspaperTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class NewspaperTest extends TestCase
99
/** @test */
1010
public function url_article_extraction()
1111
{
12-
$nlp = new \Web64\Nlp\NlpClient( $this->nlpserver_config );
12+
$nlp = new \Web64\Nlp\NlpClient( $this->nlpserver_config['hosts'], $this->nlpserver_config['debug'] );
1313

1414
$newspaper = $nlp->newspaperUrl('http://www.bbc.com/news/science-environment-43710766');
1515

‎tests/Unit/PolyglotTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class PolyglotTest extends TestCase
1010
/** @test */
1111
public function entity_extraction()
1212
{
13-
$nlp = new \Web64\Nlp\NlpClient( $this->nlpserver_config );
13+
$nlp = new \Web64\Nlp\NlpClient( $this->nlpserver_config['hosts'], $this->nlpserver_config['debug'] );
1414

1515
$text = "Big Ben is the largest of five bells and weighs 13.7 tonnes. It was the largest bell in the United Kingdom for 23 years.
1616
The origin of the bell's nickname is open to question; it may be named after Sir Benjamin Hall, who oversaw its installation, or heavyweight boxing champion Benjamin Caunt.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /