Skip to content

Commit 0f07e85

Browse files
authored
Merge pull request watson-developer-cloud#280 from g-may/AlchemyLanguage-extract-dates
Add Date Extraction to AlchemyLanguage
2 parents 9a0127f + cea6b23 commit 0f07e85

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

lib/alchemy_endpoints.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@
5656
"url" : "/url/URLGetPubDate"
5757
},
5858

59+
"extract_dates": {
60+
"html" : "/html/HTMLExtractDates",
61+
"url" : "/url/URLExtractDates",
62+
"text" : "/text/TextExtractDates"
63+
},
64+
5965
"text_raw": {
6066
"html" : "/html/HTMLGetRawText",
6167
"url" : "/url/URLGetRawText"

services/alchemy_language/v1.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,16 @@ AlchemyLanguage.prototype.relations = createRequest('relations');
148148
AlchemyLanguage.prototype.category = createRequest('category');
149149

150150
/**
151-
* Categorizes the text for text, a URL or HTML.
151+
* Extracts the publication date from a webpage or HTML file.
152152
*/
153153
AlchemyLanguage.prototype.publicationDate = createRequest('publication_date');
154154

155+
/**
156+
* Finds dates in the source text, including relative dates like "next Tuesday"
157+
* if an anchorDate is set.
158+
*/
159+
AlchemyLanguage.prototype.dates = createRequest('extract_dates');
160+
155161
/**
156162
* Detects the RSS/ATOM feeds for a URL or HTML.
157163
*/
@@ -168,7 +174,7 @@ AlchemyLanguage.prototype.microformats = createRequest('microformats');
168174
AlchemyLanguage.prototype.taxonomy = createRequest('taxonomy');
169175

170176
/**
171-
* Categorized through the taxonomy call for text, HTML, or a URL.
177+
* Combines multiple API operations into a single call.
172178
*/
173179
AlchemyLanguage.prototype.combined = createRequest('combined');
174180

test/test.alchemy_language.v1.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,24 @@ describe('alchemy_language', function() {
143143
assert.equal(body, qs.stringify({ html: 'sample text', outputMode: 'json'}));
144144
});
145145
});
146-
147146
})
147+
148+
describe('dates()', function() {
149+
var apiPath = '/text/TextExtractDates';
150+
151+
var payload = {
152+
text: 'Set a reminder for my appointment next Tuesday',
153+
anchorDate: '2016-03-22 00:00:00'
154+
};
155+
156+
it('should generate a valid payload', function() {
157+
var req = alchemy.dates(payload, noop);
158+
assert.equal(req.uri.href, service.url + apiPath + '?apikey=' + service.api_key);
159+
assert.equal(req.method, 'POST');
160+
assert(req.form);
161+
var body = new Buffer(req.body).toString('ascii');
162+
assert.equal(body, qs.stringify({ text: 'Set a reminder for my appointment next Tuesday', anchorDate: '2016-03-22 00:00:00', outputMode: 'json'}));
163+
});
164+
});
165+
148166
});

0 commit comments

Comments
 (0)