ListDocumentClassifiers TCL Example
load ./chilkat.dll
# This example requires the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.
set rest [new_CkRest]
set authAws [new_CkAuthAws]
CkAuthAws_put_AccessKey $authAws "AWS_ACCESS_KEY"
CkAuthAws_put_SecretKey $authAws "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.)
CkAuthAws_put_Region $authAws "us-west-2"
CkAuthAws_put_ServiceName $authAws "comprehend"
# SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
CkRest_SetAuthAws $rest $authAws
# URL: https://comprehend.us-west-2.amazonaws.com/
# Use the same region as specified above.
set success [CkRest_Connect $rest "comprehend.us-west-2.amazonaws.com" 443 1 1]
if {$success != 1} then {
puts "ConnectFailReason: [CkRest_get_ConnectFailReason $rest]"
puts [CkRest_lastErrorText $rest]
delete_CkRest $rest
delete_CkAuthAws $authAws
exit
}
# 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
set json [new_CkJsonObject]
CkJsonObject_UpdateString $json "Filter.DocumentClassifierName" "string"
CkJsonObject_UpdateString $json "Filter.Status" "string"
CkJsonObject_UpdateInt $json "Filter.SubmitTimeAfter" 123
CkJsonObject_UpdateInt $json "Filter.SubmitTimeBefore" 123
CkJsonObject_UpdateInt $json "MaxResults" 123
CkJsonObject_UpdateString $json "NextToken" "string"
# The JSON request body created by the above code:
# {
# "Filter": {
# "DocumentClassifierName": "string",
# "Status": "string",
# "SubmitTimeAfter": number,
# "SubmitTimeBefore": number
# },
# "MaxResults": number,
# "NextToken": "string"
# }
CkRest_AddHeader $rest "Content-Type" "application/x-amz-json-1.1"
CkRest_AddHeader $rest "X-Amz-Target" "Comprehend_20171127.ListDocumentClassifiers"
set sbRequestBody [new_CkStringBuilder]
CkJsonObject_EmitSb $json $sbRequestBody
set sbResponseBody [new_CkStringBuilder]
set success [CkRest_FullRequestSb $rest "POST" "/" $sbRequestBody $sbResponseBody]
if {$success != 1} then {
puts [CkRest_lastErrorText $rest]
delete_CkRest $rest
delete_CkAuthAws $authAws
delete_CkJsonObject $json
delete_CkStringBuilder $sbRequestBody
delete_CkStringBuilder $sbResponseBody
exit
}
set respStatusCode [CkRest_get_ResponseStatusCode $rest]
puts "response status code = $respStatusCode"
if {$respStatusCode != 200} then {
puts "Response Header:"
puts [CkRest_responseHeader $rest]
puts "Response Body:"
puts [CkStringBuilder_getAsString $sbResponseBody]
delete_CkRest $rest
delete_CkAuthAws $authAws
delete_CkJsonObject $json
delete_CkStringBuilder $sbRequestBody
delete_CkStringBuilder $sbResponseBody
exit
}
set jResp [new_CkJsonObject]
CkJsonObject_LoadSb $jResp $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
set NextToken [CkJsonObject_stringOf $jResp "NextToken"]
set i 0
set count_i [CkJsonObject_SizeOfArray $jResp "DocumentClassifierPropertiesList"]
while {$i < $count_i} {
CkJsonObject_put_I $jResp $i
set Accuracy [CkJsonObject_IntOf $jResp "DocumentClassifierPropertiesList[i].ClassifierMetadata.EvaluationMetrics.Accuracy"]
set F1Score [CkJsonObject_IntOf $jResp "DocumentClassifierPropertiesList[i].ClassifierMetadata.EvaluationMetrics.F1Score"]
set HammingLoss [CkJsonObject_IntOf $jResp "DocumentClassifierPropertiesList[i].ClassifierMetadata.EvaluationMetrics.HammingLoss"]
set MicroF1Score [CkJsonObject_IntOf $jResp "DocumentClassifierPropertiesList[i].ClassifierMetadata.EvaluationMetrics.MicroF1Score"]
set MicroPrecision [CkJsonObject_IntOf $jResp "DocumentClassifierPropertiesList[i].ClassifierMetadata.EvaluationMetrics.MicroPrecision"]
set MicroRecall [CkJsonObject_IntOf $jResp "DocumentClassifierPropertiesList[i].ClassifierMetadata.EvaluationMetrics.MicroRecall"]
set Precision [CkJsonObject_IntOf $jResp "DocumentClassifierPropertiesList[i].ClassifierMetadata.EvaluationMetrics.Precision"]
set Recall [CkJsonObject_IntOf $jResp "DocumentClassifierPropertiesList[i].ClassifierMetadata.EvaluationMetrics.Recall"]
set NumberOfLabels [CkJsonObject_IntOf $jResp "DocumentClassifierPropertiesList[i].ClassifierMetadata.NumberOfLabels"]
set NumberOfTestDocuments [CkJsonObject_IntOf $jResp "DocumentClassifierPropertiesList[i].ClassifierMetadata.NumberOfTestDocuments"]
set NumberOfTrainedDocuments [CkJsonObject_IntOf $jResp "DocumentClassifierPropertiesList[i].ClassifierMetadata.NumberOfTrainedDocuments"]
set DataAccessRoleArn [CkJsonObject_stringOf $jResp "DocumentClassifierPropertiesList[i].DataAccessRoleArn"]
set DocumentClassifierArn [CkJsonObject_stringOf $jResp "DocumentClassifierPropertiesList[i].DocumentClassifierArn"]
set EndTime [CkJsonObject_IntOf $jResp "DocumentClassifierPropertiesList[i].EndTime"]
set DataFormat [CkJsonObject_stringOf $jResp "DocumentClassifierPropertiesList[i].InputDataConfig.DataFormat"]
set LabelDelimiter [CkJsonObject_stringOf $jResp "DocumentClassifierPropertiesList[i].InputDataConfig.LabelDelimiter"]
set S3Uri [CkJsonObject_stringOf $jResp "DocumentClassifierPropertiesList[i].InputDataConfig.S3Uri"]
set TestS3Uri [CkJsonObject_stringOf $jResp "DocumentClassifierPropertiesList[i].InputDataConfig.TestS3Uri"]
set LanguageCode [CkJsonObject_stringOf $jResp "DocumentClassifierPropertiesList[i].LanguageCode"]
set Message [CkJsonObject_stringOf $jResp "DocumentClassifierPropertiesList[i].Message"]
set Mode [CkJsonObject_stringOf $jResp "DocumentClassifierPropertiesList[i].Mode"]
set ModelKmsKeyId [CkJsonObject_stringOf $jResp "DocumentClassifierPropertiesList[i].ModelKmsKeyId"]
set KmsKeyId [CkJsonObject_stringOf $jResp "DocumentClassifierPropertiesList[i].OutputDataConfig.KmsKeyId"]
set OutputDataConfigS3Uri [CkJsonObject_stringOf $jResp "DocumentClassifierPropertiesList[i].OutputDataConfig.S3Uri"]
set SourceModelArn [CkJsonObject_stringOf $jResp "DocumentClassifierPropertiesList[i].SourceModelArn"]
set Status [CkJsonObject_stringOf $jResp "DocumentClassifierPropertiesList[i].Status"]
set SubmitTime [CkJsonObject_IntOf $jResp "DocumentClassifierPropertiesList[i].SubmitTime"]
set TrainingEndTime [CkJsonObject_IntOf $jResp "DocumentClassifierPropertiesList[i].TrainingEndTime"]
set TrainingStartTime [CkJsonObject_IntOf $jResp "DocumentClassifierPropertiesList[i].TrainingStartTime"]
set VersionName [CkJsonObject_stringOf $jResp "DocumentClassifierPropertiesList[i].VersionName"]
set VolumeKmsKeyId [CkJsonObject_stringOf $jResp "DocumentClassifierPropertiesList[i].VolumeKmsKeyId"]
set j 0
set count_j [CkJsonObject_SizeOfArray $jResp "DocumentClassifierPropertiesList[i].InputDataConfig.AugmentedManifests"]
while {$j < $count_j} {
CkJsonObject_put_J $jResp $j
set AnnotationDataS3Uri [CkJsonObject_stringOf $jResp "DocumentClassifierPropertiesList[i].InputDataConfig.AugmentedManifests[j].AnnotationDataS3Uri"]
set DocumentType [CkJsonObject_stringOf $jResp "DocumentClassifierPropertiesList[i].InputDataConfig.AugmentedManifests[j].DocumentType"]
set S3Uri [CkJsonObject_stringOf $jResp "DocumentClassifierPropertiesList[i].InputDataConfig.AugmentedManifests[j].S3Uri"]
set SourceDocumentsS3Uri [CkJsonObject_stringOf $jResp "DocumentClassifierPropertiesList[i].InputDataConfig.AugmentedManifests[j].SourceDocumentsS3Uri"]
set Split [CkJsonObject_stringOf $jResp "DocumentClassifierPropertiesList[i].InputDataConfig.AugmentedManifests[j].Split"]
set k 0
set count_k [CkJsonObject_SizeOfArray $jResp "DocumentClassifierPropertiesList[i].InputDataConfig.AugmentedManifests[j].AttributeNames"]
while {$k < $count_k} {
CkJsonObject_put_K $jResp $k
set strVal [CkJsonObject_stringOf $jResp "DocumentClassifierPropertiesList[i].InputDataConfig.AugmentedManifests[j].AttributeNames[k]"]
set k [expr $k + 1]
}
set j [expr $j + 1]
}
set j 0
set count_j [CkJsonObject_SizeOfArray $jResp "DocumentClassifierPropertiesList[i].VpcConfig.SecurityGroupIds"]
while {$j < $count_j} {
CkJsonObject_put_J $jResp $j
set strVal [CkJsonObject_stringOf $jResp "DocumentClassifierPropertiesList[i].VpcConfig.SecurityGroupIds[j]"]
set j [expr $j + 1]
}
set j 0
set count_j [CkJsonObject_SizeOfArray $jResp "DocumentClassifierPropertiesList[i].VpcConfig.Subnets"]
while {$j < $count_j} {
CkJsonObject_put_J $jResp $j
set strVal [CkJsonObject_stringOf $jResp "DocumentClassifierPropertiesList[i].VpcConfig.Subnets[j]"]
set j [expr $j + 1]
}
set i [expr $i + 1]
}
# A sample JSON response body parsed by the above code:
# {
# "DocumentClassifierPropertiesList": [
# {
# "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"
# ]
# }
# }
# ],
# "NextToken": "string"
# }
delete_CkRest $rest
delete_CkAuthAws $authAws
delete_CkJsonObject $json
delete_CkStringBuilder $sbRequestBody
delete_CkStringBuilder $sbResponseBody
delete_CkJsonObject $jResp