0

我正在使用 Watson 的Retrieve & Rank服务实施解决方案。

当我使用工具界面时,我上传了我的文档,它们显示为一个列表,我可以单击其中的任何一个来打开文档中的所有标题(答案单元),如图 1 所示图 2。

当我尝试通过 Java 上传文档时,它不会识别文档,它们会分部分上传(答案单元作为文档),每个部分都作为一个新文档。

我想知道如何将我的文件作为整个文件而不是部分文件上传?

以下是Java中上传功能的代码:

    public Answers ConvertToUnits(File doc, String collection) throws ParseException, SolrServerException, IOException{
    DC.setUsernameAndPassword(USERNAME,PASSWORD);
    Answers response = DC.convertDocumentToAnswer(doc).execute();
    SolrInputDocument newdoc = new SolrInputDocument();
    WatsonProcessing wp = new WatsonProcessing();
    Collection<SolrInputDocument> newdocs = new ArrayList<SolrInputDocument>();

    for(int i=0; i<response.getAnswerUnits().size(); i++)
    {
        String titulo = response.getAnswerUnits().get(i).getTitle();
        String id = response.getAnswerUnits().get(i).getId();
        newdoc.addField("title", titulo);
        for(int j=0; j<response.getAnswerUnits().get(i).getContent().size(); j++)
        {
            String texto = response.getAnswerUnits().get(i).getContent().get(j).getText();
            newdoc.addField("body", texto);

        }
        wp.IndexDocument(newdoc,collection);
        newdoc.clear();
    }
    wp.ComitChanges(collection);
    return response;
}


      public void IndexDocument(SolrInputDocument newdoc, String collection) throws SolrServerException, IOException
  {
      UpdateRequest update = new UpdateRequest();
      update.add(newdoc);
      UpdateResponse addResponse = solrClient.add(collection, newdoc);
  }
4

1 回答 1

1

您可以在此行中指定配置选项:

Answers response = DC.convertDocumentToAnswer(doc).execute();

我认为这样的事情应该可以解决问题:

String configAsString = "{ \"conversion_target\":\"answer_units\", \"answer_units\": { \"selector_tags\": [] } }";

JsonParser jsonParser = new JsonParser();
JsonObject customConfig = jsonParser.parse(configAsString).getAsJsonObject();    

Answers response = DC.convertDocumentToAnswer(doc, null, customConfig).execute();

我还没有尝试过,所以可能没有完全正确的语法,但希望这会让你走上正确的轨道。

本质上,我在这里要做的是使用配置中的选项(有关此文档,selector_tags请参阅https://www.ibm.com/watson/developercloud/doc/document-conversion/customizing.shtml#htmlau )指定应该在哪些标签上拆分文档。通过指定一个没有标签的空列表,它会导致它根本不被拆分 - 并根据需要在单个答案单元中出现。

(请注意,您也可以通过工具界面执行此操作 - 通过在上传文档时取消选中“将我的文档拆分为我的个人答案”选项)

于 2016-08-30T16:56:11.940 回答