Skip to content

Commit 7d6b11e

Browse files
authored
[FR] flatten TextStyle's properties in TextAppearance (Azure#21197)
* flatten TextStyle's properties in TextAppearance
1 parent 1b4d183 commit 7d6b11e

File tree

13 files changed

+229
-153
lines changed

13 files changed

+229
-153
lines changed

sdk/formrecognizer/azure-ai-formrecognizer/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@
55
- Renamed `ReadingOrder` model to `FormReadingOrder`.
66
- Renamed the method names and the method parameters, using `identity` to replace `id` keyword in the identity documents recognition API.
77
For example, renamed `beginRecognizeIdDocuments` to `beginRecognizeIdentityDocuments`.
8+
- The model `TextAppearance` now includes the properties `styleName` and `styleConfidence` that were part of the `TextStyle` object.
9+
- Removed the model `TextStyle`.
10+
- Removed `V2_1_PREVIEW_1` and `V2_1_PREVIEW_2` but only support latest service beta API version `V2_1_PREVIEW_3`.
11+
12+
### New features
13+
- Added `clientOptions` method to the `FormRecognizerClientBuilder` and `FormTrainingClientBuilder`.
14+
- Added `getDefaultLogOptions` method to the `FormRecognizerClientBuilder`.
15+
- We are able to support multiple service API versions now: `V2_0` and `V2_1_PREVIEW_3`.
816

917
## 3.0.7 (2021-04-07)
1018
### Dependency updates

sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/Transforms.java

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@
33

44
package com.azure.ai.formrecognizer;
55

6-
import com.azure.ai.formrecognizer.implementation.TextAppearanceHelper;
76
import com.azure.ai.formrecognizer.implementation.FormLineHelper;
87
import com.azure.ai.formrecognizer.implementation.FormPageHelper;
98
import com.azure.ai.formrecognizer.implementation.FormSelectionMarkHelper;
109
import com.azure.ai.formrecognizer.implementation.FormTableHelper;
1110
import com.azure.ai.formrecognizer.implementation.RecognizedFormHelper;
12-
import com.azure.ai.formrecognizer.implementation.TextStyleHelper;
11+
import com.azure.ai.formrecognizer.implementation.TextAppearanceHelper;
1312
import com.azure.ai.formrecognizer.implementation.models.AnalyzeResult;
1413
import com.azure.ai.formrecognizer.implementation.models.DocumentResult;
1514
import com.azure.ai.formrecognizer.implementation.models.FieldValue;
@@ -20,7 +19,6 @@
2019
import com.azure.ai.formrecognizer.implementation.models.SelectionMarkState;
2120
import com.azure.ai.formrecognizer.implementation.models.TextLine;
2221
import com.azure.ai.formrecognizer.implementation.models.TextWord;
23-
import com.azure.ai.formrecognizer.models.TextAppearance;
2422
import com.azure.ai.formrecognizer.models.FieldBoundingBox;
2523
import com.azure.ai.formrecognizer.models.FieldData;
2624
import com.azure.ai.formrecognizer.models.FieldValueType;
@@ -36,7 +34,7 @@
3634
import com.azure.ai.formrecognizer.models.LengthUnit;
3735
import com.azure.ai.formrecognizer.models.Point;
3836
import com.azure.ai.formrecognizer.models.RecognizedForm;
39-
import com.azure.ai.formrecognizer.models.TextStyle;
37+
import com.azure.ai.formrecognizer.models.TextAppearance;
4038
import com.azure.ai.formrecognizer.models.TextStyleName;
4139
import com.azure.core.util.CoreUtils;
4240
import com.azure.core.util.logging.ClientLogger;
@@ -54,7 +52,6 @@
5452

5553
import static com.azure.ai.formrecognizer.implementation.Utility.forEachWithIndex;
5654
import static com.azure.ai.formrecognizer.implementation.models.FieldValueType.ARRAY;
57-
import static com.azure.ai.formrecognizer.implementation.models.FieldValueType.OBJECT;
5855

5956
/**
6057
* Helper class to convert service level models to SDK exposed models.
@@ -275,21 +272,20 @@ static List<FormLine> getReadResultFormLines(ReadResult readResultItem) {
275272

276273
/**
277274
* Private method to get the appearance from the service side text line object.
275+
*
278276
* @param textLine The service side text line object.
279-
* @return the custom type Appearance model.
277+
* @return the custom type TextAppearance model.
280278
*/
281279
private static TextAppearance getTextAppearance(TextLine textLine) {
282-
TextStyle textStyle = new TextStyle();
280+
TextAppearance textAppearance = new TextAppearance();
283281
if (textLine.getAppearance() != null && textLine.getAppearance().getStyle() != null) {
284282
if (textLine.getAppearance().getStyle().getName() != null) {
285-
TextStyleHelper.setName(textStyle,
283+
TextAppearanceHelper.setStyleName(textAppearance,
286284
TextStyleName.fromString(textLine.getAppearance().getStyle().getName().toString()));
287285
}
288-
TextStyleHelper.setConfidence(textStyle, textLine.getAppearance().getStyle().getConfidence());
286+
TextAppearanceHelper.setStyleConfidence(textAppearance,
287+
textLine.getAppearance().getStyle().getConfidence());
289288
}
290-
291-
TextAppearance textAppearance = new TextAppearance();
292-
TextAppearanceHelper.setStyle(textAppearance, textStyle);
293289
return textAppearance;
294290
}
295291

sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/implementation/TextAppearanceHelper.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
package com.azure.ai.formrecognizer.implementation;
55

66
import com.azure.ai.formrecognizer.models.TextAppearance;
7-
import com.azure.ai.formrecognizer.models.TextStyle;
7+
import com.azure.ai.formrecognizer.models.TextStyleName;
88

99
/**
1010
* The helper class to set the non-public properties of an {@link TextAppearance} instance.
@@ -18,19 +18,24 @@ private TextAppearanceHelper() { }
1818
* Type defining the methods to set the non-public properties of an {@link TextAppearance} instance.
1919
*/
2020
public interface TextAppearanceAccessor {
21-
void setStyle(TextAppearance textAppearance, TextStyle textStyle);
21+
void setStyleName(TextAppearance textAppearance, TextStyleName styleName);
22+
void setStyleConfidence(TextAppearance textAppearance, float styleConfidence);
2223
}
2324

2425
/**
2526
* The method called from {@link TextAppearance} to set it's accessor.
2627
*
27-
* @param styleAccessor The accessor.
28+
* @param textAppearanceAccessor The accessor.
2829
*/
29-
public static void setAccessor(final TextAppearanceAccessor styleAccessor) {
30-
accessor = styleAccessor;
30+
public static void setAccessor(final TextAppearanceAccessor textAppearanceAccessor) {
31+
accessor = textAppearanceAccessor;
3132
}
3233

33-
public static void setStyle(TextAppearance textAppearance, TextStyle textStyle) {
34-
accessor.setStyle(textAppearance, textStyle);
34+
public static void setStyleName(TextAppearance textAppearance, TextStyleName styleName) {
35+
accessor.setStyleName(textAppearance, styleName);
36+
}
37+
38+
public static void setStyleConfidence(TextAppearance textAppearance, float styleConfidence) {
39+
accessor.setStyleConfidence(textAppearance, styleConfidence);
3540
}
3641
}

sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/implementation/TextStyleHelper.java

Lines changed: 0 additions & 41 deletions
This file was deleted.

sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/models/TextAppearance.java

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,66 @@
88
/** The TextAppearance model representing the appearance of the text line. */
99
public final class TextAppearance {
1010
/*
11-
* An object representing the style of the text line.
11+
* The text line style name, including handwriting and other.
1212
*/
13-
private TextStyle style;
13+
private TextStyleName styleName;
14+
15+
/*
16+
* The confidence of text line style.
17+
*/
18+
private float styleConfidence;
1419

1520
static {
1621
TextAppearanceHelper.setAccessor(new TextAppearanceHelper.TextAppearanceAccessor() {
1722
@Override
18-
public void setStyle(TextAppearance textAppearance, TextStyle textStyle) {
19-
textAppearance.setStyle(textStyle);
23+
public void setStyleConfidence(TextAppearance textAppearance, float styleConfidence) {
24+
textAppearance.setStyleConfidence(styleConfidence);
25+
}
26+
27+
@Override
28+
public void setStyleName(TextAppearance textAppearance, TextStyleName styleName) {
29+
textAppearance.setStyleName(styleName);
2030
}
2131
});
2232
}
2333

2434
/**
25-
* Get the style of the text line.
35+
* Get the text line style name. Possible values include handwriting and other.
36+
*
37+
* @return the style name value.
38+
*/
39+
public TextStyleName getStyleName() {
40+
return this.styleName;
41+
}
42+
43+
/**
44+
* Private setter to set the text line style name, including handwriting and other.
45+
*
46+
* @param styleName the style name value to set.
47+
* @return the TextAppearance object itself.
48+
*/
49+
private TextAppearance setStyleName(TextStyleName styleName) {
50+
this.styleName = styleName;
51+
return this;
52+
}
53+
54+
/**
55+
* Get the confidence of the recognized text line style.
2656
*
27-
* @return the style value.
57+
* @return the confidence value.
2858
*/
29-
public TextStyle getStyle() {
30-
return this.style;
59+
public float getStyleConfidence() {
60+
return this.styleConfidence;
3161
}
3262

3363
/**
34-
* Private setter to set an object representing the style of the text line.
64+
* Private setter to set the confidence of text line style.
3565
*
36-
* @param style the style value to set.
37-
* @return the Appearance object itself.
66+
* @param styleConfidence the style confidence value to set.
67+
* @return the TextAppearance object itself.
3868
*/
39-
private TextAppearance setStyle(TextStyle style) {
40-
this.style = style;
69+
private TextAppearance setStyleConfidence(float styleConfidence) {
70+
this.styleConfidence = styleConfidence;
4171
return this;
4272
}
4373
}

sdk/formrecognizer/azure-ai-formrecognizer/src/main/java/com/azure/ai/formrecognizer/models/TextStyle.java

Lines changed: 0 additions & 73 deletions
This file was deleted.

sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/RecognizeContent.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ public static void main(final String[] args) throws IOException {
7171
System.out.printf(
7272
"Line %s consists of %d words and has a text style %s with a confidence score of %.2f.%n",
7373
formLine.getText(), formLine.getWords().size(),
74-
formLine.getAppearance().getStyle().getName(),
75-
formLine.getAppearance().getStyle().getConfidence());
74+
formLine.getAppearance().getStyleName(),
75+
formLine.getAppearance().getStyleConfidence());
7676
}
7777
});
7878
}

sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/RecognizeContentFromUrlAsync.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ public static void main(final String[] args) {
7373
System.out.printf(
7474
"Line %s consists of %d words and has a text style %s with a confidence score of %.2f.%n",
7575
formLine.getText(), formLine.getWords().size(),
76-
formLine.getAppearance().getStyle().getName(),
77-
formLine.getAppearance().getStyle().getConfidence());
76+
formLine.getAppearance().getStyleName(),
77+
formLine.getAppearance().getStyleConfidence());
7878
}
7979
});
8080
}

sdk/formrecognizer/azure-ai-formrecognizer/src/samples/java/com/azure/ai/formrecognizer/RecognizeContentWithSelectionMarks.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ public static void main(final String[] args) throws IOException {
7979
System.out.printf(
8080
"Line %s consists of %d words and has a text style %s with a confidence score of %.2f.%n",
8181
formLine.getText(), formLine.getWords().size(),
82-
formLine.getAppearance().getStyle().getName(),
83-
formLine.getAppearance().getStyle().getConfidence());
82+
formLine.getAppearance().getStyleName(),
83+
formLine.getAppearance().getStyleConfidence());
8484
}
8585
});
8686
}

sdk/formrecognizer/azure-ai-formrecognizer/src/test/java/com/azure/ai/formrecognizer/FormRecognizerAsyncClientTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ public void recognizeContentAppearance(HttpClient httpClient, FormRecognizerServ
515515
List<FormPage> formPages = syncPoller.getFinalResult();
516516
validateContentResultData(formPages, false);
517517
assertEquals(TextStyleName.OTHER,
518-
formPages.get(0).getLines().get(0).getAppearance().getStyle().getName());
518+
formPages.get(0).getLines().get(0).getAppearance().getStyleName());
519519
}, FORM_JPG);
520520
}
521521

0 commit comments

Comments
 (0)