@@ -242,101 +242,53 @@ private void OnGetRankedConceptsResponse(RESTConnector.Request req, RESTConnecto
242
242
private const string SERVICE_GET_DATES_TEXT = "/calls/text/TextExtractDates" ;
243
243
public delegate void OnGetDates ( DateData dateData , string data ) ;
244
244
245
- public bool GetDatesURL ( OnGetDates callback , string url , string anchorDate = default ( string ) , bool includeSourceText = false , string customData = default ( string ) )
245
+ public bool GetDates ( OnGetDates callback , string source , string anchorDate = default ( string ) , bool includeSourceText = false , string customData = default ( string ) )
246
246
{
247
247
if ( callback == null )
248
248
throw new ArgumentNullException ( "callback" ) ;
249
- if ( string . IsNullOrEmpty ( url ) )
250
- throw new WatsonException ( "Please provide a URL for GetDatesURL." ) ;
251
- if ( string . IsNullOrEmpty ( mp_ApiKey ) )
252
- SetCredentials ( ) ;
253
- if ( string . IsNullOrEmpty ( anchorDate ) )
254
- anchorDate = GetCurrentDatetime ( ) ;
255
-
256
- RESTConnector connector = RESTConnector . GetConnector ( SERVICE_ID , SERVICE_GET_DATES_URL ) ;
257
- if ( connector == null )
258
- return false ;
259
-
260
- GetDatesRequest req = new GetDatesRequest ( ) ;
261
- req . Callback = callback ;
262
- req . Data = string . IsNullOrEmpty ( customData ) ? url : customData ;
263
-
264
- req . Parameters [ "apikey" ] = mp_ApiKey ;
265
- req . Parameters [ "outputMode" ] = "json" ;
266
- req . Parameters [ "showSourceText" ] = Convert . ToInt32 ( includeSourceText ) . ToString ( ) ;
267
-
268
- req . Headers [ "Content-Type" ] = "application/x-www-form-urlencoded" ;
269
- req . Forms = new Dictionary < string , RESTConnector . Form > ( ) ;
270
- req . Forms [ "url" ] = new RESTConnector . Form ( url ) ;
271
- req . Forms [ "anchorDate" ] = new RESTConnector . Form ( anchorDate ) ;
272
-
273
- req . OnResponse = OnGetDatesResponse ;
274
- return connector . Send ( req ) ;
275
- }
276
-
277
- public bool GetDatesText ( OnGetDates callback , string text , string anchorDate = default ( string ) , bool includeSourceText = false , string customData = default ( string ) )
278
- {
279
- if ( callback == null )
280
- throw new ArgumentNullException ( "callback" ) ;
281
- if ( string . IsNullOrEmpty ( text ) )
282
- throw new WatsonException ( "Please provide text for GetDatesText." ) ;
249
+ if ( string . IsNullOrEmpty ( source ) )
250
+ throw new WatsonException ( "Please provide a source for GetAuthors." ) ;
283
251
if ( string . IsNullOrEmpty ( mp_ApiKey ) )
284
252
SetCredentials ( ) ;
285
253
if ( string . IsNullOrEmpty ( anchorDate ) )
286
254
anchorDate = GetCurrentDatetime ( ) ;
287
255
288
- RESTConnector connector = RESTConnector . GetConnector ( SERVICE_ID , SERVICE_GET_DATES_TEXT ) ;
289
- if ( connector == null )
290
- return false ;
291
-
292
256
GetDatesRequest req = new GetDatesRequest ( ) ;
293
257
req . Callback = callback ;
294
- req . Data = string . IsNullOrEmpty ( customData ) ? text : customData ;
258
+ req . Data = string . IsNullOrEmpty ( customData ) ? source : customData ;
295
259
296
260
req . Parameters [ "apikey" ] = mp_ApiKey ;
297
261
req . Parameters [ "outputMode" ] = "json" ;
298
262
req . Parameters [ "showSourceText" ] = Convert . ToInt32 ( includeSourceText ) . ToString ( ) ;
299
263
300
264
req . Headers [ "Content-Type" ] = "application/x-www-form-urlencoded" ;
301
265
req . Forms = new Dictionary < string , RESTConnector . Form > ( ) ;
302
- req . Forms [ "text" ] = new RESTConnector . Form ( text ) ;
303
266
req . Forms [ "anchorDate" ] = new RESTConnector . Form ( anchorDate ) ;
304
267
305
- req . OnResponse = OnGetDatesResponse ;
306
- return connector . Send ( req ) ;
307
- }
308
-
309
- public bool GetDatesHTML ( OnGetDates callback , string htmlFilePath , string anchorDate = default ( string ) , bool includeSourceText = false , string customData = default ( string ) )
310
- {
311
- if ( callback == null )
312
- throw new ArgumentNullException ( "callback" ) ;
313
- if ( string . IsNullOrEmpty ( htmlFilePath ) )
314
- throw new WatsonException ( "Please provide text for GetDatesHTML." ) ;
315
- if ( string . IsNullOrEmpty ( mp_ApiKey ) )
316
- SetCredentials ( ) ;
317
- if ( string . IsNullOrEmpty ( anchorDate ) )
318
- anchorDate = GetCurrentDatetime ( ) ;
319
-
320
- string htmlData = default ( string ) ;
321
- htmlData = File . ReadAllText ( htmlFilePath ) ;
268
+ string service ;
269
+ string normalizedSource = source . Trim ( ) . ToLower ( ) ;
270
+ if ( normalizedSource . StartsWith ( "http://" ) || normalizedSource . StartsWith ( "https://" ) )
271
+ {
272
+ service = SERVICE_GET_DATES_URL ;
273
+ req . Forms [ "url" ] = new RESTConnector . Form ( source ) ;
274
+ }
275
+ else if ( Path . GetExtension ( normalizedSource ) . EndsWith ( ".html" ) && ! normalizedSource . StartsWith ( "http://" ) && ! normalizedSource . StartsWith ( "https://" ) )
276
+ {
277
+ service = SERVICE_GET_DATES_HTML ;
278
+ string htmlData = default ( string ) ;
279
+ htmlData = File . ReadAllText ( source ) ;
280
+ req . Forms [ "html" ] = new RESTConnector . Form ( htmlData ) ;
281
+ }
282
+ else
283
+ {
284
+ service = SERVICE_GET_DATES_TEXT ;
285
+ req . Forms [ "text" ] = new RESTConnector . Form ( source ) ;
286
+ }
322
287
323
- RESTConnector connector = RESTConnector . GetConnector ( SERVICE_ID , SERVICE_GET_DATES_HTML ) ;
288
+ RESTConnector connector = RESTConnector . GetConnector ( SERVICE_ID , service ) ;
324
289
if ( connector == null )
325
290
return false ;
326
291
327
- GetDatesRequest req = new GetDatesRequest ( ) ;
328
- req . Callback = callback ;
329
- req . Data = string . IsNullOrEmpty ( customData ) ? htmlFilePath : customData ;
330
-
331
- req . Parameters [ "apikey" ] = mp_ApiKey ;
332
- req . Parameters [ "outputMode" ] = "json" ;
333
- req . Parameters [ "showSourceText" ] = Convert . ToInt32 ( includeSourceText ) . ToString ( ) ;
334
-
335
- req . Headers [ "Content-Type" ] = "application/x-www-form-urlencoded" ;
336
- req . Forms = new Dictionary < string , RESTConnector . Form > ( ) ;
337
- req . Forms [ "html" ] = new RESTConnector . Form ( htmlData ) ;
338
- req . Forms [ "anchorDate" ] = new RESTConnector . Form ( anchorDate ) ;
339
-
340
292
req . OnResponse = OnGetDatesResponse ;
341
293
return connector . Send ( req ) ;
342
294
}
@@ -486,7 +438,7 @@ public bool ExtractEntities(OnGetEntities callback, string source,
486
438
bool includeLinkedData = true ,
487
439
bool includeQuotations = false ,
488
440
bool analyzeSentiment = false ,
489
- bool showSourceText = false ,
441
+ bool includeSourceText = false ,
490
442
bool extractStructuredEntities = true ,
491
443
string customData = default ( string ) )
492
444
{
@@ -510,7 +462,7 @@ public bool ExtractEntities(OnGetEntities callback, string source,
510
462
req . Parameters [ "linkedData" ] = Convert . ToInt32 ( includeLinkedData ) . ToString ( ) ;
511
463
req . Parameters [ "quotations" ] = Convert . ToInt32 ( includeQuotations ) . ToString ( ) ;
512
464
req . Parameters [ "sentiment" ] = Convert . ToInt32 ( analyzeSentiment ) . ToString ( ) ;
513
- req . Parameters [ "showSourceText" ] = Convert . ToInt32 ( showSourceText ) . ToString ( ) ;
465
+ req . Parameters [ "showSourceText" ] = Convert . ToInt32 ( includeSourceText ) . ToString ( ) ;
514
466
req . Parameters [ "structuredEntities" ] = Convert . ToInt32 ( extractStructuredEntities ) . ToString ( ) ;
515
467
516
468
req . Headers [ "Content-Type" ] = "application/x-www-form-urlencoded" ;
@@ -656,7 +608,7 @@ public bool ExtractKeywords(OnGetKeywords callback, string source,
656
608
int maxRetrieve = 50 ,
657
609
bool includeKnowledgeGraph = false ,
658
610
bool analyzeSentiment = false ,
659
- bool showSourceText = false ,
611
+ bool includeSourceText = false ,
660
612
string customData = default ( string ) )
661
613
{
662
614
if ( callback == null )
@@ -675,7 +627,7 @@ public bool ExtractKeywords(OnGetKeywords callback, string source,
675
627
req . Parameters [ "maxRetrieve" ] = Convert . ToInt32 ( maxRetrieve ) . ToString ( ) ;
676
628
req . Parameters [ "knowledgeGraph" ] = Convert . ToInt32 ( includeKnowledgeGraph ) . ToString ( ) ;
677
629
req . Parameters [ "sentiment" ] = Convert . ToInt32 ( analyzeSentiment ) . ToString ( ) ;
678
- req . Parameters [ "showSourceText" ] = Convert . ToInt32 ( showSourceText ) . ToString ( ) ;
630
+ req . Parameters [ "showSourceText" ] = Convert . ToInt32 ( includeSourceText ) . ToString ( ) ;
679
631
req . Parameters [ "keywordExtractMode" ] = "strict" ;
680
632
681
633
req . Headers [ "Content-Type" ] = "application/x-www-form-urlencoded" ;
@@ -1026,7 +978,7 @@ public bool GetRelations(OnGetRelations callback, string source,
1026
978
bool includeLinkedData = true ,
1027
979
bool analyzeSentiment = false ,
1028
980
bool excludeEntitiesInSentiment = false ,
1029
- bool showSourceText = false ,
981
+ bool includeSourceText = false ,
1030
982
string customData = default ( string ) )
1031
983
{
1032
984
if ( callback == null )
@@ -1052,7 +1004,7 @@ public bool GetRelations(OnGetRelations callback, string source,
1052
1004
req . Parameters [ "linkedData" ] = Convert . ToInt32 ( includeLinkedData ) . ToString ( ) ;
1053
1005
req . Parameters [ "sentiment" ] = Convert . ToInt32 ( analyzeSentiment ) . ToString ( ) ;
1054
1006
req . Parameters [ "sentimentExcludeEntities" ] = Convert . ToInt32 ( excludeEntitiesInSentiment ) . ToString ( ) ;
1055
- req . Parameters [ "showSourceText" ] = Convert . ToInt32 ( showSourceText ) . ToString ( ) ;
1007
+ req . Parameters [ "showSourceText" ] = Convert . ToInt32 ( includeSourceText ) . ToString ( ) ;
1056
1008
req . Parameters [ "keywordExtractMode" ] = "strict" ;
1057
1009
1058
1010
req . Headers [ "Content-Type" ] = "application/x-www-form-urlencoded" ;
@@ -1127,7 +1079,7 @@ private void OnGetRelationsResponse(RESTConnector.Request req, RESTConnector.Res
1127
1079
private const string SERVICE_GET_TEXT_SENTIMENT_TEXT = "/calls/text/TextGetTextSentiment" ;
1128
1080
public delegate void OnGetTextSentiment ( SentimentData sentimentData , string data ) ;
1129
1081
1130
- public bool GetTextSentiment ( OnGetTextSentiment callback , string source , bool showSourceText = false , string customData = default ( string ) )
1082
+ public bool GetTextSentiment ( OnGetTextSentiment callback , string source , bool includeSourceText = false , string customData = default ( string ) )
1131
1083
{
1132
1084
if ( callback == null )
1133
1085
throw new ArgumentNullException ( "callback" ) ;
@@ -1142,7 +1094,7 @@ private void OnGetRelationsResponse(RESTConnector.Request req, RESTConnector.Res
1142
1094
1143
1095
req . Parameters [ "apikey" ] = mp_ApiKey ;
1144
1096
req . Parameters [ "outputMode" ] = "json" ;
1145
- req . Parameters [ "showSourceText" ] = Convert . ToInt32 ( showSourceText ) . ToString ( ) ;
1097
+ req . Parameters [ "showSourceText" ] = Convert . ToInt32 ( includeSourceText ) . ToString ( ) ;
1146
1098
1147
1099
req . Headers [ "Content-Type" ] = "application/x-www-form-urlencoded" ;
1148
1100
req . Forms = new Dictionary < string , RESTConnector . Form > ( ) ;
@@ -1216,7 +1168,7 @@ private void OnGetTextSentimentResponse(RESTConnector.Request req, RESTConnector
1216
1168
private const string SERVICE_GET_TARGETED_SENTIMENT_TEXT = "/calls/text/TextGetTargetedSentiment" ;
1217
1169
public delegate void OnGetTargetedSentiment ( TargetedSentimentData targetedSentimentData , string data ) ;
1218
1170
1219
- public bool GetTargetedSentiment ( OnGetTargetedSentiment callback , string source , string targets , bool showSourceText = false , string customData = default ( string ) )
1171
+ public bool GetTargetedSentiment ( OnGetTargetedSentiment callback , string source , string targets , bool includeSourceText = false , string customData = default ( string ) )
1220
1172
{
1221
1173
if ( callback == null )
1222
1174
throw new ArgumentNullException ( "callback" ) ;
@@ -1233,7 +1185,7 @@ private void OnGetTextSentimentResponse(RESTConnector.Request req, RESTConnector
1233
1185
1234
1186
req . Parameters [ "apikey" ] = mp_ApiKey ;
1235
1187
req . Parameters [ "outputMode" ] = "json" ;
1236
- req . Parameters [ "showSourceText" ] = Convert . ToInt32 ( showSourceText ) . ToString ( ) ;
1188
+ req . Parameters [ "showSourceText" ] = Convert . ToInt32 ( includeSourceText ) . ToString ( ) ;
1237
1189
1238
1190
req . Headers [ "Content-Type" ] = "application/x-www-form-urlencoded" ;
1239
1191
req . Forms = new Dictionary < string , RESTConnector . Form > ( ) ;
@@ -1308,7 +1260,7 @@ private void OnGetTargetedSentimentResponse(RESTConnector.Request req, RESTConne
1308
1260
private const string SERVICE_GET_RANKED_TAXONOMY_TEXT = "/calls/text/TextGetRankedTaxonomy" ;
1309
1261
public delegate void OnGetRankedTaxonomy ( TaxonomyData taxonomyData , string data ) ;
1310
1262
1311
- public bool GetRankedTaxonomy ( OnGetRankedTaxonomy callback , string source , bool showSourceText = false , string customData = default ( string ) )
1263
+ public bool GetRankedTaxonomy ( OnGetRankedTaxonomy callback , string source , bool includeSourceText = false , string customData = default ( string ) )
1312
1264
{
1313
1265
if ( callback == null )
1314
1266
throw new ArgumentNullException ( "callback" ) ;
@@ -1323,7 +1275,7 @@ private void OnGetTargetedSentimentResponse(RESTConnector.Request req, RESTConne
1323
1275
1324
1276
req . Parameters [ "apikey" ] = mp_ApiKey ;
1325
1277
req . Parameters [ "outputMode" ] = "json" ;
1326
- req . Parameters [ "showSourceText" ] = Convert . ToInt32 ( showSourceText ) . ToString ( ) ;
1278
+ req . Parameters [ "showSourceText" ] = Convert . ToInt32 ( includeSourceText ) . ToString ( ) ;
1327
1279
1328
1280
req . Headers [ "Content-Type" ] = "application/x-www-form-urlencoded" ;
1329
1281
req . Forms = new Dictionary < string , RESTConnector . Form > ( ) ;
@@ -1627,7 +1579,7 @@ private void OnGetTitleResponse(RESTConnector.Request req, RESTConnector.Respons
1627
1579
public delegate void OnGetCombinedData ( CombinedCallData combinedData , string data ) ;
1628
1580
1629
1581
public bool GetCombinedData ( OnGetCombinedData callback , string source ,
1630
- bool showSourceText = false ,
1582
+ bool includeSourceText = false ,
1631
1583
bool extractAuthors = false ,
1632
1584
bool extractConcepts = true ,
1633
1585
bool extractDates = false ,
@@ -1672,7 +1624,7 @@ public bool GetCombinedData(OnGetCombinedData callback, string source,
1672
1624
1673
1625
req . Parameters [ "apikey" ] = mp_ApiKey ;
1674
1626
req . Parameters [ "outputMode" ] = "json" ;
1675
- req . Parameters [ "showSourceText" ] = Convert . ToInt32 ( showSourceText ) . ToString ( ) ;
1627
+ req . Parameters [ "showSourceText" ] = Convert . ToInt32 ( includeSourceText ) . ToString ( ) ;
1676
1628
1677
1629
List < string > requestServices = new List < string > ( ) ;
1678
1630
if ( extractAuthors )
0 commit comments