1+ /**
2+ * Copyright 2015 IBM Corp. All Rights Reserved.
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+
17+ 'use strict' ;
18+
19+ var extend = require ( 'extend' ) ;
20+ var requestFactory = require ( '../../lib/requestwrapper' ) ;
21+ var pick = require ( 'object.pick' ) ;
22+ var omit = require ( 'object.omit' ) ;
23+ var isStream = require ( 'isstream' ) ;
24+
25+ function AlchemyLanguage ( options ) {
26+ // Default URL
27+ var serviceDefaults = {
28+ url : 'https://access.alchemyapi.com/calls' ,
29+ alchmemy : true
30+ } ;
31+
32+ this . paths = {
33+ text : 'text/TextGetRankedNamedEntities' ,
34+ url : 'url/URLGetRankedNamedEntities' ,
35+ html : 'html/HTMLGetRankedNamedEntities'
36+ } ;
37+
38+ // Replace default options with user provided
39+ this . _options = extend ( serviceDefaults , options ) ;
40+ }
41+
42+ /**
43+ * Extracts a grouped, ranked list of named entities (people, companies,
44+ * organizations, etc.) from within a text, url or html.
45+ */
46+ AlchemyLanguage . prototype . entities = function ( _params , callback ) {
47+ var params = _params || { } ;
48+ var path = null ;
49+
50+ if ( typeof ( params . text ) === 'undefined' &&
51+ typeof ( params . url ) === 'undefined' &&
52+ typeof ( params . html ) === 'undefined' ) {
53+ callback ( new Error ( 'Missing required parameters: either text, ' +
54+ 'url or html needs to be specified' ) ) ;
55+ return ;
56+ }
57+
58+ if ( typeof ( params . text ) !== 'undefined' )
59+ path = '/text/TextGetRankedNamedEntities' ;
60+ else if ( typeof ( params . url ) !== 'undefined' )
61+ path = '/url/URLGetRankedNamedEntities' ;
62+ else
63+ path = '/url/HTMLGetRankedNamedEntities' ;
64+
65+ var parameters = {
66+ options : {
67+ url : path ,
68+ method : 'GET' ,
69+ json : true ,
70+ path : params ,
71+ qs : extend ( { outputMode : 'json' } , params ) // change default output to json
72+ } ,
73+ requiredParams : [ 'text' ] ,
74+ defaultOptions : this . _options
75+ } ;
76+ return requestFactory ( parameters , callback ) ;
77+ } ;
78+
79+ module . exports = AlchemyLanguage ;
0 commit comments