Skip to content

Commit

Permalink
re-config
Browse files Browse the repository at this point in the history
  • Loading branch information
web64 committed Apr 10, 2018
1 parent 2d84676 commit 687a0d1
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 20 deletions.
2 changes: 1 addition & 1 deletion examples/embeddings.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
'debug' => true,
];

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

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

Expand Down
2 changes: 1 addition & 1 deletion examples/language_detection.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
'debug' => false,
];

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

$texts = [
'en' => "The quick brown fox jumps over the lazy dog",
Expand Down
2 changes: 1 addition & 1 deletion examples/newspaper.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
'debug' => true,
];

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

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

Expand Down
2 changes: 1 addition & 1 deletion examples/polyglot.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
'debug' => false,
];

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


$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.
Expand Down
12 changes: 6 additions & 6 deletions src/NlpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ class NlpClient{
public $debug = false;
private $max_retry_count = 3;

function __construct( $config )
function __construct( $hosts, $debug = false )
{
if ( is_array($config['hosts']) )
$this->debug = (bool)$debug;

if ( is_array($hosts) )
{
foreach( $config['hosts'] as $host )
foreach( $hosts as $host )
$this->addHost( $host );
}
else
$this->addHost( $config['hosts'] );
$this->addHost( $hosts );

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

// pick random host as default
$this->api_url = $this->api_hosts[
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/EmbeddingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class EmbeddingsTest extends TestCase
/** @test */
public function get_neighbours()
{
$nlp = new \Web64\Nlp\NlpClient( $this->nlpserver_config );
$nlp = new \Web64\Nlp\NlpClient( $this->nlpserver_config['hosts'], $this->nlpserver_config['debug'] );

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

Expand Down
13 changes: 6 additions & 7 deletions tests/Unit/LanguageDetectonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function setUp()
/** @test */
public function detect_languages()
{
$nlp = new \Web64\Nlp\NlpClient( $this->nlpserver_config );
$nlp = new \Web64\Nlp\NlpClient( $this->nlpserver_config['hosts'], $this->nlpserver_config['debug'] );

$tests = [
'en' => "The quick brown fox jumps over the lazy dog",
Expand All @@ -40,7 +40,6 @@ public function detect_languages()
foreach( $tests as $lang => $text )
{
$detected_lang = $nlp->language( $text );

$this->assertEquals($lang, $detected_lang);
}
}
Expand All @@ -50,7 +49,7 @@ public function single_host()
{
$this->nlpserver_config['hosts'] = 'http://localhost:6400/';

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

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

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

$detected_lang = $nlp->language( "?" );
echo "Detected: lang:". $detected_lang . PHP_EOL;
$this->msg( "Detected: lang:". $detected_lang );
$this->assertEquals('en', $detected_lang);;
}

/** @test */
public function fail_first_then_retry()
{
$nlp = new \Web64\Nlp\NlpClient( $this->nlpserver_config );
$nlp = new \Web64\Nlp\NlpClient( $this->nlpserver_config['hosts'], $this->nlpserver_config['debug'] );
$nlp->api_url = 'http://localhost:6666/'; // <-- wrong port
print_r( $nlp );
//print_r( $nlp );

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

Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/NewspaperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class NewspaperTest extends TestCase
/** @test */
public function url_article_extraction()
{
$nlp = new \Web64\Nlp\NlpClient( $this->nlpserver_config );
$nlp = new \Web64\Nlp\NlpClient( $this->nlpserver_config['hosts'], $this->nlpserver_config['debug'] );

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

Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/PolyglotTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class PolyglotTest extends TestCase
/** @test */
public function entity_extraction()
{
$nlp = new \Web64\Nlp\NlpClient( $this->nlpserver_config );
$nlp = new \Web64\Nlp\NlpClient( $this->nlpserver_config['hosts'], $this->nlpserver_config['debug'] );

$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.
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.
Expand Down

0 comments on commit 687a0d1

Please sign in to comment.