-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
53,162 additions
and
44,753 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "file://zonbook/docbookx.dtd" [ | ||
<!ENTITY % phrases-shared SYSTEM "file://AWSShared/common/phrases-shared.ent"> | ||
%phrases-shared; | ||
]> | ||
<block> | ||
<para> | ||
This example application analyzes and stores customer feedback cards. Specifically, | ||
it fulfills the need of a fictitious hotel in New York City. The hotel receives feedback | ||
from guests in various languages in the form of physical comment cards. That feedback | ||
is uploaded into the app through a web client. | ||
|
||
After an image of a comment card is uploaded, the following steps occur: | ||
</para> | ||
<itemizedlist> | ||
<listitem> | ||
<para>Text is extracted from the image using &TEXTRACT;.</para> | ||
</listitem> | ||
<listitem> | ||
<para>&CMP; determines the sentiment of the extracted text and its language.</para> | ||
</listitem> | ||
<listitem> | ||
<para>The extracted text is translated to French using &TSL;.</para> | ||
</listitem> | ||
<listitem> | ||
<para>&POL; synthesizes an audio file from the extracted text.</para> | ||
</listitem> | ||
</itemizedlist> | ||
<para> The full app can be deployed with the &CDK;. For source code and deployment | ||
instructions, see the project in <ulink | ||
url="https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/javascriptv3/example_code/cross-services/feedback-sentiment-analyzer"> | ||
GitHub</ulink>. </para> | ||
</block> |
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
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
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
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
1 change: 1 addition & 0 deletions
1
...iptv3/example_code/cross-services/feedback-sentiment-analyzer/AnalyzeSentiment/.gitignore
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dist |
19 changes: 19 additions & 0 deletions
19
...tv3/example_code/cross-services/feedback-sentiment-analyzer/AnalyzeSentiment/package.json
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"name": "example-javascriptv3-fsa-analyze-sentiment", | ||
"version": "1.0.0", | ||
"description": "Companion AWS Lambda functions for the Feedback Sentiment Analyzer Example.", | ||
"main": "index.js", | ||
"type": "module", | ||
"scripts": { | ||
"test": "vitest run **/*.unit.test.js", | ||
"build": "rollup -c" | ||
}, | ||
"author": "Corey Pyle <[email protected]>", | ||
"license": "Apache-2.0", | ||
"devDependencies": { | ||
"@aws-sdk/client-comprehend": "^3.388.0", | ||
"@rollup/plugin-commonjs": "^25.0.3", | ||
"@rollup/plugin-node-resolve": "^15.1.0", | ||
"rollup": "^3.28.0" | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...example_code/cross-services/feedback-sentiment-analyzer/AnalyzeSentiment/rollup.config.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { nodeResolve } from "@rollup/plugin-node-resolve"; | ||
import commonjs from "@rollup/plugin-commonjs"; | ||
|
||
export default { | ||
input: "src/index.js", | ||
output: { | ||
/** | ||
* The Lambda NodeJS runtime requires .mjs extensions to use ESM. | ||
*/ | ||
file: "dist/index.mjs", | ||
compact: true, | ||
format: "es", | ||
}, | ||
|
||
plugins: [ | ||
/** | ||
* By default Rollup will not bundle node_modules. This plugin allows that. | ||
*/ | ||
nodeResolve({ preferBuiltins: true }), | ||
/** | ||
* Allows CJS files to be included in bundle. This is mainly for Lodash. | ||
*/ | ||
commonjs(), | ||
], | ||
external: [ | ||
/** | ||
* Don't bundle the @aws-sdk. It's included in the Lambda NodeJS runtime. | ||
*/ | ||
/@aws-sdk/, | ||
], | ||
}; |
43 changes: 43 additions & 0 deletions
43
...tv3/example_code/cross-services/feedback-sentiment-analyzer/AnalyzeSentiment/src/index.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { | ||
ComprehendClient, | ||
DetectDominantLanguageCommand, | ||
DetectSentimentCommand, | ||
} from "@aws-sdk/client-comprehend"; | ||
|
||
/** | ||
* Determine the language and sentiment of the extracted text. | ||
* | ||
* @param {{ source_text: string}} extractTextOutput | ||
*/ | ||
export const handler = async (extractTextOutput) => { | ||
const comprehendClient = new ComprehendClient({}); | ||
|
||
const detectDominantLanguageCommand = new DetectDominantLanguageCommand({ | ||
Text: extractTextOutput.source_text, | ||
}); | ||
|
||
// The source language is required for sentiment analysis and | ||
// translation in the next step. | ||
const {Languages} = await comprehendClient.send( | ||
detectDominantLanguageCommand | ||
); | ||
|
||
const languageCode = Languages[0].LanguageCode; | ||
|
||
const detectSentimentCommand = new DetectSentimentCommand({ | ||
Text: extractTextOutput.source_text, | ||
LanguageCode: languageCode, | ||
}); | ||
|
||
const {Sentiment} = await comprehendClient.send(detectSentimentCommand); | ||
|
||
return { | ||
sentiment: Sentiment, | ||
language_code: languageCode, | ||
}; | ||
}; |
33 changes: 33 additions & 0 deletions
33
...feedback-sentiment-analyzer/AnalyzeSentiment/tests/analyze-sentiment-handler.unit.test.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import {describe, it, expect, vi} from "vitest"; | ||
|
||
const send = vi.fn(() => Promise.resolve()); | ||
|
||
vi.doMock("@aws-sdk/client-comprehend", async () => { | ||
const actual = await vi.importActual("@aws-sdk/client-comprehend"); | ||
return { | ||
...actual, | ||
ComprehendClient: class { | ||
send = send; | ||
}, | ||
}; | ||
}); | ||
|
||
const {handler} = await import("../src/index.js"); | ||
|
||
describe("analyze-sentiment-handler", () => { | ||
it("should return an object with the sentiment and language_code", async () => { | ||
send | ||
.mockResolvedValueOnce({ | ||
Languages: [{LanguageCode: "fr"}], | ||
}) | ||
.mockResolvedValueOnce({ | ||
Sentiment: "POSITIVE", | ||
}); | ||
|
||
const response = await handler({source_text: "J'adore."}); | ||
expect(response).toEqual({ | ||
sentiment: "POSITIVE", | ||
language_code: "fr", | ||
}); | ||
}); | ||
}); |
1 change: 1 addition & 0 deletions
1
javascriptv3/example_code/cross-services/feedback-sentiment-analyzer/ExtractText/.gitignore
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dist |
Oops, something went wrong.