IBM Watson 文档转换不起作用

Posted

技术标签:

【中文标题】IBM Watson 文档转换不起作用【英文标题】:IBM Watson Document Conversion not working 【发布时间】:2017-06-07 08:48:51 【问题描述】:

我最近实现了 IBM Watson 的文档转换 API。转换pdf文档时总是遇到编码错误!!!

#!/usr/bin/env python
#coding: utf-8


import json
from watson_developer_cloud import DocumentConversionV1
from io import open
document_conversion = DocumentConversionV1(
  username='XXXXXXXXXXX',
  password='XXXXXXXXXXXXX',
  version='2015-12-15'
)
config = 
  'conversion_target': 'ANSWER_UNITS',
  # Use a custom configuration.
  'word': 
    'heading': 
      'fonts': [
        'level': 1, 'min_size': 24,
        'level': 2, 'min_size': 16, 'max_size': 24
      ]
    
  


with open(('sample.pdf'), 'r') as document:
  response = document_conversion.convert_document(document=document, config=config)
  print(json.dumps(response, indent=2))

enter image description here

【问题讨论】:

您的配置 JSON 仍然有关键字“word”而不是像我下面的评论中的“pdf” 【参考方案1】:

enter code here您的错误是配置 JSON。您仍在使用单词 config 而不是 pdf config JSON:


"pdf": 
    "heading": 
        "fonts": [
            "level": 1, "min_size": 24,
            "level": 2, "min_size": 18, "max_size": 23, "bold": true,
            "level": 3, "min_size": 14, "max_size": 17, "italic": false,
            "level": 4, "min_size": 12, "max_size": 13, "name": "Times New Roman"
        ]
    

如果您想使用答案单元,请将其添加到您的配置文件中:

var config = 
conversion_target: "answer_units",
"pdf": 
    "heading": 
        "fonts": [
            "level": 1,
            "min_size": 24,
            "max_size": 80
        ,
            
                "level": 2,
                "min_size": 18,
                "max_size": 24,
                "bold": false,
                "italic": false
            ,
            
                "level": 2,
                "min_size": 18,
                "max_size": 24,
                "bold": true
            ,
            
                "level": 3,
                "min_size": 13,
                "max_size": 18,
                "bold": false,
                "italic": false
            ,
            
                "level": 3,
                "min_size": 13,
                "max_size": 18,
                "bold": true
            ,
            
                "level": 4,
                "min_size": 11,
                "max_size": 13,
                "bold": true,
                "italic": false
            
        ]
    

说明: https://www.ibm.com/watson/developercloud/doc/document-conversion/customizing.html

【讨论】:

以上是关于IBM Watson 文档转换不起作用的主要内容,如果未能解决你的问题,请参考以下文章

无法解析代理:POST(在运行 curl 脚本进行 watson 文档转换时)

CSS 转换不起作用 Firefox for XML 文档使用 XSLT 转换为 HTML

IBM-Watson 云产品中输入所需的数据格式是啥?

IBM Cloud Object Storage Connection 问题 Watson Studio Python 笔记本

IBM Watson JavaScript SDK for Speech-To-Text WebSocket 问题

如何在 IBM Watson Assistant 客户端中实现“客户端”类型的操作?