@@ -104,15 +104,16 @@ DiscoveryUtils.prototype = {
104104 buildParamsForPassages : function ( me , msg , config , params ) {
105105 let passagesFound = false ;
106106
107- // Allow the passages parameters to be passed in two ways
108- // 1. As the API is expecting
107+ // Allow the passages parameters to be passed in three ways
108+ // 1. As the API was expecting (watson-developer-cloud)
109109 [ 'passages.fields' , 'passages.count' , 'passages.characters'
110110 ] . forEach ( function ( f ) {
111111 params = me . buildParamsFor ( msg , config , params , f ) ;
112112 passagesFound = true ;
113113 } ) ;
114114
115115 // 2. As anyone misreading the documentation might do it.
116+ // (again watson-developer-cloud)
116117 if ( msg . discoveryparams && msg . discoveryparams . passages ) {
117118 passagesFound = true ;
118119 [ 'fields' , 'count' , 'characters'
@@ -123,7 +124,25 @@ DiscoveryUtils.prototype = {
123124 } ) ;
124125 }
125126
127+ // 3. As the ibm-watson SDK expects
128+ [ 'passagesFields' , 'passagesCount' , 'passagesCharacters'
129+ ] . forEach ( function ( f ) {
130+ params = me . buildParamsFor ( msg , config , params , f ) ;
131+ passagesFound = true ;
132+ } ) ;
133+
126134 if ( passagesFound ) {
135+ // Perform autocorrect for watson-developer-cloud to ibm-watson
136+ // differences
137+ [ 'passages.fields' , 'passages.count' , 'passages.characters'
138+ ] . forEach ( function ( f ) {
139+ if ( params [ f ] ) {
140+ let parts = f . split ( "." ) ;
141+ let secondPart = parts [ 1 ]
142+ let reformedField = parts [ 0 ] + secondPart [ 0 ] . toUpperCase ( ) + secondPart . slice ( 1 ) ;
143+ params [ reformedField ] = params [ f ] ;
144+ }
145+ } ) ;
127146 params . passages = true ;
128147 }
129148
0 commit comments