Chilkat Online Tools

DescribeEntityRecognizer Swift Example

Amazon Comprehend

func chilkatTest() {
    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    let rest = CkoRest()
    var success: Bool

    let authAws = CkoAuthAws()
    authAws.AccessKey = "AWS_ACCESS_KEY"
    authAws.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.)
    authAws.Region = "us-west-2"
    authAws.ServiceName = "comprehend"
    // SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
    rest.SetAuthAws(authAws)

    // URL: https://comprehend.us-west-2.amazonaws.com/
    // Use the same region as specified above.
    success = rest.Connect("comprehend.us-west-2.amazonaws.com", port: 443, tls: true, autoReconnect: true)
    if success != true {
        print("ConnectFailReason: \(rest.ConnectFailReason.intValue)")
        print("\(rest.LastErrorText)")
        return
    }

    // 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

    let json = CkoJsonObject()
    json.UpdateString("EntityRecognizerArn", value: "string")

    // The JSON request body created by the above code:

    // {
    //   "EntityRecognizerArn": "string"
    // }

    rest.AddHeader("Content-Type", value: "application/x-amz-json-1.1")
    rest.AddHeader("X-Amz-Target", value: "Comprehend_20171127.DescribeEntityRecognizer")

    let sbRequestBody = CkoStringBuilder()
    json.EmitSb(sbRequestBody)
    let sbResponseBody = CkoStringBuilder()
    success = rest.FullRequestSb("POST", uriPath: "/", requestBody: sbRequestBody, responseBody: sbResponseBody)
    if success != true {
        print("\(rest.LastErrorText)")
        return
    }

    var respStatusCode: Int = rest.ResponseStatusCode.intValue
    print("response status code = \(respStatusCode)")
    if respStatusCode != 200 {
        print("Response Header:")
        print("\(rest.ResponseHeader)")
        print("Response Body:")
        print("\(sbResponseBody.GetAsString())")
        return
    }

    let jResp = CkoJsonObject()
    jResp.LoadSb(sbResponseBody)

    // 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

    var AnnotationDataS3Uri: String?
    var DocumentType: String?
    var SourceDocumentsS3Uri: String?
    var Split: String?
    var j: Int
    var count_j: Int
    var strVal: String?
    var v_Type: String?
    var EvaluationMetricsF1Score: Int
    var EvaluationMetricsPrecision: Int
    var EvaluationMetricsRecall: Int
    var NumberOfTrainMentions: Int

    var DataAccessRoleArn: String? = jResp.StringOf("EntityRecognizerProperties.DataAccessRoleArn")
    var EndTime: Int = jResp.IntOf("EntityRecognizerProperties.EndTime").intValue
    var EntityRecognizerArn: String? = jResp.StringOf("EntityRecognizerProperties.EntityRecognizerArn")
    var S3Uri: String? = jResp.StringOf("EntityRecognizerProperties.InputDataConfig.Annotations.S3Uri")
    var TestS3Uri: String? = jResp.StringOf("EntityRecognizerProperties.InputDataConfig.Annotations.TestS3Uri")
    var DataFormat: String? = jResp.StringOf("EntityRecognizerProperties.InputDataConfig.DataFormat")
    var InputFormat: String? = jResp.StringOf("EntityRecognizerProperties.InputDataConfig.Documents.InputFormat")
    var DocumentsS3Uri: String? = jResp.StringOf("EntityRecognizerProperties.InputDataConfig.Documents.S3Uri")
    var DocumentsTestS3Uri: String? = jResp.StringOf("EntityRecognizerProperties.InputDataConfig.Documents.TestS3Uri")
    var EntityListS3Uri: String? = jResp.StringOf("EntityRecognizerProperties.InputDataConfig.EntityList.S3Uri")
    var LanguageCode: String? = jResp.StringOf("EntityRecognizerProperties.LanguageCode")
    var Message: String? = jResp.StringOf("EntityRecognizerProperties.Message")
    var ModelKmsKeyId: String? = jResp.StringOf("EntityRecognizerProperties.ModelKmsKeyId")
    var F1Score: Int = jResp.IntOf("EntityRecognizerProperties.RecognizerMetadata.EvaluationMetrics.F1Score").intValue
    var Precision: Int = jResp.IntOf("EntityRecognizerProperties.RecognizerMetadata.EvaluationMetrics.Precision").intValue
    var Recall: Int = jResp.IntOf("EntityRecognizerProperties.RecognizerMetadata.EvaluationMetrics.Recall").intValue
    var NumberOfTestDocuments: Int = jResp.IntOf("EntityRecognizerProperties.RecognizerMetadata.NumberOfTestDocuments").intValue
    var NumberOfTrainedDocuments: Int = jResp.IntOf("EntityRecognizerProperties.RecognizerMetadata.NumberOfTrainedDocuments").intValue
    var SourceModelArn: String? = jResp.StringOf("EntityRecognizerProperties.SourceModelArn")
    var Status: String? = jResp.StringOf("EntityRecognizerProperties.Status")
    var SubmitTime: Int = jResp.IntOf("EntityRecognizerProperties.SubmitTime").intValue
    var TrainingEndTime: Int = jResp.IntOf("EntityRecognizerProperties.TrainingEndTime").intValue
    var TrainingStartTime: Int = jResp.IntOf("EntityRecognizerProperties.TrainingStartTime").intValue
    var VersionName: String? = jResp.StringOf("EntityRecognizerProperties.VersionName")
    var VolumeKmsKeyId: String? = jResp.StringOf("EntityRecognizerProperties.VolumeKmsKeyId")
    var i: Int = 0
    var count_i: Int = jResp.SizeOfArray("EntityRecognizerProperties.InputDataConfig.AugmentedManifests").intValue
    while i < count_i {
        jResp.I = i
        AnnotationDataS3Uri = jResp.StringOf("EntityRecognizerProperties.InputDataConfig.AugmentedManifests[i].AnnotationDataS3Uri")
        DocumentType = jResp.StringOf("EntityRecognizerProperties.InputDataConfig.AugmentedManifests[i].DocumentType")
        S3Uri = jResp.StringOf("EntityRecognizerProperties.InputDataConfig.AugmentedManifests[i].S3Uri")
        SourceDocumentsS3Uri = jResp.StringOf("EntityRecognizerProperties.InputDataConfig.AugmentedManifests[i].SourceDocumentsS3Uri")
        Split = jResp.StringOf("EntityRecognizerProperties.InputDataConfig.AugmentedManifests[i].Split")
        j = 0
        count_j = jResp.SizeOfArray("EntityRecognizerProperties.InputDataConfig.AugmentedManifests[i].AttributeNames").intValue
        while j < count_j {
            jResp.J = j
            strVal = jResp.StringOf("EntityRecognizerProperties.InputDataConfig.AugmentedManifests[i].AttributeNames[j]")
            j = j + 1
        }

        i = i + 1
    }

    i = 0
    count_i = jResp.SizeOfArray("EntityRecognizerProperties.InputDataConfig.EntityTypes").intValue
    while i < count_i {
        jResp.I = i
        v_Type = jResp.StringOf("EntityRecognizerProperties.InputDataConfig.EntityTypes[i].Type")
        i = i + 1
    }

    i = 0
    count_i = jResp.SizeOfArray("EntityRecognizerProperties.RecognizerMetadata.EntityTypes").intValue
    while i < count_i {
        jResp.I = i
        EvaluationMetricsF1Score = jResp.IntOf("EntityRecognizerProperties.RecognizerMetadata.EntityTypes[i].EvaluationMetrics.F1Score").intValue
        EvaluationMetricsPrecision = jResp.IntOf("EntityRecognizerProperties.RecognizerMetadata.EntityTypes[i].EvaluationMetrics.Precision").intValue
        EvaluationMetricsRecall = jResp.IntOf("EntityRecognizerProperties.RecognizerMetadata.EntityTypes[i].EvaluationMetrics.Recall").intValue
        NumberOfTrainMentions = jResp.IntOf("EntityRecognizerProperties.RecognizerMetadata.EntityTypes[i].NumberOfTrainMentions").intValue
        v_Type = jResp.StringOf("EntityRecognizerProperties.RecognizerMetadata.EntityTypes[i].Type")
        i = i + 1
    }

    i = 0
    count_i = jResp.SizeOfArray("EntityRecognizerProperties.VpcConfig.SecurityGroupIds").intValue
    while i < count_i {
        jResp.I = i
        strVal = jResp.StringOf("EntityRecognizerProperties.VpcConfig.SecurityGroupIds[i]")
        i = i + 1
    }

    i = 0
    count_i = jResp.SizeOfArray("EntityRecognizerProperties.VpcConfig.Subnets").intValue
    while i < count_i {
        jResp.I = i
        strVal = jResp.StringOf("EntityRecognizerProperties.VpcConfig.Subnets[i]")
        i = i + 1
    }

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

    // {
    //   "EntityRecognizerProperties": {
    //     "DataAccessRoleArn": "string",
    //     "EndTime": number,
    //     "EntityRecognizerArn": "string",
    //     "InputDataConfig": {
    //       "Annotations": {
    //         "S3Uri": "string",
    //         "TestS3Uri": "string"
    //       },
    //       "AugmentedManifests": [
    //         {
    //           "AnnotationDataS3Uri": "string",
    //           "AttributeNames": [
    //             "string"
    //           ],
    //           "DocumentType": "string",
    //           "S3Uri": "string",
    //           "SourceDocumentsS3Uri": "string",
    //           "Split": "string"
    //         }
    //       ],
    //       "DataFormat": "string",
    //       "Documents": {
    //         "InputFormat": "string",
    //         "S3Uri": "string",
    //         "TestS3Uri": "string"
    //       },
    //       "EntityList": {
    //         "S3Uri": "string"
    //       },
    //       "EntityTypes": [
    //         {
    //           "Type": "string"
    //         }
    //       ]
    //     },
    //     "LanguageCode": "string",
    //     "Message": "string",
    //     "ModelKmsKeyId": "string",
    //     "RecognizerMetadata": {
    //       "EntityTypes": [
    //         {
    //           "EvaluationMetrics": {
    //             "F1Score": number,
    //             "Precision": number,
    //             "Recall": number
    //           },
    //           "NumberOfTrainMentions": number,
    //           "Type": "string"
    //         }
    //       ],
    //       "EvaluationMetrics": {
    //         "F1Score": number,
    //         "Precision": number,
    //         "Recall": number
    //       },
    //       "NumberOfTestDocuments": number,
    //       "NumberOfTrainedDocuments": number
    //     },
    //     "SourceModelArn": "string",
    //     "Status": "string",
    //     "SubmitTime": number,
    //     "TrainingEndTime": number,
    //     "TrainingStartTime": number,
    //     "VersionName": "string",
    //     "VolumeKmsKeyId": "string",
    //     "VpcConfig": {
    //       "SecurityGroupIds": [
    //         "string"
    //       ],
    //       "Subnets": [
    //         "string"
    //       ]
    //     }
    //   }
    // }

}