Skip to content

Commit 2485f9e

Browse files
committed
delete custom corpora
1 parent 9321bf0 commit 2485f9e

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

Examples/ServiceExamples/Scripts/ExampleSpeechToText.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,12 @@ private void TestGetCustomCorpora(string customizationID)
106106
m_SpeechToText.GetCustomCorpora(HandleGetCustopmCorpora, customizationID);
107107
}
108108

109+
private void TestDeleteCustomCorpora(string customizationID, string corpusName)
110+
{
111+
Log.Debug("ExampleSpeechToText", "Attempting to delete custom corpora {1} in customization {0}", customizationID, corpusName);
112+
m_SpeechToText.DeleteCustomCorpora(HandleDeleteCustomCorpora, customizationID, corpusName);
113+
}
114+
109115
private void HandleGetModels(Model[] models)
110116
{
111117
if (models != null)
@@ -309,4 +315,19 @@ private void HandleGetCustopmCorpora(Corpora corpora, string customData)
309315
Log.Debug("ExampleSpeechToText", "Failed to get custom corpora!");
310316
}
311317
}
318+
319+
private void HandleDeleteCustomCorpora(bool success, string customData)
320+
{
321+
if (!string.IsNullOrEmpty(customData))
322+
Log.Debug("ExampleSpeechToText", "custom data: {0}", customData);
323+
324+
if (success)
325+
{
326+
Log.Debug("ExampleSpeechToText", "DeleteCustomCorpora() succeeded!");
327+
}
328+
else
329+
{
330+
Log.Debug("ExampleSpeechToText", "Failed to delete custom corpora!");
331+
}
332+
}
312333
}

Scripts/Services/SpeechToText/SpeechToText.cs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1313,6 +1313,59 @@ private void OnGetCustomCorporaResp(RESTConnector.Request req, RESTConnector.Res
13131313
#endregion
13141314

13151315
#region Delete Custom Corpora
1316+
/// <summary>
1317+
/// This callback is used by the DeleteCustomCorpora() function.
1318+
/// </summary>
1319+
/// <param name="success"></param>
1320+
/// <param name="data"></param>
1321+
public delegate void OnDeleteCustomCorporaCallback(bool success, string data);
1322+
/// <summary>
1323+
/// Deletes an existing corpus from a custom language model. The service removes any out-of-vocabulary (OOV) words associated with the corpus from the custom model's words resource unless they were also added by another corpus or they have been modified in some way with the POST /v1/customizations/{customization_id}/words or PUT /v1/customizations/{customization_id}/words/{word_name} method. Removing a corpus does not affect the custom model until you train the model with the POST /v1/customizations/{customization_id}/train method. Only the owner of a custom model can use this method to delete a corpus from the model.
1324+
/// Note: This method is currently a beta release that is available for US English only.
1325+
/// </summary>
1326+
/// <param name="callback">The callback.</param>
1327+
/// <param name="customizationID">The customization ID with the corpus to be deleted.</param>
1328+
/// <param name="corpusName">The corpus name to be deleted.</param>
1329+
/// <param name="customData">Optional customization data.</param>
1330+
/// <returns></returns>
1331+
public bool DeleteCustomCorpora(OnDeleteCustomCorporaCallback callback, string customizationID, string corpusName, string customData = default(string))
1332+
{
1333+
if (callback == null)
1334+
throw new ArgumentNullException("callback");
1335+
if (string.IsNullOrEmpty(customizationID))
1336+
throw new ArgumentNullException("A customizationID is required for DeleteCustomCorpora.");
1337+
if (string.IsNullOrEmpty(corpusName))
1338+
throw new ArgumentNullException("A corpusName to delete is required to DeleteCustomCorpora.");
1339+
1340+
DeleteCustomCorporaRequest req = new DeleteCustomCorporaRequest();
1341+
req.Callback = callback;
1342+
req.CustomizationID = customizationID;
1343+
req.CorpusName = corpusName;
1344+
req.Data = customData;
1345+
req.Delete = true;
1346+
req.OnResponse = OnDeleteCustomizationResp;
1347+
1348+
string service = "/v1/customizations/{0}/corpora/{1}";
1349+
RESTConnector connector = RESTConnector.GetConnector(SERVICE_ID, string.Format(service, customizationID, corpusName));
1350+
if (connector == null)
1351+
return false;
1352+
1353+
return connector.Send(req);
1354+
}
1355+
1356+
private class DeleteCustomCorporaRequest : RESTConnector.Request
1357+
{
1358+
public OnDeleteCustomCorporaCallback Callback { get; set; }
1359+
public string CustomizationID { get; set; }
1360+
public string CorpusName { get; set; }
1361+
public string Data { get; set; }
1362+
}
1363+
1364+
private void OnDeleteCustomCorpraResp(RESTConnector.Request req, RESTConnector.Response resp)
1365+
{
1366+
if (((DeleteCustomCorporaRequest)req).Callback != null)
1367+
((DeleteCustomCorporaRequest)req).Callback(resp.Success, ((DeleteCustomCorporaRequest)req).Data);
1368+
}
13161369
#endregion
13171370

13181371
#region Add Custom Corpora

0 commit comments

Comments
 (0)