Skip to content

Commit 610e932

Browse files
authored
[FormRecognizer] 4.1.0-beta.1: implemented methods to get and list Document Classifiers (Azure#35244)
1 parent d0cd6c2 commit 610e932

27 files changed

+344
-54
lines changed

sdk/formrecognizer/Azure.AI.FormRecognizer/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## 4.1.0-beta.1 (Unreleased)
44

55
### Features Added
6+
- Added methods in `DocumentModelAdministrationClient` to support custom document classification: `BuildDocumentClassifier`, `GetDocumentClassifier`, `GetDocumentClassifiers`, and `DeleteDocumentClassifier`.
67

78
### Breaking Changes
89

sdk/formrecognizer/Azure.AI.FormRecognizer/api/Azure.AI.FormRecognizer.netstandard2.0.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,10 @@ public DocumentModelAdministrationClient(System.Uri endpoint, Azure.Core.TokenCr
629629
public virtual System.Threading.Tasks.Task<Azure.Response> DeleteDocumentModelAsync(string modelId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
630630
public virtual Azure.Response<Azure.AI.FormRecognizer.DocumentAnalysis.DocumentModelCopyAuthorization> GetCopyAuthorization(string modelId = null, string description = null, System.Collections.Generic.IDictionary<string, string> tags = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
631631
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.AI.FormRecognizer.DocumentAnalysis.DocumentModelCopyAuthorization>> GetCopyAuthorizationAsync(string modelId = null, string description = null, System.Collections.Generic.IDictionary<string, string> tags = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
632+
public virtual Azure.Response<Azure.AI.FormRecognizer.DocumentAnalysis.DocumentClassifierDetails> GetDocumentClassifier(string classifierId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
633+
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.AI.FormRecognizer.DocumentAnalysis.DocumentClassifierDetails>> GetDocumentClassifierAsync(string classifierId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
634+
public virtual Azure.Pageable<Azure.AI.FormRecognizer.DocumentAnalysis.DocumentClassifierDetails> GetDocumentClassifiers(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
635+
public virtual Azure.AsyncPageable<Azure.AI.FormRecognizer.DocumentAnalysis.DocumentClassifierDetails> GetDocumentClassifiersAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
632636
public virtual Azure.Response<Azure.AI.FormRecognizer.DocumentAnalysis.DocumentModelDetails> GetDocumentModel(string modelId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
633637
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.AI.FormRecognizer.DocumentAnalysis.DocumentModelDetails>> GetDocumentModelAsync(string modelId, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
634638
public virtual Azure.Pageable<Azure.AI.FormRecognizer.DocumentAnalysis.DocumentModelSummary> GetDocumentModels(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }

sdk/formrecognizer/Azure.AI.FormRecognizer/src/DocumentModelAdministrationClient.cs

Lines changed: 167 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace Azure.AI.FormRecognizer.DocumentAnalysis
1717
/// properties.
1818
/// </summary>
1919
/// <remarks>
20-
/// This client only works with <see cref="DocumentAnalysisClientOptions.ServiceVersion.V2022_08_31"/> and up.
20+
/// This client only works with <see cref="DocumentAnalysisClientOptions.ServiceVersion.V2022_08_31"/> and newer.
2121
/// If you want to use a lower version, please use the <see cref="Training.FormTrainingClient"/>.
2222
/// </remarks>
2323
public class DocumentModelAdministrationClient
@@ -392,7 +392,7 @@ public virtual async Task<Response> DeleteDocumentModelAsync(string modelId, Can
392392
}
393393

394394
/// <summary>
395-
/// Gets a collection of items describing the models available on this Cognitive Services Account.
395+
/// Gets a collection of items describing the models available on this Form Recognizer resource.
396396
/// </summary>
397397
/// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param>
398398
/// <returns>A collection of <see cref="DocumentModelSummary"/> items.</returns>
@@ -436,7 +436,7 @@ Page<DocumentModelSummary> NextPageFunc(string nextLink, int? pageSizeHint)
436436
}
437437

438438
/// <summary>
439-
/// Gets a collection of items describing the models available on this Cognitive Services Account.
439+
/// Gets a collection of items describing the models available on this Form Recognizer resource.
440440
/// </summary>
441441
/// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param>
442442
/// <returns>A collection of <see cref="DocumentModelSummary"/> items.</returns>
@@ -981,6 +981,9 @@ internal static List<ComponentDocumentModelDetails> ConvertToComponentModelDetai
981981
/// A <see cref="BuildDocumentClassifierOperation"/> to wait on this long-running operation. Its Value upon successful
982982
/// completion will contain meta-data about the created document classifier.
983983
/// </returns>
984+
/// <remarks>
985+
/// This method is only available for <see cref="DocumentAnalysisClientOptions.ServiceVersion.V2023_02_28_Preview"/> and newer.
986+
/// </remarks>
984987
public virtual BuildDocumentClassifierOperation BuildDocumentClassifier(WaitUntil waitUntil, IDictionary<string, ClassifierDocumentTypeDetails> documentTypes, string classifierId = default, string description = default, CancellationToken cancellationToken = default)
985988
{
986989
Argument.AssertNotNullOrEmpty(documentTypes, nameof(documentTypes));
@@ -1031,6 +1034,9 @@ public virtual BuildDocumentClassifierOperation BuildDocumentClassifier(WaitUnti
10311034
/// A <see cref="BuildDocumentClassifierOperation"/> to wait on this long-running operation. Its Value upon successful
10321035
/// completion will contain meta-data about the created document classifier.
10331036
/// </returns>
1037+
/// <remarks>
1038+
/// This method is only available for <see cref="DocumentAnalysisClientOptions.ServiceVersion.V2023_02_28_Preview"/> and newer.
1039+
/// </remarks>
10341040
public virtual async Task<BuildDocumentClassifierOperation> BuildDocumentClassifierAsync(WaitUntil waitUntil, IDictionary<string, ClassifierDocumentTypeDetails> documentTypes, string classifierId = default, string description = default, CancellationToken cancellationToken = default)
10351041
{
10361042
Argument.AssertNotNullOrEmpty(documentTypes, nameof(documentTypes));
@@ -1063,12 +1069,167 @@ public virtual async Task<BuildDocumentClassifierOperation> BuildDocumentClassif
10631069
}
10641070
}
10651071

1072+
/// <summary>
1073+
/// Gets information about a document classifier, including the types of documents it can identify.
1074+
/// </summary>
1075+
/// <param name="classifierId">The ID of the classifier to retrieve.</param>
1076+
/// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param>
1077+
/// <returns>A <see cref="Response{T}"/> representing the result of the operation. It can be cast to a <see cref="DocumentClassifierDetails"/> containing
1078+
/// information about the requested classifier.</returns>
1079+
/// <remarks>
1080+
/// This method is only available for <see cref="DocumentAnalysisClientOptions.ServiceVersion.V2023_02_28_Preview"/> and newer.
1081+
/// </remarks>
1082+
public virtual Response<DocumentClassifierDetails> GetDocumentClassifier(string classifierId, CancellationToken cancellationToken = default)
1083+
{
1084+
Argument.AssertNotNullOrEmpty(classifierId, nameof(classifierId));
1085+
1086+
using DiagnosticScope scope = Diagnostics.CreateScope($"{nameof(DocumentModelAdministrationClient)}.{nameof(GetDocumentClassifier)}");
1087+
scope.Start();
1088+
1089+
try
1090+
{
1091+
Response<DocumentClassifierDetails> response = ServiceClient.DocumentClassifiersGetClassifier(classifierId, cancellationToken);
1092+
return Response.FromValue(response.Value, response.GetRawResponse());
1093+
}
1094+
catch (Exception e)
1095+
{
1096+
scope.Failed(e);
1097+
throw;
1098+
}
1099+
}
1100+
1101+
/// <summary>
1102+
/// Gets information about a document classifier, including the types of documents it can identify.
1103+
/// </summary>
1104+
/// <param name="classifierId">The ID of the classifier to retrieve.</param>
1105+
/// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param>
1106+
/// <returns>A <see cref="Response{T}"/> representing the result of the operation. It can be cast to a <see cref="DocumentClassifierDetails"/> containing
1107+
/// information about the requested classifier.</returns>
1108+
/// <remarks>
1109+
/// This method is only available for <see cref="DocumentAnalysisClientOptions.ServiceVersion.V2023_02_28_Preview"/> and newer.
1110+
/// </remarks>
1111+
public virtual async Task<Response<DocumentClassifierDetails>> GetDocumentClassifierAsync(string classifierId, CancellationToken cancellationToken = default)
1112+
{
1113+
Argument.AssertNotNullOrEmpty(classifierId, nameof(classifierId));
1114+
1115+
using DiagnosticScope scope = Diagnostics.CreateScope($"{nameof(DocumentModelAdministrationClient)}.{nameof(GetDocumentClassifier)}");
1116+
scope.Start();
1117+
1118+
try
1119+
{
1120+
Response<DocumentClassifierDetails> response = await ServiceClient.DocumentClassifiersGetClassifierAsync(classifierId, cancellationToken).ConfigureAwait(false);
1121+
return Response.FromValue(response.Value, response.GetRawResponse());
1122+
}
1123+
catch (Exception e)
1124+
{
1125+
scope.Failed(e);
1126+
throw;
1127+
}
1128+
}
1129+
1130+
/// <summary>
1131+
/// Gets a collection of items describing the document classifiers available on this Form Recognizer resource.
1132+
/// </summary>
1133+
/// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param>
1134+
/// <returns>A collection of <see cref="DocumentClassifierDetails"/> items.</returns>
1135+
/// <remarks>
1136+
/// This method is only available for <see cref="DocumentAnalysisClientOptions.ServiceVersion.V2023_02_28_Preview"/> and newer.
1137+
/// </remarks>
1138+
public virtual Pageable<DocumentClassifierDetails> GetDocumentClassifiers(CancellationToken cancellationToken = default)
1139+
{
1140+
Page<DocumentClassifierDetails> FirstPageFunc(int? pageSizeHint)
1141+
{
1142+
using DiagnosticScope scope = Diagnostics.CreateScope($"{nameof(DocumentModelAdministrationClient)}.{nameof(GetDocumentClassifiers)}");
1143+
scope.Start();
1144+
1145+
try
1146+
{
1147+
Response<GetDocumentClassifiersResponse> response = ServiceClient.DocumentClassifiersListClassifiers(cancellationToken);
1148+
return Page.FromValues(response.Value.Value, response.Value.NextLink?.AbsoluteUri, response.GetRawResponse());
1149+
}
1150+
catch (Exception e)
1151+
{
1152+
scope.Failed(e);
1153+
throw;
1154+
}
1155+
}
1156+
1157+
Page<DocumentClassifierDetails> NextPageFunc(string nextLink, int? pageSizeHint)
1158+
{
1159+
using DiagnosticScope scope = Diagnostics.CreateScope($"{nameof(DocumentModelAdministrationClient)}.{nameof(GetDocumentClassifiers)}");
1160+
scope.Start();
1161+
1162+
try
1163+
{
1164+
Response<GetDocumentClassifiersResponse> response = ServiceClient.DocumentClassifiersListClassifiersNextPage(nextLink, cancellationToken);
1165+
return Page.FromValues(response.Value.Value, response.Value.NextLink?.AbsoluteUri, response.GetRawResponse());
1166+
}
1167+
catch (Exception e)
1168+
{
1169+
scope.Failed(e);
1170+
throw;
1171+
}
1172+
}
1173+
1174+
return PageableHelpers.CreateEnumerable(FirstPageFunc, NextPageFunc);
1175+
}
1176+
1177+
/// <summary>
1178+
/// Gets a collection of items describing the document classifiers available on this Form Recognizer resource.
1179+
/// </summary>
1180+
/// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param>
1181+
/// <returns>A collection of <see cref="DocumentClassifierDetails"/> items.</returns>
1182+
/// <remarks>
1183+
/// This method is only available for <see cref="DocumentAnalysisClientOptions.ServiceVersion.V2023_02_28_Preview"/> and newer.
1184+
/// </remarks>
1185+
public virtual AsyncPageable<DocumentClassifierDetails> GetDocumentClassifiersAsync(CancellationToken cancellationToken = default)
1186+
{
1187+
async Task<Page<DocumentClassifierDetails>> FirstPageFunc(int? pageSizeHint)
1188+
{
1189+
using DiagnosticScope scope = Diagnostics.CreateScope($"{nameof(DocumentModelAdministrationClient)}.{nameof(GetDocumentClassifiers)}");
1190+
scope.Start();
1191+
1192+
try
1193+
{
1194+
Response<GetDocumentClassifiersResponse> response = await ServiceClient.DocumentClassifiersListClassifiersAsync(cancellationToken).ConfigureAwait(false);
1195+
return Page.FromValues(response.Value.Value, response.Value.NextLink?.AbsoluteUri, response.GetRawResponse());
1196+
}
1197+
catch (Exception e)
1198+
{
1199+
scope.Failed(e);
1200+
throw;
1201+
}
1202+
}
1203+
1204+
async Task<Page<DocumentClassifierDetails>> NextPageFunc(string nextLink, int? pageSizeHint)
1205+
{
1206+
using DiagnosticScope scope = Diagnostics.CreateScope($"{nameof(DocumentModelAdministrationClient)}.{nameof(GetDocumentClassifiers)}");
1207+
scope.Start();
1208+
1209+
try
1210+
{
1211+
Response<GetDocumentClassifiersResponse> response = await ServiceClient.DocumentClassifiersListClassifiersNextPageAsync(nextLink, cancellationToken).ConfigureAwait(false);
1212+
return Page.FromValues(response.Value.Value, response.Value.NextLink?.AbsoluteUri, response.GetRawResponse());
1213+
}
1214+
catch (Exception e)
1215+
{
1216+
scope.Failed(e);
1217+
throw;
1218+
}
1219+
}
1220+
1221+
return PageableHelpers.CreateAsyncEnumerable(FirstPageFunc, NextPageFunc);
1222+
}
1223+
10661224
/// <summary>
10671225
/// Deletes the document classifier with the specified classifier ID.
10681226
/// </summary>
10691227
/// <param name="classifierId">The ID of the document classifier to delete.</param>
10701228
/// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param>
10711229
/// <returns>A <see cref="Response"/> representing the result of the operation.</returns>
1230+
/// <remarks>
1231+
/// This method is only available for <see cref="DocumentAnalysisClientOptions.ServiceVersion.V2023_02_28_Preview"/> and newer.
1232+
/// </remarks>
10721233
public virtual Response DeleteDocumentClassifier(string classifierId, CancellationToken cancellationToken = default)
10731234
{
10741235
Argument.AssertNotNullOrEmpty(classifierId, nameof(classifierId));
@@ -1093,6 +1254,9 @@ public virtual Response DeleteDocumentClassifier(string classifierId, Cancellati
10931254
/// <param name="classifierId">The ID of the document classifier to delete.</param>
10941255
/// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param>
10951256
/// <returns>A <see cref="Response"/> representing the result of the operation.</returns>
1257+
/// <remarks>
1258+
/// This method is only available for <see cref="DocumentAnalysisClientOptions.ServiceVersion.V2023_02_28_Preview"/> and newer.
1259+
/// </remarks>
10961260
public virtual async Task<Response> DeleteDocumentClassifierAsync(string classifierId, CancellationToken cancellationToken = default)
10971261
{
10981262
Argument.AssertNotNullOrEmpty(classifierId, nameof(classifierId));

sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormRecognizerClient/FieldValue.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ public IReadOnlyDictionary<string, FormField> AsDictionary()
414414
/// <returns>The value of the field converted to <see cref="SelectionMarkState"/>.</returns>
415415
/// <exception cref="InvalidOperationException">Thrown when <see cref="ValueType"/> is not <see cref="FieldValueType.SelectionMark"/>.</exception>
416416
/// <remarks>
417-
/// This method is only available for <see cref="FormRecognizerClientOptions.ServiceVersion.V2_1"/> and up.
417+
/// This method is only available for <see cref="FormRecognizerClientOptions.ServiceVersion.V2_1"/> and newer.
418418
/// </remarks>
419419
public SelectionMarkState AsSelectionMarkState()
420420
{

sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormRecognizerClient/FieldValueType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public enum FieldValueType
6161
/// Used for <see cref="SelectionMarkState"/> type.
6262
/// </summary>
6363
/// <remarks>
64-
/// This property only has value for <see cref="FormRecognizerClientOptions.ServiceVersion.V2_1"/> and up.
64+
/// This property only has value for <see cref="FormRecognizerClientOptions.ServiceVersion.V2_1"/> and newer.
6565
/// </remarks>
6666
SelectionMark,
6767

sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormRecognizerClient/FormContentType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public enum FormContentType
3737
/// Used for BMP files.
3838
/// </summary>
3939
/// <remarks>
40-
/// This property only has value for <see cref="FormRecognizerClientOptions.ServiceVersion.V2_1"/> and up.
40+
/// This property only has value for <see cref="FormRecognizerClientOptions.ServiceVersion.V2_1"/> and newer.
4141
/// </remarks>
4242
Bmp
4343
}

sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormRecognizerClient/FormLine.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ internal FormLine(FieldBoundingBox boundingBox, int pageNumber, string text, IRe
4141
/// An object representing the appearance of the text line.
4242
/// </summary>
4343
/// <remarks>
44-
/// This property only has value for <see cref="FormRecognizerClientOptions.ServiceVersion.V2_1"/> and up.
44+
/// This property only has value for <see cref="FormRecognizerClientOptions.ServiceVersion.V2_1"/> and newer.
4545
/// </remarks>
4646
public TextAppearance Appearance { get; }
4747

sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormRecognizerClient/FormPage.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ internal FormPage(int pageNumber, float width, float height, float textAngle, Le
103103
/// A list of recognized selection marks contained in this page.
104104
/// </summary>
105105
/// <remarks>
106-
/// This property only has value for <see cref="FormRecognizerClientOptions.ServiceVersion.V2_1"/> and up.
106+
/// This property only has value for <see cref="FormRecognizerClientOptions.ServiceVersion.V2_1"/> and newer.
107107
/// </remarks>
108108
public IReadOnlyList<FormSelectionMark> SelectionMarks { get; }
109109

sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormRecognizerClient/FormRecognizerClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace Azure.AI.FormRecognizer
1919
/// In order to use later versions and their new features, see <see cref="DocumentAnalysis.DocumentAnalysisClient"/>.
2020
/// </summary>
2121
/// <remarks>
22-
/// Client is only available for <see cref="FormRecognizerClientOptions.ServiceVersion.V2_1"/> and lower.
22+
/// Client is only available for <see cref="FormRecognizerClientOptions.ServiceVersion.V2_1"/> and older.
2323
/// </remarks>
2424
public class FormRecognizerClient
2525
{

sdk/formrecognizer/Azure.AI.FormRecognizer/src/FormRecognizerClient/FormTable.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ internal FormTable(int pageNumber, int columnCount, int rowCount, IReadOnlyList<
6363

6464
/// <summary> Bounding box of the table. </summary>
6565
/// <remarks>
66-
/// This property only has value for <see cref="FormRecognizerClientOptions.ServiceVersion.V2_1"/> and up.
66+
/// This property only has value for <see cref="FormRecognizerClientOptions.ServiceVersion.V2_1"/> and newer.
6767
/// </remarks>
6868
public FieldBoundingBox BoundingBox { get; }
6969

0 commit comments

Comments
 (0)