Skip to content

Commit 105f23c

Browse files
author
Keith Weaver
authored
Merge pull request #2 from kweaver00/dev-retrieve-rank
Dev retrieve rank
2 parents d37306e + d4e5d93 commit 105f23c

File tree

14 files changed

+15313
-0
lines changed

14 files changed

+15313
-0
lines changed

examples/retrieve-and-rank/cranfield-data.json

Lines changed: 12603 additions & 0 deletions
Large diffs are not rendered by default.

examples/retrieve-and-rank/cranfield-gt.csv

Lines changed: 150 additions & 0 deletions
Large diffs are not rendered by default.
20.4 KB
Binary file not shown.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
/*
3+
* What's this vendor/autoload.php? This is used with composer.
4+
* You need to run `composer install`
5+
*/
6+
require_once "../../vendor/autoload.php";
7+
// require_once "../../src/RetrieveAndRank.php";
8+
9+
$retrieveAndRankObj = new \Kweaver\Watson\RetrieveAndRank();
10+
11+
//Set your IBM Watson Bluemix Service Credentials
12+
$retrieveAndRankObj->setServiceCredentials("ea7df130-724c-4074-8add-e5e753c19acb","sTRQVp3Bd6NZ");
13+
14+
/*
15+
* These steps match https://www.ibm.com/watson/developercloud/doc/retrieve-rank/tutorial.shtml#create-collection
16+
*
17+
* Step 1 is Create Cluster
18+
*/
19+
20+
$response = $retrieveAndRankObj->createCluster("NewTestCluster",1);
21+
22+
print_r($response);
23+
24+
25+
/*
26+
Array ( [success] => 1 [message] => Success. Cluster created [results] => stdClass Object ( [solr_cluster_id] => sc9a0b6b6d_bc72_43e8_acfd_99ad14267e59 [cluster_name] => NewTestCluster [cluster_size] => 1 [solr_cluster_status] => NOT_AVAILABLE ) )
27+
*/
28+
?>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
/*
3+
* What's this vendor/autoload.php? This is used with composer.
4+
* You need to run `composer install`
5+
*/
6+
require_once "../../vendor/autoload.php";
7+
// require_once "../../src/RetrieveAndRank.php";
8+
9+
$retrieveAndRankObj = new \Kweaver\Watson\RetrieveAndRank();
10+
11+
//Set your IBM Watson Bluemix Service Credentials
12+
$retrieveAndRankObj->setServiceCredentials("ea7df130-724c-4074-8add-e5e753c19acb","sTRQVp3Bd6NZ");
13+
14+
/*
15+
* These steps match https://www.ibm.com/watson/developercloud/doc/retrieve-rank/tutorial.shtml#create-collection
16+
*
17+
* Step 2 is verify cluster. Waiting for solr_cluster_status to be READY
18+
*/
19+
20+
$response = $retrieveAndRankObj->getCluster("sc9a0b6b6d_bc72_43e8_acfd_99ad14267e59");
21+
22+
print_r($response);
23+
24+
25+
/*
26+
Array ( [success] => 1 [message] => Success. Cluster created [results] => stdClass Object ( [solr_cluster_id] => sc9a0b6b6d_bc72_43e8_acfd_99ad14267e59 [cluster_name] => NewTestCluster [cluster_size] => 1 [solr_cluster_status] => NOT_AVAILABLE ) )
27+
*/
28+
?>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
/*
3+
* What's this vendor/autoload.php? This is used with composer.
4+
* You need to run `composer install`
5+
*/
6+
require_once "../../vendor/autoload.php";
7+
// require_once "../../src/RetrieveAndRank.php";
8+
9+
$retrieveAndRankObj = new \Kweaver\Watson\RetrieveAndRank();
10+
11+
//Set your IBM Watson Bluemix Service Credentials
12+
$retrieveAndRankObj->setServiceCredentials("ea7df130-724c-4074-8add-e5e753c19acb","sTRQVp3Bd6NZ");
13+
14+
/*
15+
* These steps match https://www.ibm.com/watson/developercloud/doc/retrieve-rank/tutorial.shtml#create-collection
16+
*
17+
* Step 3 is add solr config files
18+
*/
19+
20+
$localPathToSolrZip = realpath("./docs/cranfield-solr-config.zip");
21+
22+
$response = $retrieveAndRankObj->uploadSolrConfiguration("sc9a0b6b6d_bc72_43e8_acfd_99ad14267e59", $localPathToSolrZip);
23+
24+
print_r($response);
25+
26+
27+
/*
28+
Array ( [success] => 1 [message] => Success. Uploaded Solr Configuration for sc9a0b6b6d_bc72_43e8_acfd_99ad14267e59. [results] => stdClass Object ( [message] => WRRCSR026: Successfully uploaded named config [cranfield-solr-config.zip] for Solr cluster [sc9a0b6b6d_bc72_43e8_acfd_99ad14267e59]. [statusCode] => 200 ) )
29+
*/
30+
?>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
/*
3+
* What's this vendor/autoload.php? This is used with composer.
4+
* You need to run `composer install`
5+
*/
6+
require_once "../../vendor/autoload.php";
7+
// require_once "../../src/RetrieveAndRank.php";
8+
9+
$retrieveAndRankObj = new \Kweaver\Watson\RetrieveAndRank();
10+
11+
//Set your IBM Watson Bluemix Service Credentials
12+
$retrieveAndRankObj->setServiceCredentials("ea7df130-724c-4074-8add-e5e753c19acb","sTRQVp3Bd6NZ");
13+
14+
/*
15+
* These steps match https://www.ibm.com/watson/developercloud/doc/retrieve-rank/tutorial.shtml#create-collection
16+
*
17+
* Step 4 is create a collection
18+
*
19+
* cranfield-solr-config.zip <-- is the configuration name from the previous step
20+
* and this is the file name
21+
*/
22+
23+
// createCollection (clusterId, collectionName, configurationName)
24+
$response = $retrieveAndRankObj->createCollection("sc9a0b6b6d_bc72_43e8_acfd_99ad14267e59","ExampleCollectionName","cranfield-solr-config.zip");
25+
26+
print_r($response);
27+
28+
29+
/*
30+
Array ( [success] => 1 [message] => Success. Created collection. [results] => stdClass Object ( [responseHeader] => stdClass Object ( [status] => 0 [QTime] => 11138 ) [success] => stdClass Object ( [10.176.43.111:5937_solr] => stdClass Object ( [responseHeader] => stdClass Object ( [status] => 0 [QTime] => 2492 ) [core] => ExampleCollectionName_shard1_replica2 ) [10.176.42.14:5704_solr] => stdClass Object ( [responseHeader] => stdClass Object ( [status] => 0 [QTime] => 2861 ) [core] => ExampleCollectionName_shard1_replica1 ) ) ) )
31+
*/
32+
?>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
/*
3+
* What's this vendor/autoload.php? This is used with composer.
4+
* You need to run `composer install`
5+
*/
6+
require_once "../../vendor/autoload.php";
7+
// require_once "../../src/RetrieveAndRank.php";
8+
9+
$retrieveAndRankObj = new \Kweaver\Watson\RetrieveAndRank();
10+
11+
//Set your IBM Watson Bluemix Service Credentials
12+
$retrieveAndRankObj->setServiceCredentials("ea7df130-724c-4074-8add-e5e753c19acb","sTRQVp3Bd6NZ");
13+
14+
/*
15+
* These steps match https://www.ibm.com/watson/developercloud/doc/retrieve-rank/tutorial.shtml#create-collection
16+
*
17+
* Step 5 - add data json (this is all data)
18+
*/
19+
20+
$localPathToDataJSON = realpath("./cranfield-data.json");
21+
22+
$response = $retrieveAndRankObj->uploadDataJSON("sc9a0b6b6d_bc72_43e8_acfd_99ad14267e59","ExampleCollectionName", $localPathToDataJSON);
23+
24+
print_r($response);
25+
26+
27+
/*
28+
Array ( [success] => 1 [message] => Success. Uploaded Solr Configuration for sc9a0b6b6d_bc72_43e8_acfd_99ad14267e59. [results] => stdClass Object ( [responseHeader] => stdClass Object ( [status] => 0 [QTime] => 1611 ) ) )
29+
*/
30+
?>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
/*
3+
* In step 7, there's actually no PHP code. You are using the file train.py to
4+
* train a ranker (the python code will create it) with cranfield-gt.csv. This
5+
* is the train data file, there are rules associated with it, that can be
6+
* found online at the IBM site.
7+
*
8+
* Open your terminal and run:
9+
* python ./train.py -u {username}:{password} -i {/path_to_file}/cranfield-gt.csv -c {solr_cluster_id} -x example_collection -n "example_ranker"
10+
*
11+
12+
My query was and wont work for you:
13+
14+
python ./train.py -u ea7df130-724c-4074-8add-e5e753c19acb:sTRQVp3Bd6NZ -i ./cranfield-gt.csv -c sc9a0b6b6d_bc72_43e8_acfd_99ad14267e59 -x ExampleCollectionName -n "example_ranker"
15+
16+
// Output
17+
18+
Input file is ./cranfield-gt.csv
19+
Solr cluster is sc9a0b6b6d_bc72_43e8_acfd_99ad14267e59
20+
Solr collection is ExampleCollectionName
21+
Ranker name is example_ranker
22+
Rows per query 10
23+
Generating training data...
24+
Generating training data complete.
25+
% Total % Received % Xferd Average Speed Time Time Time Current
26+
Dload Upload Total Spent Left Speed
27+
100 304k 0 319 100 304k 93 91206 0:00:03 0:00:03 --:--:-- 91221
28+
{"ranker_id":"1eec74x28-rank-1000","name":"example_ranker","created":"2017-02-22T02:44:25.697Z","url":"https://gateway.watsonplatform.net/retrieve-and-rank/api/v1/rankers/1eec74x28-rank-1000","status":"Training","status_description":"The ranker instance is in its training phase, not yet ready to accept rank requests"}
29+
30+
*/
31+
?>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
/*
3+
* What's this vendor/autoload.php? This is used with composer.
4+
* You need to run `composer install`
5+
*/
6+
require_once "../../vendor/autoload.php";
7+
// require_once "../../src/RetrieveAndRank.php";
8+
9+
$retrieveAndRankObj = new \Kweaver\Watson\RetrieveAndRank();
10+
11+
//Set your IBM Watson Bluemix Service Credentials
12+
$retrieveAndRankObj->setServiceCredentials("ea7df130-724c-4074-8add-e5e753c19acb","sTRQVp3Bd6NZ");
13+
14+
/*
15+
* These steps match https://www.ibm.com/watson/developercloud/doc/retrieve-rank/tutorial.shtml#create-collection
16+
*
17+
* Step 7 - verify ranker is ready [status] => Available
18+
*/
19+
20+
$response = $retrieveAndRankObj->getRanker("1eec74x28-rank-1000");
21+
22+
print_r($response);
23+
24+
25+
/*
26+
Array ( [success] => 1 [message] => Success. Search and rank. [results] => stdClass Object ( [ranker_id] => 1eec74x28-rank-1000 [name] => example_ranker [created] => 2017-02-22T02:44:25.697Z [url] => https://gateway.watsonplatform.net/retrieve-and-rank/api/v1/rankers/1eec74x28-rank-1000 [status] => Available [status_description] => The ranker instance is now available and is ready to take ranker requests. ) )
27+
*/
28+
?>

0 commit comments

Comments
 (0)