2016-05-23 6 views
-1

は私がワトソン - 開発者 - クラウド Node.jsのライブラリを使用して、ワトソンのドキュメント変換サービス内のユニットに答えるためにthis document (http://www.redbooks.ibm.com/redbooks/pdfs/ga195486.pdf)を変換しようとしています。実際のプログラム(ではない、このテストプログラム)でまず、Watsonのドキュメント変換サービスにディスクを書き込まずにPDFを送信しますか?

、私は文書を検索していますし、最初のディスクに書き込むことなく、オンザフライでそれを変換します。これまで他の文書でこれを行っていましたが、ライブラリの最新バージョン(v 1.7.0)が変更されたように見え、使用していないようです。しかし、私が最新バージョンを使用する前から、この特定の文書は変換されませんでした。

私が使用している注釈付きテストコードは以下のとおりです。私はのバリエーションがすべてをコメントアウトしているvarは以下= {を付き合えない、仕事にこれを取得するにはいくつかの方法を試してみました。結果を確認するには、一度に1つずつコメントを外す必要があります。

'use strict'; 
var bluemix = require('./bluemix'); 
var extend=require('util')._extend; 
var fs=require('fs'); 
var watson=require('watson-developer-cloud'); 
var streams = require('memory-streams'); 

var dcCredentials = extend({ 
    url: '<url>', 
    version: 'v1', 
    username: '<username>', 
    password: '<password>' 
}, bluemix.getServiceCreds('document_conversion')); // VCAP_SERVICES 
var document_conversion = watson.document_conversion(dcCredentials); 

var bookpdf=getBook('ga195486.pdf'); 
convert(bookpdf); 

function getBook(filename) 
    { 
    var bl=fs.readFileSync(filename,'utf8'); 
    return bl; 
    } 

function convert(content) 
    { 
    var opts={ //uncomment ONE of these 
//  file: new Buffer(content), //See message #1 below 
//  file: {value: new Buffer(content), options: {}}, //see message #2 below 
//  file: {value: new Buffer(content), options: {contentType: "application/pdf"}}, //This used to work. See message #2 (again) below 
//  file: new streams.ReadableStream(content),//see message #3 below 
     conversion_target: "ANSWER_UNITS", 
     content_type:'application/pdf' 
     }; 
    document_conversion.convert(opts, 
     function (err, response) 
     { 
     if (err) 
      { 
      console.log("Error converting doc: ", err); 
      } 
     else if (response.answer_units.length==0) 
      { 
      var msg="No answer units"; 
      console.log(msg,response); 
      } 
     else 
      { 
      console.log('Works!'); 
      console.dir(response); 
      } 
     } 
    ); 
    } 

//Message #1: This returns: 
// No answer units { source_document_id: '', 
// timestamp: '2016-05-23T16:18:23.825Z', 
// media_type_detected: 'application/pdf', 
// metadata: [], 
// answer_units: [], 
// warnings: 
// [ { phase: 'pdf', 
//  warning_id: 'empty_input_to_converter', 
//  description: 'The input provided to the converter phase is empty or doesn\'t contain text that can be converted.' }, 
//  { phase: 'normalized_html', 
//  warning_id: 'empty_input_to_converter', 
//  description: 'The input HTML document has no body content.' }, 
//  { phase: 'answer_units', 
//  warning_id: 'empty_input_to_converter', 
//  description: 'The input provided to the converter phase is empty or doesn\'t contain text that can be converted.' } ] } 


//Message #2: These return: 
///home/david/git/ccb-contentbridge/node_modules/watson-developer-cloud/node_modules/request/node_modules/combined-stream/node_modules/delayed-stream/lib/delayed_stream.js:33 
// source.on('error', function() {}); 
// 
//TypeError: source.on is not a function 
// at Function.DelayedStream.create (/home/david/git/ccb-contentbridge/node_modules/watson-developer-cloud/node_modules/request/node_modules/combined-stream/node_modules/delayed-stream/lib/delayed_stream.js:33:10) 
// at FormData.CombinedStream.append (/home/david/git/ccb-contentbridge/node_modules/watson-developer-cloud/node_modules/request/node_modules/combined-stream/lib/combined_stream.js:43:37) 
// at FormData.append (/home/david/git/ccb-contentbridge/node_modules/watson-developer-cloud/node_modules/request/node_modules/form-data/lib/form_data.js:68:3) 
// at appendFormValue (/home/david/git/ccb-contentbridge/node_modules/watson-developer-cloud/node_modules/request/request.js:339:21) 
// at Request.init (/home/david/git/ccb-contentbridge/node_modules/watson-developer-cloud/node_modules/request/request.js:352:11) 
// at new Request (/home/david/git/ccb-contentbridge/node_modules/watson-developer-cloud/node_modules/request/request.js:142:8) 
// at request (/home/david/git/ccb-contentbridge/node_modules/watson-developer-cloud/node_modules/request/index.js:55:10) 
// at createRequest (/home/david/git/ccb-contentbridge/node_modules/watson-developer-cloud/lib/requestwrapper.js:134:10) 
// at DocumentConversion.convert (/home/david/git/ccb-contentbridge/node_modules/watson-developer-cloud/services/document_conversion/v1.js:134:10) 
// at convert (/home/david/git/ccb-contentbridge/testRedbooks.js:35:24) 


//Message #3: This returns and then it hangs there: 
//Error converting doc: { code: 400, error: 'Error in the web application' } 

私が間違っていることを教えてもらえますか?

+0

私はこれを見ています。 v1.7.0より前に動作し、v1.7.0以降は動作しないものの例がありますか? –

答えて

1

この特定のファイルは、ドキュメント変換サービスが現在処理できるものよりも大きくなっています。残念ながら、私は限界が今何かについての非常に良い情報を持っていませんが、チームはこれを認識して改善を検討しています。

あなたが以前働いていたが、Node.jsのライブラリのv1.7.0で破った例を提供できる場合、私はそれを見て、うまくいけば、より良い情報を提供できるようになります。

お使いのfs.readfileSync()コールで'utf8'と指定すると、発生している問題の原因となっている可能性があります。ドクコンの制限が50メガバイトper thisと私たちの文書はそれよりも小さいですのような...他のいくつかの問題でなければなりません

+0

私が変換しようとしていたすべてのレッドブック文書は、サイズ制限を超えています。私はサイズの制限さえあることに気付かず、私が受け取ったエラーはそのようには示さなかった。メガバイト以下のPDFファイルを使用している場合、最初のオプション(file:new Buffer(content))が正常に動作しているようです。 'utf8'パラメータに関しては、私がそこに置くときに私が何を考えているのか分かりません。これは "本物の"コードの一部ではなく、このテストプログラムだけです。 –

1

が見えます。

関連する問題