/oci-language-translate.sql Secret
Created
February 27, 2023 05:04
OCI Languageサービスの翻訳リクエストを発行する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare | |
/* OCI Languageの翻訳処理のエンドポイント */ | |
C_ENDPOINT constant varchar2(120) := 'https://language.aiservice.us-ashburn-1.oci.oraclecloud.com/20221001/actions/batchLanguageTranslation'; | |
l_request json_object_t; | |
l_request_clob clob; | |
l_response json_object_t; | |
l_response_clob clob; | |
l_documents json_array_t; | |
l_document json_object_t; | |
begin | |
/* 翻訳を依頼するメッセージを作成する。 */ | |
l_request := json_object_t(); | |
l_document := json_object_t(); | |
l_document.put('key', '1'); | |
l_document.put('text', :P1_SOURCE_TEXT); | |
l_document.put('languageCode',:P1_SOURCE_LANG); | |
l_documents := json_array_t(); | |
l_documents.append(l_document); | |
l_request.put('documents',l_documents); | |
l_request.put('targetLanguageCode',:P1_TARGET_LANG); | |
l_request_clob := l_request.to_clob(); | |
/* 翻訳リクエストの発行 */ | |
apex_web_service.clear_request_headers(); | |
apex_web_service.set_request_headers('Content-Type','application/json'); | |
l_response_clob := apex_web_service.make_rest_request( | |
p_url => C_ENDPOINT | |
,p_http_method => 'POST' | |
,p_body => l_request_clob | |
,p_credential_static_id => 'OCI_API_ACCESS' | |
); | |
/* 応答のすべてをJSON形式で確認する。 */ | |
-- :P1_TARGET_TEXT := l_response_clob; | |
/* 翻訳された文章だけを確認する。 */ | |
l_response := json_object_t(l_response_clob); | |
l_documents := l_response.get_array('documents'); | |
/* 送信したkeyは1だけなので、翻訳された文章も1つだけ */ | |
l_document := json_object_t(l_documents.get(0)); | |
:P1_TARGET_TEXT := l_document.get_string('translatedText'); | |
end; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment