0

我已经按照 IBM 网站上的教程(https://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/doc/retrieve-rank/get_start.shtml),我现在正在尝试应用相同的Java中的程序,但是当我开始训练排名器时遇到了一些麻烦。

我使用了教程中提供的数据(Cranfield 数据集),但是排名者继续训练,并且在开始后大约 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..."
[...]

欢迎所有建议,感谢您的宝贵时间。

4

0 回答 0