File: responses.py

package info (click to toggle)
python-moto 5.1.18-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 116,520 kB
  • sloc: python: 636,725; javascript: 181; makefile: 39; sh: 3
file content (658 lines) | stat: -rw-r--r-- 26,661 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
"""Handles incoming comprehend requests, invokes methods, returns responses."""

import json
from typing import Any

from moto.core.responses import BaseResponse

from .models import ComprehendBackend, comprehend_backends


class ComprehendResponse(BaseResponse):
    """Handler for Comprehend requests and responses."""

    def __init__(self) -> None:
        super().__init__(service_name="comprehend")

    @property
    def comprehend_backend(self) -> ComprehendBackend:
        """Return backend instance specific for this region."""
        return comprehend_backends[self.current_account][self.region]

    def list_entity_recognizers(self) -> str:
        params = json.loads(self.body)
        _filter = params.get("Filter", {})
        recognizers = self.comprehend_backend.list_entity_recognizers(_filter=_filter)
        return json.dumps(
            {"EntityRecognizerPropertiesList": [r.to_dict() for r in recognizers]}
        )

    def create_entity_recognizer(self) -> str:
        params = json.loads(self.body)
        recognizer_name = params.get("RecognizerName")
        version_name = params.get("VersionName")
        data_access_role_arn = params.get("DataAccessRoleArn")
        tags = params.get("Tags")
        input_data_config = params.get("InputDataConfig")
        language_code = params.get("LanguageCode")
        volume_kms_key_id = params.get("VolumeKmsKeyId")
        vpc_config = params.get("VpcConfig")
        model_kms_key_id = params.get("ModelKmsKeyId")
        model_policy = params.get("ModelPolicy")
        entity_recognizer_arn = self.comprehend_backend.create_entity_recognizer(
            recognizer_name=recognizer_name,
            version_name=version_name,
            data_access_role_arn=data_access_role_arn,
            tags=tags,
            input_data_config=input_data_config,
            language_code=language_code,
            volume_kms_key_id=volume_kms_key_id,
            vpc_config=vpc_config,
            model_kms_key_id=model_kms_key_id,
            model_policy=model_policy,
        )
        return json.dumps({"EntityRecognizerArn": entity_recognizer_arn})

    def describe_entity_recognizer(self) -> str:
        params = json.loads(self.body)
        entity_recognizer_arn = params.get("EntityRecognizerArn")
        recognizer = self.comprehend_backend.describe_entity_recognizer(
            entity_recognizer_arn=entity_recognizer_arn,
        )
        return json.dumps({"EntityRecognizerProperties": recognizer.to_dict()})

    def stop_training_entity_recognizer(self) -> str:
        params = json.loads(self.body)
        entity_recognizer_arn = params.get("EntityRecognizerArn")
        self.comprehend_backend.stop_training_entity_recognizer(
            entity_recognizer_arn=entity_recognizer_arn,
        )
        return json.dumps({})

    def list_tags_for_resource(self) -> str:
        params = json.loads(self.body)
        resource_arn = params.get("ResourceArn")
        tags = self.comprehend_backend.list_tags_for_resource(
            resource_arn=resource_arn,
        )
        return json.dumps({"ResourceArn": resource_arn, "Tags": tags})

    def delete_entity_recognizer(self) -> str:
        params = json.loads(self.body)
        entity_recognizer_arn = params.get("EntityRecognizerArn")
        self.comprehend_backend.delete_entity_recognizer(
            entity_recognizer_arn=entity_recognizer_arn,
        )
        return "{}"

    def tag_resource(self) -> str:
        params = json.loads(self.body)
        resource_arn = params.get("ResourceArn")
        tags = params.get("Tags")
        self.comprehend_backend.tag_resource(resource_arn, tags)
        return "{}"

    def untag_resource(self) -> str:
        params = json.loads(self.body)
        resource_arn = params.get("ResourceArn")
        tag_keys = params.get("TagKeys")
        self.comprehend_backend.untag_resource(resource_arn, tag_keys)
        return "{}"

    def detect_pii_entities(self) -> str:
        params = json.loads(self.body)
        text = params.get("Text")
        language = params.get("LanguageCode")
        resp = self.comprehend_backend.detect_pii_entities(text, language)
        return json.dumps({"Entities": resp})

    def detect_key_phrases(self) -> str:
        params = json.loads(self.body)
        text = params.get("Text")
        language = params.get("LanguageCode")
        resp = self.comprehend_backend.detect_key_phrases(text, language)
        return json.dumps({"KeyPhrases": resp})

    def detect_sentiment(self) -> str:
        params = json.loads(self.body)
        text = params.get("Text")
        language = params.get("LanguageCode")
        resp = self.comprehend_backend.detect_sentiment(text, language)
        return json.dumps(resp)

    def create_document_classifier(self) -> str:
        params = json.loads(self.body)
        document_classifier_name = params.get("DocumentClassifierName")
        version_name = params.get("VersionName")
        data_access_role_arn = params.get("DataAccessRoleArn")
        tags = params.get("Tags")
        input_data_config = params.get("InputDataConfig")
        output_data_config = params.get("OutputDataConfig")
        client_request_token = params.get("ClientRequestToken")
        language_code = params.get("LanguageCode")
        volume_kms_key_id = params.get("VolumeKmsKeyId")
        vpc_config = params.get("VpcConfig")
        mode = params.get("Mode")
        model_kms_key_id = params.get("ModelKmsKeyId")
        model_policy = params.get("ModelPolicy")

        document_classifier_arn = self.comprehend_backend.create_document_classifier(
            document_classifier_name=document_classifier_name,
            version_name=version_name,
            data_access_role_arn=data_access_role_arn,
            tags=tags,
            input_data_config=input_data_config,
            output_data_config=output_data_config,
            client_request_token=client_request_token,
            language_code=language_code,
            volume_kms_key_id=volume_kms_key_id,
            vpc_config=vpc_config,
            mode=mode,
            model_kms_key_id=model_kms_key_id,
            model_policy=model_policy,
        )

        return json.dumps({"DocumentClassifierArn": document_classifier_arn})

    def create_endpoint(self) -> str:
        params = json.loads(self.body)
        endpoint_name = params.get("EndpointName")
        model_arn = params.get("ModelArn")
        desired_inference_units = params.get("DesiredInferenceUnits")
        client_request_token = params.get("ClientRequestToken")
        tags = params.get("Tags")
        data_access_role_arn = params.get("DataAccessRoleArn")
        flywheel_arn = params.get("FlywheelArn")
        endpoint_arn, model_arn = self.comprehend_backend.create_endpoint(
            endpoint_name=endpoint_name,
            model_arn=model_arn,
            desired_inference_units=desired_inference_units,
            client_request_token=client_request_token,
            tags=tags,
            data_access_role_arn=data_access_role_arn,
            flywheel_arn=flywheel_arn,
        )

        return json.dumps({"EndpointArn": endpoint_arn, "ModelArn": model_arn})

    def create_flywheel(self) -> str:
        params = json.loads(self.body)
        flywheel_name = params.get("FlywheelName")
        active_model_arn = params.get("ActiveModelArn")
        data_access_role_arn = params.get("DataAccessRoleArn")
        task_config = params.get("TaskConfig")
        model_type = params.get("ModelType")
        data_lake_s3_uri = params.get("DataLakeS3Uri")
        data_security_config = params.get("DataSecurityConfig")
        client_request_token = params.get("ClientRequestToken")
        tags = params.get("Tags")
        flywheel_arn, active_model_arn = self.comprehend_backend.create_flywheel(
            flywheel_name=flywheel_name,
            active_model_arn=active_model_arn,
            data_access_role_arn=data_access_role_arn,
            task_config=task_config,
            model_type=model_type,
            data_lake_s3_uri=data_lake_s3_uri,
            data_security_config=data_security_config,
            client_request_token=client_request_token,
            tags=tags,
        )

        return json.dumps(
            {"FlywheelArn": flywheel_arn, "activeModelArn": active_model_arn}
        )

    def describe_document_classifier(self) -> str:
        params = json.loads(self.body)
        document_classifier_arn = params.get("DocumentClassifierArn")
        document_classifier = self.comprehend_backend.describe_document_classifier(
            document_classifier_arn=document_classifier_arn,
        )

        return json.dumps(
            {"DocumentClassifierProperties": document_classifier.to_dict()}
        )

    def describe_endpoint(self) -> str:
        params = json.loads(self.body)
        endpoint_arn = params.get("EndpointArn")
        endpoint_properties = self.comprehend_backend.describe_endpoint(
            endpoint_arn=endpoint_arn,
        )

        return json.dumps({"EndpointProperties": endpoint_properties.to_dict()})

    def describe_flywheel(self) -> str:
        params = json.loads(self.body)
        flywheel_arn = params.get("FlywheelArn")
        flywheel_properties = self.comprehend_backend.describe_flywheel(
            flywheel_arn=flywheel_arn,
        )

        return json.dumps({"FlywheelProperties": flywheel_properties.to_dict()})

    def delete_document_classifier(self) -> str:
        params = json.loads(self.body)
        document_classifier_arn = params.get("DocumentClassifierArn")
        self.comprehend_backend.delete_document_classifier(
            document_classifier_arn=document_classifier_arn,
        )

        return json.dumps({})

    def delete_endpoint(self) -> str:
        params = json.loads(self.body)
        endpoint_arn = params.get("EndpointArn")
        self.comprehend_backend.delete_endpoint(
            endpoint_arn=endpoint_arn,
        )

        return json.dumps({})

    def delete_flywheel(self) -> str:
        params = json.loads(self.body)
        flywheel_arn = params.get("FlywheelArn")
        self.comprehend_backend.delete_flywheel(
            flywheel_arn=flywheel_arn,
        )

        return json.dumps({})

    def list_document_classifiers(self) -> str:
        params = json.loads(self.body)
        filter = params.get("Filter")
        next_token = params.get("NextToken")
        max_results = params.get("MaxResults")
        document_classifier_properties_list, next_token = (
            self.comprehend_backend.list_document_classifiers(
                filter=filter,
                next_token=next_token,
                max_results=max_results,
            )
        )

        return json.dumps(
            {
                "DocumentClassifierPropertiesList": document_classifier_properties_list,
                "NextToken": next_token,
            }
        )

    def list_endpoints(self) -> str:
        params = json.loads(self.body)
        filter = params.get("Filter")
        next_token = params.get("NextToken")
        max_results = params.get("MaxResults")
        endpoint_properties_list, next_token = self.comprehend_backend.list_endpoints(
            filter=filter,
            next_token=next_token,
            max_results=max_results,
        )

        return json.dumps(
            {
                "EndpointPropertiesList": endpoint_properties_list,
                "NextToken": next_token,
            }
        )

    def list_flywheels(self) -> str:
        params = json.loads(self.body)
        filter = params.get("Filter")
        next_token = params.get("NextToken")
        max_results = params.get("MaxResults")
        flywheel_summary_list, next_token = self.comprehend_backend.list_flywheels(
            filter=filter,
            next_token=next_token,
            max_results=max_results,
        )

        return json.dumps(
            {"FlywheelSummaryList": flywheel_summary_list, "nextToken": next_token}
        )

    def stop_training_document_classifier(self) -> str:
        params = json.loads(self.body)
        document_classifier_arn = params.get("DocumentClassifierArn")
        self.comprehend_backend.stop_training_document_classifier(
            document_classifier_arn=document_classifier_arn,
        )

        return json.dumps({})

    def start_flywheel_iteration(self) -> str:
        params = json.loads(self.body)
        flywheel_arn = params.get("FlywheelArn")
        client_request_token = params.get("ClientRequestToken")
        flywheel_arn, flywheel_iteration_id = (
            self.comprehend_backend.start_flywheel_iteration(
                flywheel_arn=flywheel_arn,
                client_request_token=client_request_token,
            )
        )

        return json.dumps(
            {"FlywheelArn": flywheel_arn, "FlywheelIterationId": flywheel_iteration_id}
        )

    def update_endpoint(self) -> str:
        params = json.loads(self.body)
        endpoint_arn = params.get("EndpointArn")
        desired_model_arn = params.get("DesiredModelArn")
        desired_inference_units = params.get("DesiredInferenceUnits")
        desired_data_access_role_arn = params.get("DesiredDataAccessRoleArn")
        flywheel_arn = params.get("FlywheelArn")
        desired_model_arn = self.comprehend_backend.update_endpoint(
            endpoint_arn=endpoint_arn,
            desired_model_arn=desired_model_arn,
            desired_inference_units=desired_inference_units,
            desired_data_access_role_arn=desired_data_access_role_arn,
            flywheel_arn=flywheel_arn,
        )

        return json.dumps({"DesiredModelArn": desired_model_arn})

    def _job_to_dict_resp(self, job_properties: dict[str, Any]) -> str:
        job_type_key = job_properties.pop("job_type")

        if job_properties.get("SubmitTime"):
            job_properties["SubmitTime"] = job_properties["SubmitTime"].isoformat()
        if job_properties.get("EndTime"):
            job_properties["EndTime"] = job_properties["EndTime"].isoformat()

        key_name = f"{job_type_key}JobProperties"
        return json.dumps({key_name: job_properties})

    def _list_jobs_to_dict_resp(
        self, job_list: list[dict[str, Any]], job_type: str
    ) -> str:
        for job_properties in job_list:
            job_properties.pop("job_type")
            if job_properties.get("SubmitTime"):
                job_properties["SubmitTime"] = job_properties["SubmitTime"].isoformat()
            if job_properties.get("EndTime"):
                job_properties["EndTime"] = job_properties["EndTime"].isoformat()

        key_name = f"{job_type}JobPropertiesList"
        return json.dumps({key_name: job_list, "NextToken": None})

    def start_pii_entities_detection_job(self) -> str:
        params = json.loads(self.body)
        job = self.comprehend_backend.start_pii_entities_detection_job(**params)
        return json.dumps(
            {"JobId": job.job_id, "JobArn": job.job_arn, "JobStatus": job.job_status}
        )

    def describe_pii_entities_detection_job(self) -> str:
        params = json.loads(self.body)
        job = self.comprehend_backend.describe_pii_entities_detection_job(
            job_id=params["JobId"]
        )
        return self._job_to_dict_resp(job.to_dict())

    def stop_pii_entities_detection_job(self) -> str:
        params = json.loads(self.body)
        self.comprehend_backend.stop_pii_entities_detection_job(job_id=params["JobId"])
        return json.dumps({"JobId": params["JobId"], "JobStatus": "STOP_REQUESTED"})

    def list_pii_entities_detection_jobs(self) -> str:
        params = json.loads(self.body)
        job_filter = params.get("Filter")
        jobs = self.comprehend_backend.list_pii_entities_detection_jobs(
            filter=job_filter
        )
        job_list = [job.to_dict() for job in jobs]
        return self._list_jobs_to_dict_resp(job_list, "PiiEntitiesDetection")

    def start_key_phrases_detection_job(self) -> str:
        params = json.loads(self.body)
        job = self.comprehend_backend.start_key_phrases_detection_job(**params)
        return json.dumps(
            {"JobId": job.job_id, "JobArn": job.job_arn, "JobStatus": job.job_status}
        )

    def describe_key_phrases_detection_job(self) -> str:
        params = json.loads(self.body)
        job = self.comprehend_backend.describe_key_phrases_detection_job(
            job_id=params["JobId"]
        )
        return self._job_to_dict_resp(job.to_dict())

    def stop_key_phrases_detection_job(self) -> str:
        params = json.loads(self.body)
        self.comprehend_backend.stop_key_phrases_detection_job(job_id=params["JobId"])
        return json.dumps({"JobId": params["JobId"], "JobStatus": "STOP_REQUESTED"})

    def list_key_phrases_detection_jobs(self) -> str:
        params = json.loads(self.body)
        job_filter = params.get("Filter")
        jobs = self.comprehend_backend.list_key_phrases_detection_jobs(
            filter=job_filter
        )
        job_list = [job.to_dict() for job in jobs]
        return self._list_jobs_to_dict_resp(job_list, "KeyPhrasesDetection")

    def start_sentiment_detection_job(self) -> str:
        params = json.loads(self.body)
        job = self.comprehend_backend.start_sentiment_detection_job(**params)
        return json.dumps(
            {"JobId": job.job_id, "JobArn": job.job_arn, "JobStatus": job.job_status}
        )

    def describe_sentiment_detection_job(self) -> str:
        params = json.loads(self.body)
        job = self.comprehend_backend.describe_sentiment_detection_job(
            job_id=params["JobId"]
        )
        return self._job_to_dict_resp(job.to_dict())

    def stop_sentiment_detection_job(self) -> str:
        params = json.loads(self.body)
        self.comprehend_backend.stop_sentiment_detection_job(job_id=params["JobId"])
        return json.dumps({"JobId": params["JobId"], "JobStatus": "STOP_REQUESTED"})

    def list_sentiment_detection_jobs(self) -> str:
        params = json.loads(self.body)
        job_filter = params.get("Filter")
        jobs = self.comprehend_backend.list_sentiment_detection_jobs(filter=job_filter)
        job_list = [job.to_dict() for job in jobs]
        return self._list_jobs_to_dict_resp(job_list, "SentimentDetection")

    def put_resource_policy(self) -> str:
        params = json.loads(self.body)
        resource_arn = params.get("ResourceArn")
        resource_policy = params.get("ResourcePolicy")
        policy_revision_id = params.get("PolicyRevisionId")

        revision_id = self.comprehend_backend.put_resource_policy(
            resource_arn=resource_arn,
            resource_policy=resource_policy,
            policy_revision_id=policy_revision_id,
        )

        return json.dumps({"PolicyRevisionId": revision_id})

    def describe_resource_policy(self) -> str:
        params = json.loads(self.body)
        resource_arn = params.get("ResourceArn")

        policy_details = self.comprehend_backend.describe_resource_policy(
            resource_arn=resource_arn
        )

        response_payload = {
            "ResourcePolicy": policy_details["ResourcePolicy"],
            "CreationTime": policy_details["CreationTime"].isoformat(),
            "LastModifiedTime": policy_details["LastModifiedTime"].isoformat(),
            "PolicyRevisionId": policy_details["PolicyRevisionId"],
        }

        return json.dumps(response_payload)

    def delete_resource_policy(self) -> str:
        params = json.loads(self.body)
        resource_arn = params.get("ResourceArn")
        policy_revision_id = params.get("PolicyRevisionId")

        self.comprehend_backend.delete_resource_policy(
            resource_arn=resource_arn,
            policy_revision_id=policy_revision_id,
        )

        return "{}"

    def start_targeted_sentiment_detection_job(self) -> str:
        params = json.loads(self.body)
        job = self.comprehend_backend.start_targeted_sentiment_detection_job(**params)
        return json.dumps(
            {"JobId": job.job_id, "JobArn": job.job_arn, "JobStatus": job.job_status}
        )

    def describe_targeted_sentiment_detection_job(self) -> str:
        params = json.loads(self.body)
        job = self.comprehend_backend.describe_targeted_sentiment_detection_job(
            job_id=params["JobId"]
        )
        return self._job_to_dict_resp(job.to_dict())

    def stop_targeted_sentiment_detection_job(self) -> str:
        params = json.loads(self.body)
        self.comprehend_backend.stop_targeted_sentiment_detection_job(
            job_id=params["JobId"]
        )
        return json.dumps({"JobId": params["JobId"], "JobStatus": "STOP_REQUESTED"})

    def list_targeted_sentiment_detection_jobs(self) -> str:
        params = json.loads(self.body)
        job_filter = params.get("Filter")
        jobs = self.comprehend_backend.list_targeted_sentiment_detection_jobs(
            filter=job_filter
        )
        job_list = [job.to_dict() for job in jobs]
        return self._list_jobs_to_dict_resp(job_list, "TargetedSentimentDetection")

    def start_dominant_language_detection_job(self) -> str:
        params = json.loads(self.body)
        job = self.comprehend_backend.start_dominant_language_detection_job(**params)
        return json.dumps(
            {"JobId": job.job_id, "JobArn": job.job_arn, "JobStatus": job.job_status}
        )

    def describe_dominant_language_detection_job(self) -> str:
        params = json.loads(self.body)
        job = self.comprehend_backend.describe_dominant_language_detection_job(
            job_id=params["JobId"]
        )
        return self._job_to_dict_resp(job.to_dict())

    def stop_dominant_language_detection_job(self) -> str:
        params = json.loads(self.body)
        self.comprehend_backend.stop_dominant_language_detection_job(
            job_id=params["JobId"]
        )
        return json.dumps({"JobId": params["JobId"], "JobStatus": "STOP_REQUESTED"})

    def list_dominant_language_detection_jobs(self) -> str:
        params = json.loads(self.body)
        job_filter = params.get("Filter")
        jobs = self.comprehend_backend.list_dominant_language_detection_jobs(
            filter=job_filter
        )
        job_list = [job.to_dict() for job in jobs]
        return self._list_jobs_to_dict_resp(job_list, "DominantLanguageDetection")

    def start_entities_detection_job(self) -> str:
        params = json.loads(self.body)
        job = self.comprehend_backend.start_entities_detection_job(**params)
        return json.dumps(
            {"JobId": job.job_id, "JobArn": job.job_arn, "JobStatus": job.job_status}
        )

    def describe_entities_detection_job(self) -> str:
        params = json.loads(self.body)
        job = self.comprehend_backend.describe_entities_detection_job(
            job_id=params["JobId"]
        )
        return self._job_to_dict_resp(job.to_dict())

    def stop_entities_detection_job(self) -> str:
        params = json.loads(self.body)
        self.comprehend_backend.stop_entities_detection_job(job_id=params["JobId"])
        return json.dumps({"JobId": params["JobId"], "JobStatus": "STOP_REQUESTED"})

    def list_entities_detection_jobs(self) -> str:
        params = json.loads(self.body)
        job_filter = params.get("Filter")
        jobs = self.comprehend_backend.list_entities_detection_jobs(filter=job_filter)
        job_list = [job.to_dict() for job in jobs]
        return self._list_jobs_to_dict_resp(job_list, "EntitiesDetection")

    def start_topics_detection_job(self) -> str:
        params = json.loads(self.body)
        job = self.comprehend_backend.start_topics_detection_job(**params)
        return json.dumps(
            {"JobId": job.job_id, "JobArn": job.job_arn, "JobStatus": job.job_status}
        )

    def describe_topics_detection_job(self) -> str:
        params = json.loads(self.body)
        job = self.comprehend_backend.describe_topics_detection_job(
            job_id=params["JobId"]
        )
        return self._job_to_dict_resp(job.to_dict())

    def list_topics_detection_jobs(self) -> str:
        params = json.loads(self.body)
        job_filter = params.get("Filter")
        jobs = self.comprehend_backend.list_topics_detection_jobs(filter=job_filter)
        job_list = [job.to_dict() for job in jobs]
        return self._list_jobs_to_dict_resp(job_list, "TopicsDetection")

    def start_document_classification_job(self) -> str:
        params = json.loads(self.body)
        job = self.comprehend_backend.start_document_classification_job(**params)
        return json.dumps(
            {"JobId": job.job_id, "JobArn": job.job_arn, "JobStatus": job.job_status}
        )

    def describe_document_classification_job(self) -> str:
        params = json.loads(self.body)
        job = self.comprehend_backend.describe_document_classification_job(
            job_id=params["JobId"]
        )
        return self._job_to_dict_resp(job.to_dict())

    def list_document_classification_jobs(self) -> str:
        params = json.loads(self.body)
        job_filter = params.get("Filter")
        jobs = self.comprehend_backend.list_document_classification_jobs(
            filter=job_filter
        )
        job_list = [job.to_dict() for job in jobs]
        return self._list_jobs_to_dict_resp(job_list, "DocumentClassification")

    def start_events_detection_job(self) -> str:
        params = json.loads(self.body)
        job = self.comprehend_backend.start_events_detection_job(**params)
        return json.dumps(
            {"JobId": job.job_id, "JobArn": job.job_arn, "JobStatus": job.job_status}
        )

    def describe_events_detection_job(self) -> str:
        params = json.loads(self.body)
        job = self.comprehend_backend.describe_events_detection_job(
            job_id=params["JobId"]
        )
        return self._job_to_dict_resp(job.to_dict())

    def stop_events_detection_job(self) -> str:
        params = json.loads(self.body)
        self.comprehend_backend.stop_events_detection_job(job_id=params["JobId"])
        return json.dumps({"JobId": params["JobId"], "JobStatus": "STOP_REQUESTED"})

    def list_events_detection_jobs(self) -> str:
        params = json.loads(self.body)
        job_filter = params.get("Filter")
        jobs = self.comprehend_backend.list_events_detection_jobs(filter=job_filter)
        job_list = [job.to_dict() for job in jobs]
        return self._list_jobs_to_dict_resp(job_list, "EventsDetection")