【问题标题】:Watson discovery app not working with JSONWatson 发现应用程序无法使用 JSON
【发布时间】:2017-05-23 06:32:00
【问题描述】:

您好,我正在尝试将 json 文件作为数据集上传到 watson 发现控制台。通常对于 PDF 和其他可接受的文件格式,数据丰富(关键字、实体、分类等)由 Discovery 应用程序自动创建。但是,如果我以 JSON 格式上传数据集,则不会这样做。

是否需要遵循任何特定的 JSON 格式?我是否正确,它会自动插入丰富内容?

【问题讨论】:

    标签: json dataset ibm-watson watson-discovery data-collection


    【解决方案1】:

    可能发生的事情

    我猜您使用的是 Watson Discovery 提供的 Default ConfigurationDefault Configuration 将扩充应用于输入数据中的单个字段,该字段名为 text。默认情况下,HTML、PDF 和 Microsoft Word 的转换器会将文档的正文输出到 JSON 字段 text。当您将 JSON 发送到 Watson Discovery 时,不会进行任何转换 - 字段名称会直接传递。

    你可以尝试什么

    1. 调整您的输入 JSON,使其具有一个名为 text 的顶级字段,其中包含您要丰富的文本。
    2. 制作并使用自定义配置,其中 enrichments 下的一个或多个条目(其值为 source_field)是您希望 Watson Discovery 丰富的 JSON 中的字段名称。

    Watson Discovery Tooling 对于试验自定义配置非常有帮助。

    示例

    具体说明一下。这是Default Configurationenrichments 部分:

    "enrichments": [{
      "destination_field": "enriched_text",
      "source_field": "text",
      "enrichment": "alchemy_language",
      "options": {
        "extract": "keyword, entity, doc-sentiment, taxonomy, concept, relation",
        "sentiment": true,
        "quotations": true
      }
    }]
    

    如果您的 JSON 在名为 paragraphs 的字段中包含英文文本,并且您希望 Watson Discovery 为该字段提供丰富内容,则可以使用以下配置:

    "enrichments": [{
      "destination_field": "enriched_paragraphs",
      "source_field": "paragraphs",
      "enrichment": "alchemy_language",
      "options": {
        "extract": "keyword, entity, doc-sentiment, taxonomy, concept, relation",
        "sentiment": true,
        "quotations": true
      }
    }]
    

    【讨论】:

      【解决方案2】:

      您可以在界面内和cURL上传。

      查看一个示例 (cURL) - 创建一个集合:

      curl -X POST -u "{username}":"{password}" -H "Content-Type: application/json" -d '{
        "name": "test_collection",
        "description": "My test collection",
        "configuration_id": "{configuration_id}"
      }' "https://gateway.watsonplatform.net/discovery/api/v1/environments/{environment_id}/collections?version=2016-12-01"
      

      您将设置"Content-Type: application/json"。使用Service Credentials 插入您的usernamepassword。并在 URL 中设置您的 enviromenment_id。

      添加一些文档:

      curl -X POST -u "{username}":"{password}" -F file=@sample1.html "https://gateway.watsonplatform.net/discovery/api/v1/environments/{environment_id}/collections/{collection_id}/documents?version=2016-12-01"
      

      Obs.:要摄取的文档。支持的最大文件大小为 50 兆字节。大于 50 兆字节的文件将被拒绝。 API 会检测 文档类型,但如果不正确,您可以指定它。可接受的 MIME 类型值为 application/json、application/msword、application/vnd.openxmlformats-officedocument.wordprocessingml.document、application/pdf、text/html 和 application/xhtml+xml。将多部分表单中的内容类型指定为type=

      curl -X PUT -u "{username}":"{password}" -H "Content-Type: application/json" -d@my_config.json "https://gateway.watsonplatform.net/discovery/api/v1/environments/{environment_ID}/configurations/{Configuration_ID}?version=2016-12-01"
      

      请参阅official API 参考文档。

      【讨论】:

        猜你喜欢
        • 2016-02-06
        • 1970-01-01
        • 1970-01-01
        • 2019-01-20
        • 1970-01-01
        • 1970-01-01
        • 2021-04-17
        • 1970-01-01
        • 2018-11-19
        相关资源
        最近更新 更多