Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .doc_gen/metadata/comprehend_metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,14 @@ comprehend_DetectSentiment:
snippet_tags:
- python.example_code.comprehend.ComprehendDetect
- python.example_code.comprehend.DetectSentiment
SAP ABAP:
versions:
- sdk_version: 1
github: sap-abap/services/cpd
excerpts:
- description:
snippet_tags:
- cpd.abapv1.detect_sentiment
services:
comprehend: {DetectSentiment}
comprehend_DetectSyntax:
Expand Down
1 change: 1 addition & 0 deletions .tools/readmes/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@
"service_folder_overrides": {
"bedrock-runtime": "sap-abap/services/bdr",
"bedrock-agent-runtime": "sap-abap/services/bdz",
"comprehend": "sap-abap/services/cpd",
"dynamodb": "sap-abap/services/dyn",
},
}
Expand Down
78 changes: 78 additions & 0 deletions sap-abap/services/cpd/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Amazon Comprehend code examples for the SDK for SAP ABAP

## Overview

Shows how to use the AWS SDK for SAP ABAP to work with Amazon Comprehend.

<!--custom.overview.start-->
<!--custom.overview.end-->

_Amazon Comprehend uses natural language processing (NLP) to extract insights about the content of documents without the need of any special preprocessing._

## ⚠ Important

* Running this code might result in charges to your AWS account. For more details, see [AWS Pricing](https://aws.amazon.com/pricing/) and [Free Tier](https://aws.amazon.com/free/).
* Running the tests might result in charges to your AWS account.
* We recommend that you grant your code least privilege. At most, grant only the minimum permissions required to perform the task. For more information, see [Grant least privilege](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#grant-least-privilege).
* This code is not tested in every AWS Region. For more information, see [AWS Regional Services](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services).

<!--custom.important.start-->
<!--custom.important.end-->

## Code examples

### Prerequisites

For prerequisites, see the [README](../../README.md#Prerequisites) in the `sap-abap` folder.


<!--custom.prerequisites.start-->
<!--custom.prerequisites.end-->

### Single actions

Code excerpts that show you how to call individual service functions.

- [DetectSentiment](zcl_aws1_cpd_actions.clas.abap#L32)


<!--custom.examples.start-->
<!--custom.examples.end-->

## Run the examples

### Instructions


<!--custom.instructions.start-->
<!--custom.instructions.end-->



### Tests

⚠ Running tests might result in charges to your AWS account.


To find instructions for running these tests, see the [README](../../README.md#Tests)
in the `sap-abap` folder.



<!--custom.tests.start-->
<!--custom.tests.end-->

## Additional resources

- [Amazon Comprehend Developer Guide](https://docs.aws.amazon.com/comprehend/latest/dg/what-is.html)
- [Amazon Comprehend API Reference](https://docs.aws.amazon.com/comprehend/latest/APIReference/welcome.html)
- [SDK for SAP ABAP Amazon Comprehend reference](https://docs.aws.amazon.com/sdk-for-sap-abap/v1/api/latest/comprehend/index.html)

<!--custom.resources.start-->
<!--custom.resources.end-->

---

Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.

SPDX-License-Identifier: Apache-2.0
10 changes: 10 additions & 0 deletions sap-abap/services/cpd/package.devc.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_DEVC" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<DEVC>
<CTEXT>Package for Amazon Comprehend</CTEXT>
</DEVC>
</asx:values>
</asx:abap>
</abapGit>
47 changes: 47 additions & 0 deletions sap-abap/services/cpd/zcl_aws1_cpd_actions.clas.abap
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
" Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
" SPDX-License-Identifier: Apache-2.0

class ZCL_AWS1_CPD_ACTIONS definition
public
final
create public .

public section.
METHODS detectsentiment
EXPORTING VALUE(oo_result) TYPE REF TO /aws1/cl_cpddetectsentimentrsp .
protected section.
private section.

ENDCLASS.



CLASS ZCL_AWS1_CPD_ACTIONS IMPLEMENTATION.


METHOD detectsentiment.
CONSTANTS cv_pfl TYPE /aws1/rt_profile_id VALUE 'ZCODE_DEMO'.

DATA(lo_session) = /aws1/cl_rt_session_aws=>create( cv_pfl ).
DATA(lo_cpd) = /aws1/cl_cpd_factory=>create( lo_session ).

DATA(lv_text) = |I love unicorns!| .
DATA(lv_language_code) = |en| .


" snippet-start:[cpd.abapv1.detect_sentiment]
TRY.
oo_result = lo_cpd->detectsentiment(
iv_languagecode = lv_language_code
iv_text = lv_text
).

MESSAGE |Detected sentiment: { oo_result->get_sentiment( ) }| TYPE 'I'.

CATCH /aws1/cx_cpdtextsizelmtexcdex INTO DATA(lo_cpdex) .
MESSAGE 'The size of the input text exceeds the limit. Use a smaller document.' TYPE 'E'.

ENDTRY.
" snippet-end:[cpd.abapv1.detect_sentiment]
ENDMETHOD.
ENDCLASS.
37 changes: 37 additions & 0 deletions sap-abap/services/cpd/zcl_aws1_cpd_actions.clas.testclasses.abap
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
" Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
" SPDX-License-Identifier: Apache-2.0

CLASS ltc_zcl_aws1_cpd_actions DEFINITION FOR TESTING
DURATION SHORT
RISK LEVEL HARMLESS.

PRIVATE SECTION.
DATA ao_cpd_actions TYPE REF TO zcl_aws1_cpd_actions.
METHODS: detectsentiment FOR TESTING.
ENDCLASS. "ltc_Zcl_Aws1_Cpd_Actions


CLASS ltc_zcl_aws1_cpd_actions IMPLEMENTATION.

METHOD detectsentiment.
ao_cpd_actions = NEW zcl_aws1_cpd_actions( ).
DATA lo_output TYPE REF TO /aws1/cl_cpddetectsentimentrsp.
DATA(lv_expected_output) = |POSITIVE|.

ao_cpd_actions->detectsentiment(
IMPORTING
oo_result = lo_output ).

DATA(lv_found) = abap_true.
IF lo_output->has_sentiment( ) = abap_true.
IF lo_output->ask_sentiment( ) = lv_expected_output.
lv_found = abap_true.
ENDIF.
ENDIF.

cl_abap_unit_assert=>assert_true(
act = lv_found
msg = |Sentiment detection failed| ).
ENDMETHOD.

ENDCLASS.
17 changes: 17 additions & 0 deletions sap-abap/services/cpd/zcl_aws1_cpd_actions.clas.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<abapGit version="v1.0.0" serializer="LCL_OBJECT_CLAS" serializer_version="v1.0.0">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<VSEOCLASS>
<CLSNAME>ZCL_AWS1_CPD_ACTIONS</CLSNAME>
<LANGU>E</LANGU>
<DESCRIPT>Comprehend Code Example</DESCRIPT>
<STATE>1</STATE>
<CLSCCINCL>X</CLSCCINCL>
<FIXPT>X</FIXPT>
<UNICODE>X</UNICODE>
<WITH_UNIT_TESTS>X</WITH_UNIT_TESTS>
</VSEOCLASS>
</asx:values>
</asx:abap>
</abapGit>
Loading