Skip to content

Commit

Permalink
[TA and Translatior] Update snippets (#20552)
Browse files Browse the repository at this point in the history
  • Loading branch information
maririos authored Apr 21, 2021
1 parent 2aa289c commit 402c776
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,27 @@ public partial class Snippets: SamplesBase<TextAnalyticsTestEnvironment>
[Test]
public void CreateTextAnalyticsClient()
{
#region Snippet:CreateTextAnalyticsClient
#if SNIPPET
string endpoint = "<endpoint>";
string apiKey = "<apiKey>";
#else
string endpoint = TestEnvironment.Endpoint;
string apiKey = TestEnvironment.ApiKey;

#region Snippet:CreateTextAnalyticsClient
//@@ string endpoint = "<endpoint>";
//@@ string apiKey = "<apiKey>";
#endif
var client = new TextAnalyticsClient(new Uri(endpoint), new AzureKeyCredential(apiKey));
#endregion
}

[Test]
public void CreateTextAnalyticsClientTokenCredential()
{
string endpoint = TestEnvironment.Endpoint;

#region Snippet:CreateTextAnalyticsClientTokenCredential
//@@ string endpoint = "<endpoint>";
#if SNIPPET
string endpoint = "<endpoint>";
#else
string endpoint = TestEnvironment.Endpoint;
#endif
var client = new TextAnalyticsClient(new Uri(endpoint), new DefaultAzureCredential());
#endregion
}
Expand Down
37 changes: 19 additions & 18 deletions sdk/translation/Azure.AI.Translation.Document/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,19 +94,19 @@ To start a translation operation you need to create one instance or a list of `D
A single source URL to documents can be translated to many different languages:

```C# Snippet:DocumentTranslationSingleInput
Uri sourceSasUri = <source SAS URI>;
Uri frenchTargetSasUri = <french target SAS URI>;
Uri sourceSasUri = new Uri("<source SAS URI>");
Uri frenchTargetSasUri = new Uri("<french target SAS URI>");

var input = new DocumentTranslationInput(sourceSasUri, frenchTargetSasUri, "fr");
```

Or multiple different sources can be provided each with their own targets.

```C# Snippet:DocumentTranslationMultipleInputs
Uri source1SasUri = <source1 SAS URI>;
Uri source2SasUri = <source2 SAS URI>;
Uri frenchTargetSasUri = <french target SAS URI>;
Uri spanishTargetSasUri = <spanish target SAS URI>;
Uri arabicTargetSasUri = new Uri("<arabic target SAS URI>");
Uri spanishTargetSasUri = new Uri("<spanish target SAS URI>");
Uri source1SasUri = new Uri("<source1 SAS URI>");
Uri source2SasUri = new Uri("<source2 SAS URI>");

var inputs = new List<DocumentTranslationInput>
{
Expand All @@ -116,7 +116,7 @@ var inputs = new List<DocumentTranslationInput>
targets: new List<TranslationTarget>
{
new TranslationTarget(frenchTargetSasUri, "fr"),
new TranslationTarget(spanishTargetSasUri, "es")
new TranslationTarget(arabicTargetSasUri, "ar")
}),
};
```
Expand Down Expand Up @@ -160,8 +160,8 @@ Note: our `DocumentTranslationClient` provides both synchronous and asynchronous
Start a translation operation to translate documents in the source container and write the translated files to the target container. `DocumentTranslationOperation` allows you to poll the status of the translation operation and get the status of the individual documents.

```C# Snippet:StartTranslationAsync
Uri sourceUri = <source SAS URI>;
Uri targetUri = <target SAS URI>;
Uri sourceUri = new Uri("<source SAS URI>");
Uri targetUri = new Uri("<target SAS URI>");

var input = new DocumentTranslationInput(sourceUri, targetUri, "es");

Expand Down Expand Up @@ -232,12 +232,13 @@ Console.WriteLine($"Cancelled Documents: {docsCancelled}");
Start a translation operation to translate documents in multiple source containers to multiple target containers in different languages. `DocumentTranslationOperation` allows you to poll the status of the translation operation and get the status of the individual documents.

```C# Snippet:MultipleInputsAsync
Uri source1SasUriUri = <source1 SAS URI>;
Uri source2SasUri = <source2 SAS URI>;
Uri frenchTargetSasUri = <french target SAS URI>;
Uri arabicTargetSasUri = <arabic target SAS URI>;
Uri spanishTargetSasUri = <spanish target SAS URI>;
Uri frenchGlossarySasUri = <french glossary SAS URI>;
Uri source1SasUriUri = new Uri("<source1 SAS URI>");
Uri source2SasUri = new Uri("<source2 SAS URI>");
Uri frenchTargetSasUri = new Uri("<french target SAS URI>");
Uri arabicTargetSasUri = new Uri("<arabic target SAS URI>");
Uri spanishTargetSasUri = new Uri("<spanish target SAS URI>");
Uri frenchGlossarySasUri = new Uri("<french glossary SAS URI>");

var glossaryFormat = "TSV";

var input1 = new DocumentTranslationInput(source1SasUriUri, frenchTargetSasUri, "fr", new TranslationGlossary(frenchGlossarySasUri, glossaryFormat));
Expand Down Expand Up @@ -279,8 +280,8 @@ await foreach (DocumentStatusResult document in operation.GetValuesAsync())
Start a translation operation to translate documents in the source container and write the translated files to the target container. `DocumentTranslationOperation` allows you to poll the status of the translation operation and get the status of the individual documents.

```C# Snippet:StartTranslation
Uri sourceUri = <source SAS URI>;
Uri targetUri = <target SAS URI>;
Uri sourceUri = new Uri("<source SAS URI>");
Uri targetUri = new Uri("<target SAS URI>");

var input = new DocumentTranslationInput(sourceUri, targetUri, "es");

Expand Down Expand Up @@ -342,7 +343,7 @@ When you interact with the Cognitive Services Document Translation client librar
For example, if you submit a request with an empty targets list, a `400` error is returned, indicating "Bad Request".

```C# Snippet:BadRequest
var invalidInput = new DocumentTranslationInput(new TranslationSource(sourceSasUri, new List<TranslationTarget>());
var invalidInput = new DocumentTranslationInput(new TranslationSource(new Uri(endpoint)), new List<TranslationTarget>());

try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ To call `StartTranslationAsync` you need to initialize an object of type `Docume
More on generating SAS Tokens [here](https://docs.microsoft.com/azure/cognitive-services/translator/document-translation/get-started-with-document-translation?tabs=csharp#create-sas-access-tokens-for-document-translation)

```C# Snippet:StartTranslationAsync
Uri sourceUri = <source SAS URI>;
Uri targetUri = <target SAS URI>;
Uri sourceUri = new Uri("<source SAS URI>");
Uri targetUri = new Uri("<target SAS URI>");

var input = new DocumentTranslationInput(sourceUri, targetUri, "es");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ var client = new DocumentTranslationClient(new Uri(endpoint), new AzureKeyCreden
To poll the status of documents in an operation you use the `DocumentTranslationOperation` class which contains two functions `GetAllDocumentsStatusAsync` which returns the status of all documents in the operation and `GetDocumentStatusAsync` which returns the status of a specific document given its ID.

```C# Snippet:PollIndividualDocumentsAsync
Uri sourceUri = <source SAS URI>;
Uri targetUri = <target SAS URI>;
Uri sourceUri = new Uri("<source SAS URI>");
Uri targetUri = new Uri("<target SAS URI>");

var input = new DocumentTranslationInput(sourceUri, targetUri, "es");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ To call `StartTranslationAsync` you need to initialize a list of `DocumentTransl
More on generating SAS Tokens [here](https://docs.microsoft.com/azure/cognitive-services/translator/document-translation/get-started-with-document-translation?tabs=csharp#create-sas-access-tokens-for-document-translation)

```C# Snippet:MultipleInputsAsync
Uri source1SasUriUri = <source1 SAS URI>;
Uri source2SasUri = <source2 SAS URI>;
Uri frenchTargetSasUri = <french target SAS URI>;
Uri arabicTargetSasUri = <arabic target SAS URI>;
Uri spanishTargetSasUri = <spanish target SAS URI>;
Uri frenchGlossarySasUri = <french glossary SAS URI>;
Uri source1SasUriUri = new Uri("<source1 SAS URI>");
Uri source2SasUri = new Uri("<source2 SAS URI>");
Uri frenchTargetSasUri = new Uri("<french target SAS URI>");
Uri arabicTargetSasUri = new Uri("<arabic target SAS URI>");
Uri spanishTargetSasUri = new Uri("<spanish target SAS URI>");
Uri frenchGlossarySasUri = new Uri("<french glossary SAS URI>");

var glossaryFormat = "TSV";

var input1 = new DocumentTranslationInput(source1SasUriUri, frenchTargetSasUri, "fr", new TranslationGlossary(frenchGlossarySasUri, glossaryFormat));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ public partial class SampleSnippets : SamplesBase<DocumentTranslationTestEnviron
[Ignore("Samples not working yet")]
public void CreateDocumentTranslationClient()
{
#region Snippet:CreateDocumentTranslationClient
#if SNIPPET
string endpoint = "<endpoint>";
string apiKey = "<apiKey>";
#else
string endpoint = TestEnvironment.Endpoint;
string apiKey = TestEnvironment.ApiKey;

#region Snippet:CreateDocumentTranslationClient
//@@ string endpoint = "<endpoint>";
//@@ string apiKey = "<apiKey>";
#endif
var client = new DocumentTranslationClient(new Uri(endpoint), new AzureKeyCredential(apiKey));
#endregion
}
Expand All @@ -32,17 +34,18 @@ public void CreateDocumentTranslationClient()
[Ignore("Samples not working yet")]
public void BadRequestSnippet()
{
#if SNIPPET
string endpoint = "<endpoint>";
#else
string endpoint = TestEnvironment.Endpoint;
#endif
string apiKey = TestEnvironment.ApiKey;

var credentials = new AzureKeyCredential(apiKey);
var client = new DocumentTranslationClient(new Uri(endpoint), credentials);

var invalidInput = new DocumentTranslationInput(new TranslationSource(new Uri(endpoint)), new List<TranslationTarget>());

#region Snippet:BadRequest

//@@ var invalidInput = new DocumentTranslationInput(new TranslationSource(sourceSasUri, new List<TranslationTarget>());
var invalidInput = new DocumentTranslationInput(new TranslationSource(new Uri(endpoint)), new List<TranslationTarget>());

try
{
Expand All @@ -59,27 +62,19 @@ public void BadRequestSnippet()
[Ignore("Samples not working yet")]
public void DocumentTranslationInput()
{
#region Snippet:DocumentTranslationSingleInput
Uri sourceSasUri = new Uri("<source SAS URI>");
Uri frenchTargetSasUri = new Uri("<french target SAS URI>");
Uri arabicTargetSasUri = new Uri("<arabic target SAS URI>");
Uri spanishTargetSasUri = new Uri("<spanish target SAS URI>");

#region Snippet:DocumentTranslationSingleInput
//@@ Uri sourceSasUri = <source SAS URI>;
//@@ Uri frenchTargetSasUri = <french target SAS URI>;

var input = new DocumentTranslationInput(sourceSasUri, frenchTargetSasUri, "fr");
#endregion

#region Snippet:DocumentTranslationMultipleInputs
Uri arabicTargetSasUri = new Uri("<arabic target SAS URI>");
Uri spanishTargetSasUri = new Uri("<spanish target SAS URI>");
Uri source1SasUri = new Uri("<source1 SAS URI>");
Uri source2SasUri = new Uri("<source2 SAS URI>");

#region Snippet:DocumentTranslationMultipleInputs
//@@ Uri source1SasUri = <source1 SAS URI>;
//@@ Uri source2SasUri = <source2 SAS URI>;
//@@ Uri frenchTargetSasUri = <french target SAS URI>;
//@@ Uri spanishTargetSasUri = <spanish target SAS URI>;

var inputs = new List<DocumentTranslationInput>
{
new DocumentTranslationInput(source1SasUri, spanishTargetSasUri, "es"),
Expand All @@ -88,7 +83,7 @@ public void DocumentTranslationInput()
targets: new List<TranslationTarget>
{
new TranslationTarget(frenchTargetSasUri, "fr"),
new TranslationTarget(spanishTargetSasUri, "es")
new TranslationTarget(arabicTargetSasUri, "ar")
}),
};
#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,14 @@ public void MultipleInputs()

var client = new DocumentTranslationClient(new Uri(endpoint), new AzureKeyCredential(apiKey));

#region Snippet:MultipleInputs
Uri source1SasUriUri = new Uri("<source1 SAS URI>");
Uri source2SasUri = new Uri("<source2 SAS URI>");
Uri frenchTargetSasUri = new Uri("<french target SAS URI>");
Uri arabicTargetSasUri = new Uri("<arabic target SAS URI>");
Uri spanishTargetSasUri = new Uri("<spanish target SAS URI>");
Uri frenchGlossarySasUri = new Uri("<french glossary SAS URI>");

#region Snippet:MultipleInputs

//@@ Uri source1SasUriUri = <source1 SAS URI>;
//@@ Uri source2SasUri = <source2 SAS URI>;
//@@ Uri frenchTargetSasUri = <french target SAS URI>;
//@@ Uri arabicTargetSasUri = <arabic target SAS URI>;
//@@ Uri spanishTargetSasUri = <spanish target SAS URI>;
//@@ Uri frenchGlossarySasUri = <french glossary SAS URI>;
var glossaryFormat = "TSV";

var input1 = new DocumentTranslationInput(source1SasUriUri, frenchTargetSasUri, "fr", new TranslationGlossary(frenchGlossarySasUri, glossaryFormat));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,14 @@ public async Task MultipleInputsAsync()

var client = new DocumentTranslationClient(new Uri(endpoint), new AzureKeyCredential(apiKey));

#region Snippet:MultipleInputsAsync
Uri source1SasUriUri = new Uri("<source1 SAS URI>");
Uri source2SasUri = new Uri("<source2 SAS URI>");
Uri frenchTargetSasUri = new Uri("<french target SAS URI>");
Uri arabicTargetSasUri = new Uri("<arabic target SAS URI>");
Uri spanishTargetSasUri = new Uri("<spanish target SAS URI>");
Uri frenchGlossarySasUri = new Uri("<french glossary SAS URI>");

#region Snippet:MultipleInputsAsync

//@@ Uri source1SasUriUri = <source1 SAS URI>;
//@@ Uri source2SasUri = <source2 SAS URI>;
//@@ Uri frenchTargetSasUri = <french target SAS URI>;
//@@ Uri arabicTargetSasUri = <arabic target SAS URI>;
//@@ Uri spanishTargetSasUri = <spanish target SAS URI>;
//@@ Uri frenchGlossarySasUri = <french glossary SAS URI>;
var glossaryFormat = "TSV";

var input1 = new DocumentTranslationInput(source1SasUriUri, frenchTargetSasUri, "fr", new TranslationGlossary(frenchGlossarySasUri, glossaryFormat));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,10 @@ public void PollIndividualDocuments()

var client = new DocumentTranslationClient(new Uri(endpoint), new AzureKeyCredential(apiKey));

#region Snippet:PollIndividualDocuments
Uri sourceUri = new Uri("<source SAS URI>");
Uri targetUri = new Uri("<target SAS URI>");

#region Snippet:PollIndividualDocuments

//@@ Uri sourceUri = <source SAS URI>;
//@@ Uri targetUri = <target SAS URI>;

var input = new DocumentTranslationInput(sourceUri, targetUri, "es");
DocumentTranslationOperation operation = client.StartTranslation(input);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,10 @@ public async Task PollIndividualDocumentsAsync()

var client = new DocumentTranslationClient(new Uri(endpoint), new AzureKeyCredential(apiKey));

#region Snippet:PollIndividualDocumentsAsync
Uri sourceUri = new Uri("<source SAS URI>");
Uri targetUri = new Uri("<target SAS URI>");

#region Snippet:PollIndividualDocumentsAsync

//@@ Uri sourceUri = <source SAS URI>;
//@@ Uri targetUri = <target SAS URI>;

var input = new DocumentTranslationInput(sourceUri, targetUri, "es");

DocumentTranslationOperation operation = await client.StartTranslationAsync(input);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,10 @@ public void StartTranslation()

var client = new DocumentTranslationClient(new Uri(endpoint), new AzureKeyCredential(apiKey));

#region Snippet:StartTranslation
Uri sourceUri = new Uri("<source SAS URI>");
Uri targetUri = new Uri("<target SAS URI>");

#region Snippet:StartTranslation

//@@ Uri sourceUri = <source SAS URI>;
//@@ Uri targetUri = <target SAS URI>;

var input = new DocumentTranslationInput(sourceUri, targetUri, "es");

DocumentTranslationOperation operation = client.StartTranslation(input);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,10 @@ public async Task StartTranslationAsync()

var client = new DocumentTranslationClient(new Uri(endpoint), new AzureKeyCredential(apiKey));

#region Snippet:StartTranslationAsync
Uri sourceUri = new Uri("<source SAS URI>");
Uri targetUri = new Uri("<target SAS URI>");

#region Snippet:StartTranslationAsync

//@@ Uri sourceUri = <source SAS URI>;
//@@ Uri targetUri = <target SAS URI>;

var input = new DocumentTranslationInput(sourceUri, targetUri, "es");

DocumentTranslationOperation operation = await client.StartTranslationAsync(input);
Expand Down

0 comments on commit 402c776

Please sign in to comment.