Chilkat Online Tools

DescribeDocumentClassifier Foxpro Example

Amazon Comprehend

LOCAL loRest
LOCAL lnSuccess
LOCAL loAuthAws
LOCAL loJson
LOCAL loSbRequestBody
LOCAL loSbResponseBody
LOCAL lnRespStatusCode
LOCAL loJResp
LOCAL lcAnnotationDataS3Uri
LOCAL lcDocumentType
LOCAL lcSourceDocumentsS3Uri
LOCAL lcSplit
LOCAL j
LOCAL lnCount_j
LOCAL lcStrVal
LOCAL lnAccuracy
LOCAL lnF1Score
LOCAL lnHammingLoss
LOCAL lnMicroF1Score
LOCAL lnMicroPrecision
LOCAL lnMicroRecall
LOCAL lnPrecision
LOCAL lnRecall
LOCAL lnNumberOfLabels
LOCAL lnNumberOfTestDocuments
LOCAL lnNumberOfTrainedDocuments
LOCAL lcDataAccessRoleArn
LOCAL lcDocumentClassifierArn
LOCAL lnEndTime
LOCAL lcDataFormat
LOCAL lcLabelDelimiter
LOCAL lcS3Uri
LOCAL lcTestS3Uri
LOCAL lcLanguageCode
LOCAL lcMessage
LOCAL lcMode
LOCAL lcModelKmsKeyId
LOCAL lcKmsKeyId
LOCAL lcOutputDataConfigS3Uri
LOCAL lcSourceModelArn
LOCAL lcStatus
LOCAL lnSubmitTime
LOCAL lnTrainingEndTime
LOCAL lnTrainingStartTime
LOCAL lcVersionName
LOCAL lcVolumeKmsKeyId
LOCAL i
LOCAL lnCount_i

* This example requires the Chilkat API to have been previously unlocked.
* See Global Unlock Sample for sample code.

loRest = CreateObject('Chilkat_9_5_0.Rest')

loAuthAws = CreateObject('Chilkat_9_5_0.AuthAws')
loAuthAws.AccessKey = "AWS_ACCESS_KEY"
loAuthAws.SecretKey = "AWS_SECRET_KEY"

* Don't forget to change the region to your particular region. (Also make the same change in the call to Connect below.)
loAuthAws.Region = "us-west-2"
loAuthAws.ServiceName = "comprehend"
* SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
loRest.SetAuthAws(loAuthAws)

* URL: https://comprehend.us-west-2.amazonaws.com/
* Use the same region as specified above.
lnSuccess = loRest.Connect("comprehend.us-west-2.amazonaws.com",443,1,1)
IF (lnSuccess <> 1) THEN
    ? "ConnectFailReason: " + STR(loRest.ConnectFailReason)
    ? loRest.LastErrorText
    RELEASE loRest
    RELEASE loAuthAws
    CANCEL
ENDIF

* The following code creates the JSON request body.
* The JSON created by this code is shown below.

* Use this online tool to generate code from sample JSON:
* Generate Code to Create JSON

loJson = CreateObject('Chilkat_9_5_0.JsonObject')
loJson.UpdateString("DocumentClassifierArn","string")

* The JSON request body created by the above code:

* {
*   "DocumentClassifierArn": "string"
* }

loRest.AddHeader("Content-Type","application/x-amz-json-1.1")
loRest.AddHeader("X-Amz-Target","Comprehend_20171127.DescribeDocumentClassifier")

loSbRequestBody = CreateObject('Chilkat_9_5_0.StringBuilder')
loJson.EmitSb(loSbRequestBody)
loSbResponseBody = CreateObject('Chilkat_9_5_0.StringBuilder')
lnSuccess = loRest.FullRequestSb("POST","/",loSbRequestBody,loSbResponseBody)
IF (lnSuccess <> 1) THEN
    ? loRest.LastErrorText
    RELEASE loRest
    RELEASE loAuthAws
    RELEASE loJson
    RELEASE loSbRequestBody
    RELEASE loSbResponseBody
    CANCEL
ENDIF

lnRespStatusCode = loRest.ResponseStatusCode
? "response status code = " + STR(lnRespStatusCode)
IF (lnRespStatusCode <> 200) THEN
    ? "Response Header:"
    ? loRest.ResponseHeader
    ? "Response Body:"
    ? loSbResponseBody.GetAsString()
    RELEASE loRest
    RELEASE loAuthAws
    RELEASE loJson
    RELEASE loSbRequestBody
    RELEASE loSbResponseBody
    CANCEL
ENDIF

loJResp = CreateObject('Chilkat_9_5_0.JsonObject')
loJResp.LoadSb(loSbResponseBody)

* The following code parses the JSON response.
* A sample JSON response is shown below the sample code.

* Use this online tool to generate parsing code from sample JSON:
* Generate Parsing Code from JSON

lnAccuracy = loJResp.IntOf("DocumentClassifierProperties.ClassifierMetadata.EvaluationMetrics.Accuracy")
lnF1Score = loJResp.IntOf("DocumentClassifierProperties.ClassifierMetadata.EvaluationMetrics.F1Score")
lnHammingLoss = loJResp.IntOf("DocumentClassifierProperties.ClassifierMetadata.EvaluationMetrics.HammingLoss")
lnMicroF1Score = loJResp.IntOf("DocumentClassifierProperties.ClassifierMetadata.EvaluationMetrics.MicroF1Score")
lnMicroPrecision = loJResp.IntOf("DocumentClassifierProperties.ClassifierMetadata.EvaluationMetrics.MicroPrecision")
lnMicroRecall = loJResp.IntOf("DocumentClassifierProperties.ClassifierMetadata.EvaluationMetrics.MicroRecall")
lnPrecision = loJResp.IntOf("DocumentClassifierProperties.ClassifierMetadata.EvaluationMetrics.Precision")
lnRecall = loJResp.IntOf("DocumentClassifierProperties.ClassifierMetadata.EvaluationMetrics.Recall")
lnNumberOfLabels = loJResp.IntOf("DocumentClassifierProperties.ClassifierMetadata.NumberOfLabels")
lnNumberOfTestDocuments = loJResp.IntOf("DocumentClassifierProperties.ClassifierMetadata.NumberOfTestDocuments")
lnNumberOfTrainedDocuments = loJResp.IntOf("DocumentClassifierProperties.ClassifierMetadata.NumberOfTrainedDocuments")
lcDataAccessRoleArn = loJResp.StringOf("DocumentClassifierProperties.DataAccessRoleArn")
lcDocumentClassifierArn = loJResp.StringOf("DocumentClassifierProperties.DocumentClassifierArn")
lnEndTime = loJResp.IntOf("DocumentClassifierProperties.EndTime")
lcDataFormat = loJResp.StringOf("DocumentClassifierProperties.InputDataConfig.DataFormat")
lcLabelDelimiter = loJResp.StringOf("DocumentClassifierProperties.InputDataConfig.LabelDelimiter")
lcS3Uri = loJResp.StringOf("DocumentClassifierProperties.InputDataConfig.S3Uri")
lcTestS3Uri = loJResp.StringOf("DocumentClassifierProperties.InputDataConfig.TestS3Uri")
lcLanguageCode = loJResp.StringOf("DocumentClassifierProperties.LanguageCode")
lcMessage = loJResp.StringOf("DocumentClassifierProperties.Message")
lcMode = loJResp.StringOf("DocumentClassifierProperties.Mode")
lcModelKmsKeyId = loJResp.StringOf("DocumentClassifierProperties.ModelKmsKeyId")
lcKmsKeyId = loJResp.StringOf("DocumentClassifierProperties.OutputDataConfig.KmsKeyId")
lcOutputDataConfigS3Uri = loJResp.StringOf("DocumentClassifierProperties.OutputDataConfig.S3Uri")
lcSourceModelArn = loJResp.StringOf("DocumentClassifierProperties.SourceModelArn")
lcStatus = loJResp.StringOf("DocumentClassifierProperties.Status")
lnSubmitTime = loJResp.IntOf("DocumentClassifierProperties.SubmitTime")
lnTrainingEndTime = loJResp.IntOf("DocumentClassifierProperties.TrainingEndTime")
lnTrainingStartTime = loJResp.IntOf("DocumentClassifierProperties.TrainingStartTime")
lcVersionName = loJResp.StringOf("DocumentClassifierProperties.VersionName")
lcVolumeKmsKeyId = loJResp.StringOf("DocumentClassifierProperties.VolumeKmsKeyId")
i = 0
lnCount_i = loJResp.SizeOfArray("DocumentClassifierProperties.InputDataConfig.AugmentedManifests")
DO WHILE i < lnCount_i
    loJResp.I = i
    lcAnnotationDataS3Uri = loJResp.StringOf("DocumentClassifierProperties.InputDataConfig.AugmentedManifests[i].AnnotationDataS3Uri")
    lcDocumentType = loJResp.StringOf("DocumentClassifierProperties.InputDataConfig.AugmentedManifests[i].DocumentType")
    lcS3Uri = loJResp.StringOf("DocumentClassifierProperties.InputDataConfig.AugmentedManifests[i].S3Uri")
    lcSourceDocumentsS3Uri = loJResp.StringOf("DocumentClassifierProperties.InputDataConfig.AugmentedManifests[i].SourceDocumentsS3Uri")
    lcSplit = loJResp.StringOf("DocumentClassifierProperties.InputDataConfig.AugmentedManifests[i].Split")
    j = 0
    lnCount_j = loJResp.SizeOfArray("DocumentClassifierProperties.InputDataConfig.AugmentedManifests[i].AttributeNames")
    DO WHILE j < lnCount_j
        loJResp.J = j
        lcStrVal = loJResp.StringOf("DocumentClassifierProperties.InputDataConfig.AugmentedManifests[i].AttributeNames[j]")
        j = j + 1
    ENDDO
    i = i + 1
ENDDO
i = 0
lnCount_i = loJResp.SizeOfArray("DocumentClassifierProperties.VpcConfig.SecurityGroupIds")
DO WHILE i < lnCount_i
    loJResp.I = i
    lcStrVal = loJResp.StringOf("DocumentClassifierProperties.VpcConfig.SecurityGroupIds[i]")
    i = i + 1
ENDDO
i = 0
lnCount_i = loJResp.SizeOfArray("DocumentClassifierProperties.VpcConfig.Subnets")
DO WHILE i < lnCount_i
    loJResp.I = i
    lcStrVal = loJResp.StringOf("DocumentClassifierProperties.VpcConfig.Subnets[i]")
    i = i + 1
ENDDO

* A sample JSON response body parsed by the above code:

* {
*   "DocumentClassifierProperties": {
*     "ClassifierMetadata": {
*       "EvaluationMetrics": {
*         "Accuracy": number,
*         "F1Score": number,
*         "HammingLoss": number,
*         "MicroF1Score": number,
*         "MicroPrecision": number,
*         "MicroRecall": number,
*         "Precision": number,
*         "Recall": number
*       },
*       "NumberOfLabels": number,
*       "NumberOfTestDocuments": number,
*       "NumberOfTrainedDocuments": number
*     },
*     "DataAccessRoleArn": "string",
*     "DocumentClassifierArn": "string",
*     "EndTime": number,
*     "InputDataConfig": {
*       "AugmentedManifests": [
*         {
*           "AnnotationDataS3Uri": "string",
*           "AttributeNames": [
*             "string"
*           ],
*           "DocumentType": "string",
*           "S3Uri": "string",
*           "SourceDocumentsS3Uri": "string",
*           "Split": "string"
*         }
*       ],
*       "DataFormat": "string",
*       "LabelDelimiter": "string",
*       "S3Uri": "string",
*       "TestS3Uri": "string"
*     },
*     "LanguageCode": "string",
*     "Message": "string",
*     "Mode": "string",
*     "ModelKmsKeyId": "string",
*     "OutputDataConfig": {
*       "KmsKeyId": "string",
*       "S3Uri": "string"
*     },
*     "SourceModelArn": "string",
*     "Status": "string",
*     "SubmitTime": number,
*     "TrainingEndTime": number,
*     "TrainingStartTime": number,
*     "VersionName": "string",
*     "VolumeKmsKeyId": "string",
*     "VpcConfig": {
*       "SecurityGroupIds": [
*         "string"
*       ],
*       "Subnets": [
*         "string"
*       ]
*     }
*   }
* }

RELEASE loRest
RELEASE loAuthAws
RELEASE loJson
RELEASE loSbRequestBody
RELEASE loSbResponseBody
RELEASE loJResp