Skip to content

Commit 33701a0

Browse files
added document conversion example
1 parent 58ff26f commit 33701a0

File tree

6 files changed

+56
-7
lines changed

6 files changed

+56
-7
lines changed

README.md

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ APIs and SDKs that use cognitive computing to solve complex problems.
2525
* [Concept Expansion](#concept-expansion)
2626
* [Concept Insights](#concept-insights)
2727
* [Dialog](#dialog)
28+
* [Document Conversion](#document-conversion)
2829
* [Language Translation](#language-translation)
2930
* [Message Resonance](#message-resonance)
3031
* [Natural Language Classifier](#natural-language-classifier)
@@ -221,12 +222,37 @@ var dialog = watson.dialog({
221222
version: 'v1'
222223
});
223224

224-
225225
dialog.getDialogs({}, function (err, dialogs) {
226-
if (err)
227-
console.log('error:', err);
228-
else
229-
console.log(JSON.stringify(dialogs, null, 2));
226+
if (err)
227+
console.log('error:', err);
228+
else
229+
console.log(JSON.stringify(dialogs, null, 2));
230+
});
231+
```
232+
233+
### Document Conversion
234+
235+
```javascript
236+
var watson = require('watson-developer-cloud');
237+
var fs = require('fs');
238+
239+
var document_conversion = watson.document_conversion({
240+
username: '<username>',
241+
password: '<password>',
242+
version: 'v1-experimental'
243+
});
244+
245+
// convert a single document
246+
document_conversion.convert({
247+
// (JSON) ANSWER_UNITS, NORMALIZED_HTML, or NORMALIZED_TEXT
248+
file: fs.createReadStream('sample-docx.docx'),
249+
conversion_target: document_conversion.conversion_target.ANSWER_UNITS
250+
}, function (err, response) {
251+
if (err) {
252+
console.error(err);
253+
} else {
254+
console.log(JSON.stringify(response, null, 2));
255+
}
230256
});
231257
```
232258

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'use strict';
2+
3+
var watson = require('watson-developer-cloud');
4+
var fs = require('fs');
5+
6+
var document_conversion = watson.document_conversion({
7+
username: 'INSERT YOUR USERNAME FOR THE SERVICE HERE',
8+
password: 'INSERT YOUR PASSWORD FOR THE SERVICE HERE',
9+
version: 'v1-experimental'
10+
});
11+
12+
// convert a single document
13+
document_conversion.convert({
14+
// (JSON) ANSWER_UNITS, NORMALIZED_HTML, or NORMALIZED_TEXT
15+
file: fs.createReadStream(__dirname + '/resources/document_conversion/sample-docx.docx'),
16+
conversion_target: document_conversion.conversion_target.ANSWER_UNITS
17+
}, function (err, response) {
18+
if (err) {
19+
console.error(err);
20+
} else {
21+
console.log(JSON.stringify(response, null, 2));
22+
}
23+
});
17.3 KB
Binary file not shown.

lib/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ var watson = {};
114114
'tone_analyzer',
115115
'dialog',
116116
'retrieve_and_rank',
117+
'document_conversion',
118+
117119
// deprecated
118120
'search',
119121
'language_identification',

services/document-conversion/v1-experimental.js renamed to services/document_conversion/v1-experimental.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,8 +381,6 @@ DocumentConversion.prototype.getBatchDocument = function(params, callback) {
381381
/**
382382
* Creates a job to convert a batch of documents
383383
*
384-
* todo: config (?)
385-
*
386384
* @param params.name
387385
* @param params.batch_id
388386
* @param params.conversion_target

test/resources/sampleWORD.docx

97.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)