您好我正在尝试将 json 文件上传为 watson 发现控制台中的数据集。通常对于 PDF 和其他可接受的文件格式,数据丰富(关键字、实体、分类等)由 Discovery 应用程序自动创建。但是,如果我以 JSON 格式上传数据集,它不会做同样的事情。
是否需要遵循任何特定的 JSON 格式?我对它自己自动插入浓缩物是对的吗?
您好我正在尝试将 json 文件上传为 watson 发现控制台中的数据集。通常对于 PDF 和其他可接受的文件格式,数据丰富(关键字、实体、分类等)由 Discovery 应用程序自动创建。但是,如果我以 JSON 格式上传数据集,它不会做同样的事情。
是否需要遵循任何特定的 JSON 格式?我对它自己自动插入浓缩物是对的吗?
我猜你使用的Default Configuration
是 Watson Discovery 提供的。Default Configuration
将扩充应用于输入数据中的单个字段,该字段名为text
. 默认情况下,HTML、PDF 和 Microsoft Word 的转换器会将文档正文输出到 JSON 字段中text
。当您将 JSON 发送到 Watson Discovery 时,不会进行任何转换 — 字段名称会直接传递。
text
,其中包含您要丰富的文本。enrichments
的值source_field
是 JSON 中您希望 Watson Discovery 丰富的字段的名称。Watson Discovery Tooling 对于试验自定义配置非常有帮助。
要具体说明这一点。以下是 的enrichments
部分Default Configuration
:
"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
andpassword
与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 兆字节。大于 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"
请参阅官方API 参考文档。