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