嗨,我正在尝试在 Watson 发现控制台中将 json 文件作为数据集上传。通常,对于 PDF 和其他可接受的文件格式,数据扩充(关键字、实体、分类等)由发现应用程序自动创建。但是,如果我以 JSON 格式上传数据集,它不会做同样的事情。
是否有任何需要遵循的特定 JSON 格式?我说的对吗,它会自动自行插入浓缩内容?
可能会发生什么
我猜你使用的是 Watson Discovery 提供的Default Configuration
。Default Configuration
将扩充应用于输入数据中的单个字段,即名为text
的字段。默认情况下,HTML、PDF 和 Microsoft Word 的转换器会将文档正文输出到 JSON 字段text
中。当您将 JSON 发送到 Watson Discovery 时,不会进行任何转换 - 字段名称直接传递。
你可以尝试什么
- 调整输入 JSON 以具有名为
text
的顶级字段,其中包含要扩充的文本。 - 创建并使用自定义配置,
enrichments
下的一个或多个条目的值为source_field
是您希望 Watson Discovery 扩充的 JSON 中字段的名称。
Watson Discovery Tooling 对于试验自定义配置非常有帮助。
例
具体说明这一点。这是Default Configuration
enrichments
部分:
"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
}
}]
您可以在界面内上传,并使用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"
。插入username
,password
Service Credentials
。并在 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 MB。大于 50 MB 的文件将被拒绝。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"
请参阅官方 API 参考文档。