Skip to content

Commit 562b245

Browse files
committed
feat(discovery v1): Added support for stopwords
1 parent 39509da commit 562b245

File tree

3 files changed

+314
-7
lines changed

3 files changed

+314
-7
lines changed

Examples/ServiceExamples/Scripts/ExampleDiscovery.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
using System;
2424
using System.Collections;
2525
using System.Collections.Generic;
26+
using System.IO;
2627
using UnityEngine;
2728
using Environment = IBM.Watson.DeveloperCloud.Services.Discovery.v1.Environment;
2829

@@ -92,11 +93,17 @@ public class ExampleDiscovery : MonoBehaviour
9293
private bool _getMetricsQueryTokenEventTested = false;
9394
private bool _queryLogTested = false;
9495

96+
private string _stopwordsFilepath;
97+
private bool _createStopwordListTested = false;
98+
private bool _deleteStopwordListTested = false;
99+
95100
private void Start()
96101
{
97102
LogSystem.InstallDefaultReactors();
98103
_filePathToIngest = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/watson_beats_jeopardy.html";
99104
_documentFilePath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/watson_beats_jeopardy.html";
105+
_stopwordsFilepath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/Discovery/stopwords.txt";
106+
100107
Runnable.Run(CreateService());
101108
}
102109

@@ -333,6 +340,22 @@ private IEnumerator Examples()
333340
while (!_isEnvironmentReady)
334341
yield return null;
335342

343+
// Create stopword list
344+
using (FileStream fs = File.OpenRead(_stopwordsFilepath))
345+
{
346+
347+
Log.Debug("TestDiscovery.RunTest()", "Attempting to create stopword list {0}", _createdCollectionId);
348+
_service.CreateStopwordList(OnCreateStopwordList, OnFail, _environmentId, _createdCollectionId, fs);
349+
while (!_createStopwordListTested)
350+
yield return null;
351+
}
352+
353+
// Delete stopword list
354+
Log.Debug("TestDiscovery.RunTest()", "Attempting to delete stopword list {0}", _createdCollectionId);
355+
_service.DeleteStopwordList(OnDeleteStopwordList, OnFail, _environmentId, _createdCollectionId);
356+
while (!_deleteStopwordListTested)
357+
yield return null;
358+
336359
// Delete Collection
337360
Log.Debug("ExampleDiscovery.RunTest()", "Attempting to delete collection {0}", _createdCollectionId);
338361
if (!_service.DeleteCollection(OnDeleteCollection, OnFail, _environmentId, _createdCollectionId))
@@ -579,6 +602,18 @@ private void OnQueryLog(LogQueryResponse response, Dictionary<string, object> cu
579602
_queryLogTested = true;
580603
}
581604

605+
private void OnCreateStopwordList(TokenDictStatusResponse response, Dictionary<string, object> customData)
606+
{
607+
Log.Debug("ExampleDiscovery.OnCreateStopwordList()", "Response: {0}", customData["json"].ToString());
608+
_createStopwordListTested = true;
609+
}
610+
611+
private void OnDeleteStopwordList(object response, Dictionary<string, object> customData)
612+
{
613+
Log.Debug("ExampleDiscovery.OnDeleteStopwordList()", "Success!");
614+
_deleteStopwordListTested = true;
615+
}
616+
582617
private void OnFail(RESTConnector.Error error, Dictionary<string, object> customData)
583618
{
584619
Log.Error("ExampleDiscovery.OnFail()", "Error received: {0}", error.ToString());

0 commit comments

Comments
 (0)