Skip to content

Commit

Permalink
[Text Translation] Updating to the latest TypeSpec (#40035)
Browse files Browse the repository at this point in the history
* Update to latest TypeSpec

* Convinienc methods

* format

* Async change

* Languages Scopes

* Using latest typespec

* Fix build

* Fixing PR comments

* Using the latest TypeSpec

* Using public typespec reference

* Fix build

* Fix

* Attempt to fix lint

* Adding package-info.java file

* fix build

* Fixing PR comments

* Fixing PR comments

* Using latest TypeSpec

* Fix lint

---------

Co-authored-by: Michal Materna <mimat@microsoft.com>
  • Loading branch information
MikeyMCZ and Michal Materna committed May 17, 2024
1 parent 229378b commit d0a6cb7
Show file tree
Hide file tree
Showing 56 changed files with 2,394 additions and 1,482 deletions.
2 changes: 1 addition & 1 deletion eng/versioning/version_client.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ com.azure:azure-ai-openai-assistants;1.0.0-beta.2;1.0.0-beta.3
com.azure:azure-ai-personalizer;1.0.0-beta.1;1.0.0-beta.2
com.azure:azure-ai-textanalytics;5.4.5;5.5.0-beta.1
com.azure:azure-ai-textanalytics-perf;1.0.0-beta.1;1.0.0-beta.1
com.azure:azure-ai-translation-text;1.0.0-beta.1;1.0.0-beta.2
com.azure:azure-ai-translation-text;1.0.0-beta.1;1.0.0
com.azure:azure-analytics-defender-easm;1.0.0-beta.1;1.0.0-beta.2
com.azure:azure-analytics-purview-catalog;1.0.0-beta.4;1.0.0-beta.5
com.azure:azure-analytics-purview-datamap;1.0.0-beta.1;1.0.0-beta.2
Expand Down
11 changes: 10 additions & 1 deletion sdk/translation/azure-ai-translation-text/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
# Release History

## 1.0.0-beta.2 (Unreleased)
## 1.0.0 (Unreleased)

### Features Added

- Added support for AAD authentication for Text Translation endpoints.
- Ability to translate strings directly without a need to create instances of objects.
- Options pattern used for methods with too many parameters.

### Breaking Changes

- Method `getSentLen` renamed to `getSentencesLengths`.
- `String` can be used for translate, transliterate, find sentence boundaries methods instead of `InputTextItem`.
- `GetLanguages*` classes and definitions were renamed to `GetSupportedLanguages*`.
- `getProj` method renamed to `getProjections`.
- `Translation` class renamed to `TranslationText`.
- `getScore` method renamed to `getConfidence`.

### Bugs Fixed

### Other Changes
Expand Down
53 changes: 20 additions & 33 deletions sdk/translation/azure-ai-translation-text/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Various documentation is available to help you get started
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-ai-translation-text</artifactId>
<version>1.0.0-beta.1</version>
<version>1.0.0</version>
</dependency>
```
[//]: # ({x-version-update-end})
Expand Down Expand Up @@ -96,7 +96,7 @@ The following section provides several code snippets using the `client` [created
Gets the set of languages currently supported by other operations of the Translator.

```java getTextTranslationLanguages
GetLanguagesResult languages = client.getLanguages();
GetSupportedLanguagesResult languages = client.getSupportedLanguages();

System.out.println("Number of supported languages for translate operation: " + languages.getTranslation().size() + ".");
System.out.println("Number of supported languages for transliterate operation: " + languages.getTransliteration().size() + ".");
Expand Down Expand Up @@ -125,18 +125,14 @@ Please refer to the service documentation for a conceptual discussion of [langua
Renders single source-language text to multiple target-language texts with a single request.

```java getTextTranslationMultiple
String from = "en";
List<String> targetLanguages = new ArrayList<>();
targetLanguages.add("cs");
List<InputTextItem> content = new ArrayList<>();
content.add(new InputTextItem("This is a test."));

List<TranslatedTextItem> translations = client.translate(targetLanguages, content, null, from, TextType.PLAIN, null, ProfanityAction.NO_ACTION, ProfanityMarker.ASTERISK, false, false, null, null, null, false);

for (TranslatedTextItem translation : translations) {
for (Translation textTranslation : translation.getTranslations()) {
System.out.println("Text was translated to: '" + textTranslation.getTo() + "' and the result is: '" + textTranslation.getText() + "'.");
}
TranslateOptions translateOptions = new TranslateOptions()
.setSourceLanguage("en")
.addTargetLanguage("es");

TranslatedTextItem translation = client.translate("This is a test.", translateOptions);

for (TranslationText textTranslation : translation.getTranslations()) {
System.out.println("Text was translated to: '" + textTranslation.getTargetLanguage() + "' and the result is: '" + textTranslation.getText() + "'.");
}
```

Expand All @@ -150,14 +146,11 @@ Converts characters or letters of a source language to the corresponding charact
String language = "zh-Hans";
String fromScript = "Hans";
String toScript = "Latn";
List<InputTextItem> content = new ArrayList<>();
content.add(new InputTextItem("这是个测试。"));
String content = "这是个测试。";

List<TransliteratedText> transliterations = client.transliterate(language, fromScript, toScript, content);
TransliteratedText transliteration = client.transliterate(language, fromScript, toScript, content);

for (TransliteratedText transliteration : transliterations) {
System.out.println("Input text was transliterated to '" + transliteration.getScript() + "' script. Transliterated text: '" + transliteration.getText() + "'.");
}
System.out.println("Input text was transliterated to '" + transliteration.getScript() + "' script. Transliterated text: '" + transliteration.getText() + "'.");
```

Please refer to the service documentation for a conceptual discussion of [transliterate][transliterate_doc].
Expand All @@ -169,14 +162,11 @@ Identifies the positioning of sentence boundaries in a piece of text.
```java getTextTranslationSentenceBoundaries
String sourceLanguage = "zh-Hans";
String sourceScript = "Latn";
List<InputTextItem> content = new ArrayList<>();
content.add(new InputTextItem("zhè shì gè cè shì。"));
String content = "zhè shì gè cè shì。";

List<BreakSentenceItem> breakSentences = client.findSentenceBoundaries(content, null, sourceLanguage, sourceScript);
BreakSentenceItem breakSentence = client.findSentenceBoundaries(content, sourceLanguage, sourceScript);

for (BreakSentenceItem breakSentence : breakSentences) {
System.out.println("The detected sentence boundaries: " + breakSentence.getSentLen());
}
System.out.println("The detected sentence boundaries: " + breakSentence.getSentencesLengths());
```

Please refer to the service documentation for a conceptual discussion of [break sentence][breaksentence_doc].
Expand All @@ -188,15 +178,12 @@ Returns equivalent words for the source term in the target language.
```java getTextTranslationDictionaryLookup
String sourceLanguage = "en";
String targetLanguage = "es";
List<InputTextItem> content = new ArrayList<>();
content.add(new InputTextItem("fly"));
String content = "fly";

List<DictionaryLookupItem> dictionaryEntries = client.lookupDictionaryEntries(sourceLanguage, targetLanguage, content);
DictionaryLookupItem dictionaryEntry = client.lookupDictionaryEntries(sourceLanguage, targetLanguage, content);

for (DictionaryLookupItem dictionaryEntry : dictionaryEntries) {
System.out.println("For the given input " + dictionaryEntry.getTranslations().size() + " entries were found in the dictionary.");
System.out.println("First entry: '" + dictionaryEntry.getTranslations().get(0).getDisplayTarget() + "', confidence: " + dictionaryEntry.getTranslations().get(0).getConfidence());
}
System.out.println("For the given input " + dictionaryEntry.getTranslations().size() + " entries were found in the dictionary.");
System.out.println("First entry: '" + dictionaryEntry.getTranslations().get(0).getDisplayTarget() + "', confidence: " + dictionaryEntry.getTranslations().get(0).getConfidence());
```

Please refer to the service documentation for a conceptual discussion of [dictionary lookup][dictionarylookup_doc].
Expand Down
2 changes: 1 addition & 1 deletion sdk/translation/azure-ai-translation-text/assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"AssetsRepo": "Azure/azure-sdk-assets",
"AssetsRepoPrefixPath": "java",
"TagPrefix": "java/translation/azure-ai-translation-text",
"Tag": "java/translation/azure-ai-translation-text_09668e5176"
"Tag": "java/translation/azure-ai-translation-text_a2b0c1776a"
}
7 changes: 1 addition & 6 deletions sdk/translation/azure-ai-translation-text/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<groupId>com.azure</groupId>
<artifactId>azure-ai-translation-text</artifactId>
<version>1.0.0-beta.2</version> <!-- {x-version-update;com.azure:azure-ai-translation-text;current} -->
<version>1.0.0</version> <!-- {x-version-update;com.azure:azure-ai-translation-text;current} -->

<name>Microsoft Azure client library for Text Translation</name>
<description>This package contains Microsoft Azure Text Translation client library.</description>
Expand Down Expand Up @@ -49,11 +49,6 @@
<artifactId>azure-core</artifactId>
<version>1.49.0</version> <!-- {x-version-update;com.azure:azure-core;dependency} -->
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core-experimental</artifactId>
<version>1.0.0-beta.50</version> <!-- {x-version-update;com.azure:azure-core-experimental;dependency} -->
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core-http-netty</artifactId>
Expand Down

0 comments on commit d0a6cb7

Please sign in to comment.