我已经按照IBM网站(https://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/doc/retrieve-rank/get_start.shtml)上提供的教程进行了操作,现在我正在尝试在Java中应用相同的过程,但是当我开始训练排名时遇到一些麻烦。
我使用了教程(颅场数据集)中提供的数据,但是排名者继续训练,并且在开始后大约20分钟,排名状态变为“失败”。
我猜我错过了一些东西,因为它与curl完美配合,但我无法弄清楚我的代码有什么问题。
public static void main(String[] args) {
String cluster_id = "", config_name = "config0", collection_name = "ibm_collection", ranker_id = "", ranker_name = "ranker0";
String username = "<RAR_login>", password = "<RAR_password>";
HttpSolrClient solrClient = null;
//The RetrieveAndRankService class contains a RetrieveAndRank instance; it also contains some method to store results in ElasticSearch
RetrieveAndRankService rars = new RetrieveAndRankService(username, password);
rars.deleteAllCluster(rars.getService());
//Create cluster
try {
SolrCluster cluster = rars.createSolrCluster("Cluster0", 0);
cluster_id = cluster.getId();
solrClient = rars.getSolrClient(rars.getService().getSolrUrl(cluster_id), username, password, cluster_id);
}catch(Exception e) { e.printStackTrace(); }
//Upload configuration
rars.uploadSolrConfig(cluster_id, config_name, CRANFIELD_CONFIG);
//Create configuration
try {
rars.createCollection(collection_name, config_name, solrClient);
}catch(Exception e) {e.printStackTrace(); }
//Indexing documents
try {
addJsonDocuments(solrClient, CRANFIELD_DATA, collection_name);
}catch(Exception e) { e.printStackTrace(); }
//Create and train ranker
try {
Ranker ranker = rars.getService().createRanker(ranker_name, new File(CRANFIELD_GT)).execute();
ranker_id = ranker.getId();
while (ranker.getStatus() == com.ibm.watson.developer_cloud.retrieve_and_rank.v1.model.Ranker.Status.TRAINING) {
Thread.sleep(4000); // sleep 4 seconds
ranker = rars.getService().getRankerStatus(ranker.getId()).execute();
System.out.println(ranker.getStatusDescription());
System.out.println("Training Ranker...");
}
System.out.println(ranker.getStatusDescription());
rars.cleanupResources(solrClient, cluster_id, config_name, collection_name);
rars.deleteAllCluster(rars.getService());
}catch(Exception e) { e.printStackTrace(); }
}
结果如下:
Creating cluster...
Creating cluster...
[...]
The following cluster have been created : {
"solr_cluster_id": "scb4bbcd66_5aa1_4862_9c8d_b1572846102c",
"cluster_name": "Cluster0",
"cluster_size": "",
"solr_cluster_status": "READY"
}
Uploading configuration...
Uploaded configuration !
Creating collection...
Collection created.
Adding documents done. Response Text is : {"responseHeader
{"status":0,"QTime":1655}}
"Training Ranker..."
"Training Ranker..."
"Training Ranker..."
[...]
感谢所有建议,感谢您的时间。