Skip to content

Instantly share code, notes, and snippets.

@mssfang
Last active July 8, 2021 06:14
Show Gist options
  • Save mssfang/3db2e855fc32f908de6de61d145217b8 to your computer and use it in GitHub Desktop.
Save mssfang/3db2e855fc32f908de6de61d145217b8 to your computer and use it in GitHub Desktop.

API

PollerFlux<AnalyzeActionsOperationDetail, AnalyzeActionsResultPagedFlux> beginAnalyzeActions(Iterable<TextDocumentInput> documents, TextAnalyticsActions actions, AnalyzeActionsOptions options) 
SyncPoller<AnalyzeActionsOperationDetail, AnalyzeActionsResultPagedIterable> beginAnalyzeActions(Iterable<TextDocumentInput> documents, TextAnalyticsActions actions, AnalyzeActionsOptions options, Context context) 

Example:

{ 
  "displayName": "Custom Text Jobs", 
  "analysisInput": { 
    "documents": [ 
      { 
        "id": "1", 
        "text": "The government of British Prime Minster Theresa May has been plunged into turmoil with the resignation of two senior Cabinet ministers in a deep split over her Brexit strategy.  The Foreign Secretary Boris Johnson, quit on Monday, hours after the resignation late on Sunday night of the minister in charge of Brexit negotiations, David Davis.  Their decision to leave the government came three days after May appeared to have agreed a deal with her fractured Cabinet on the UK's post-Brexit relationship with the EU.  That plan is now in tatters and her political future appears uncertain.  May appeared in Parliament on Monday afternoon to defend her plan, minutes after Downing Street confirmed the departure of Johnson.  May acknowledged the splits in her statement to MPs, saying of the ministers who quit: \"We do not agree about the best way of delivering our shared commitment to honoring the result of the referendum.\"  The Prime Minister's latest plitical drama began late on Sunday night when Davis quit, declaring he could not support May's Brexit plan.  He said it involved too close a relationship with the EU and gave only an illusion of control being returned to the UK after it left the EU.  \"It seems to me we're giving too much away, too easily, and that's a dangerous strategy at this time,\" Davis said in a BBC radio interview Monday morning.  Johnson's resignation came Monday afternoon local time, just before the Prime Minister was due to make a scheduled statement in Parliament.  \"This afternoon, the Prime Minister accepted the resignation of Boris Johnson as Foreign Secretary,\" a statement from Downing Street said." 
      } 
    ] 
  }, 
  "tasks": { 
    "customEntitiesTasks": [ 
      { 
          "stringIndexType": "UnicodeCodePoint", 
          "projectName": "project_name", 
          "deploymentName": "deployment_name" 
      } 
    ], 
    "customClassificationTasks": [ 
      { 
          "projectName": "project_name", 
          "deploymentName": "deployment_name" 
      } 
    ], 
    "customMultiClassificationTasks": [ 
      { 
          "projectName": "project_name", 
          "deploymentName": "deployment_name" 
      } 
    ] 
  } 
} 
  
{ 
  "displayName": "Custom Text Jobs", 
  "jobId": "49e8b199-2a07-40e3-9207-cc16f6917909", 
  "lastUpdateDateTime": "2021-03-18T20:11:01Z", 
  "createdDateTime": "2021-03-18T20:10:57Z", 
  "expirationDateTime": "2021-03-19T20:10:57Z", 
  "status": "succeeded", 
  "errors": [], 
  "tasks": { 
    "details": { 
      "name": "Custom Text Jobs", 
      "lastUpdateDateTime": "2021-03-18T20:11:01Z" 
    }, 
    "completed": 3, 
    "failed": 0, 
    "inProgress": 0, 
    "total": 3, 
    "customEntitiesTasks": [ 
      {
        "lastUpdateDateTime": "2021-03-18T20:11:01.2235829Z", 
        "name": "Custom Text Jobs", 
        "state": "succeeded", 
        "results": { 
          "documents": [ 
              { 
                  "id": "1", 
                  "entities": [ 
                    { 
                        "text": "Boris Johnson", 
                        "category": "Politician", 
                        "offset": "178", 
                        "length": "13", 
                        "confidenceScore": 0.87 
                    }, 
                    { 
                        "text": "Parliament", 
                        "category": "Governmental Building",  
                        "offset": "591", 
                        "length": "10", 
                        "confidenceScore": 0.68 
                    }                  ], 
                  "warnings": [] 
              } 
          ], 
          "errors": [], 
        } 
      } 
    ], 
    "customClassificationTasks": [ 
      { 
        "lastUpdateDateTime": "2021-03-18T20:11:01.2235829Z", 
        "name": "Custom Text Jobs", 
        "state": "succeeded", 
        "results": { 
          "documents": [ 
              { 
                  "id": "1", 
                  "classification": { 
                        "category": "Politics", 
                        "confidenceScore": 0.87 
                  }, 
                  "warnings": [] 
              } 
          ], 
          "errors": [], 
        } 
      } 
    ], 
    "customMultiClassificationTasks": [ 
      { 
        "lastUpdateDateTime": "2021-03-18T20:11:01.2235829Z", 
        "name": "Custom Text Jobs", 
        "state": "succeeded", 
        "results": { 
          "documents": [ 
              { 
                  "id": "1", 
                  "classifications": [ 
                    { 
                        "category": "Politics", 
                        "confidenceScore": 0.87 
                    }, 
                    { 
                        "category": "Europe", 
                        "confidenceScore": 0.65 
                    } 
            ], 
                  "warnings": [] 
              } 
          ], 
          "errors": [], 
        } 
      } 
    ] 
  } 
}   

Custom NER

Input:

TextAnalyticsActions {
  ...
  Iterable<RecognizeCustomEntitiesAction> getRecognizeCustomEntitiesActions() 
  TextAnalyticsActions setRecognizeCustomEntitiesActions(RecognizeCustomEntitiesAction... recognizeCustomEntitiesActions) 
}
RecognizeCustomEntitiesAction {
  StringIndexType stringIndexType
  String projectName
  String modelName
}

Output:

AnalyzeActionsResult {
  IterableStream<RecognizeCustomEntitiesActionResult> getRecognizeCustomEntitiesResults() 
}
RecognizeCustomEntitiesActionResult extends TextAnalyticsActionResult {
  RecognizeCustomEntitiesResultCollection getDocumentsResults() 
}
RecognizeCustomEntitiesResultCollection extends IterableStream<RecognizeCustomEntitiesResult> {
  RecognizeCustomEntitiesResultCollection(Iterable<RecognizeCustomEntitiesResult> documentResults, String modelVersion, TextDocumentBatchStatistics statistics) 
  String getModelVersion() 
  TextDocumentBatchStatistics getStatistics() 
}
RecognizeCustomEntitiesResult extends TextAnalyticsResult {
  RecognizeCustomEntitiesResult(String id, TextDocumentStatistics textDocumentStatistics, TextAnalyticsError error, CustomEntityCollection entities) 
  CustomEntityCollection getEntities() 
}
CustomEntityCollection extends IterableStream<CustomEntity> {
  CustomEntityCollection(IterableStream<CustomEntity> entities, IterableStream<TextAnalyticsWarning> warnings) 
  IterableStream<TextAnalyticsWarning> getWarnings() 
}
CustomEntity {
  // Text="Boris Johnson", category="Politician"
  CustomEntityCategory getCategory() // enums
  double getConfidenceScore() 
  int getLength() 
  int getOffset() 
  String getSubcategory() 
  String getText() 
}

Text Classification - Single label

Input

TextAnalyticsActions {
  ...
  Iterable<RecognizeClassficationAction> getRecognizeClassficationActions() 
  TextAnalyticsActions setRecognizeClassficationActions(RecognizeClassficationAction... recognizeClassficationActions) 
}
RecognizeClassficationAction {
  String projectName
  String modelName
}

Output

AnalyzeActionsResult {
  IterableStream<RecognizeClassificationActionResult> getRecognizeClassificationResults() 
}
RecognizeClassificationActionResult extends TextAnalyticsActionResult {
  RecognizeClassificationResultCollection getDocumentsResults() 
}
// batch documents
RecognizeClassificationResultCollection extends IterableStream<RecognizeClassificationResult> {
  RecognizeClassificationResultCollection(Iterable<RecognizeClassificationResult> documentResults, String modelVersion, TextDocumentBatchStatistics statistics) 
  String getModelVersion() 
  TextDocumentBatchStatistics getStatistics() 
}
// per document
RecognizeClassificationResult extends TextAnalyticsResult {
  RecognizeClassificationResult(String id, TextDocumentStatistics textDocumentStatistics, TextAnalyticsError error) 
  DocumentClassification getDocumentClassfication();
}

Text classification - Multiple Label

Input

TextAnalyticsActions {
  ...
  Iterable<RecognizeClassficationCollectionAction> getRecognizeClassficationCollectionActions() 
  TextAnalyticsActions setRecognizeClassficationCollectionActions(RecognizeClassficationCollectionAction... recognizeClassficationCollectionActions) 
}
RecognizeClassficationCollectionAction {
  String projectName
  String modelName
}

Output

AnalyzeActionsResult {
  IterableStream<RecognizeClassificationCollectionActionResult> getRecognizeClassificationCollectionResults() 
}
RecognizeClassificationCollectionActionResult extends TextAnalyticsActionResult {
  RecognizeClassificationCollectionResultCollection getDocumentsResults() 
}
RecognizeClassificationCollectionResultCollection extends IterableStream<RecognizeClassificationCollectionResult> {
  RecognizeClassificationCollectionResultCollection(Iterable<RecognizeClassificationCollectionResult> documentResults, String modelVersion, TextDocumentBatchStatistics statistics) 
  String getModelVersion() 
  TextDocumentBatchStatistics getStatistics() 
}
RecognizeClassificationCollectionResult extends TextAnalyticsResult {
  RecognizeClassificationCollectionResult(String id, TextDocumentStatistics textDocumentStatistics, TextAnalyticsError error) 
  IterableStream<DocumentClassification> getDocumentClassfications(); // "Politics", "Europe"
}  
DocumentClassification {
  ClassificationCategory getCategrory() // enums. e.g., "Politics"
  double getConfidenceScore() 
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment