Skip to content

Commit 044ca48

Browse files
authored
Add Comprehend client (#1259)
* Add Comprehend client * Added tests * fixed broken tests * Update baseline * Updated docs
0 parents  commit 044ca48

25 files changed

+751
-0
lines changed

.gitattributes

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/.github export-ignore
2+
/tests export-ignore
3+
/.gitignore export-ignore
4+
/Makefile export-ignore
5+
/phpunit.xml.dist export-ignore

.github/FUNDING.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# These are supported funding model platforms
2+
3+
github: [nyholm, jderusse]

.github/workflows/.editorconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[*.yml]
2+
indent_size = 2

.github/workflows/branch_alias.yml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: Update branch alias
2+
3+
on:
4+
push:
5+
tags: ['*']
6+
7+
jobs:
8+
branch-alias:
9+
name: Update branch alias
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Set up PHP
14+
uses: shivammathur/setup-php@v2
15+
with:
16+
php-version: 8.1
17+
coverage: none
18+
19+
- name: Find branch alias
20+
id: find_alias
21+
run: |
22+
TAG=$(echo $GITHUB_REF | cut -d'/' -f 3)
23+
echo "Last tag was $TAG"
24+
ARR=(${TAG//./ })
25+
ARR[1]=$((${ARR[1]}+1))
26+
echo ::set-output name=alias::${ARR[0]}.${ARR[1]}
27+
28+
- name: Checkout main repo
29+
run: |
30+
git clone --branch master https://${{ secrets.BOT_GITHUB_TOKEN }}:x-oauth-basic@github.com/async-aws/aws aws
31+
32+
- name: Update branch alias
33+
run: |
34+
cd aws/src/Service/Comprehend
35+
CURRENT_ALIAS=$(composer config extra.branch-alias.dev-master | cut -d'-' -f 1)
36+
37+
# If there is a current value on the branch alias
38+
if [ ! -z $CURRENT_ALIAS ]; then
39+
NEW_ALIAS=${{ steps.find_alias.outputs.alias }}
40+
CURRENT_ARR=(${CURRENT_ALIAS//./ })
41+
NEW_ARR=(${NEW_ALIAS//./ })
42+
43+
if [ ${CURRENT_ARR[0]} -gt ${NEW_ARR[0]} ]; then
44+
echo "The current value for major version is larger"
45+
exit 1;
46+
fi
47+
48+
if [ ${CURRENT_ARR[0]} -eq ${NEW_ARR[0]} ] && [ ${CURRENT_ARR[1]} -gt ${NEW_ARR[1]} ]; then
49+
echo "The current value for minor version is larger"
50+
exit 1;
51+
fi
52+
fi
53+
54+
composer config extra.branch-alias.dev-master ${{ steps.find_alias.outputs.alias }}-dev
55+
56+
- name: Commit & push the new files
57+
run: |
58+
echo "::group::git status"
59+
cd aws
60+
git status
61+
echo "::endgroup::"
62+
63+
git add -N .
64+
if [[ $(git diff --numstat | wc -l) -eq 0 ]]; then
65+
echo "No changes found. Exiting."
66+
exit 0;
67+
fi
68+
69+
git config --local user.email "github@async-aws.com"
70+
git config --local user.name "AsyncAws Bot"
71+
72+
echo "::group::git push"
73+
git add .
74+
git commit -m "Update branch alias"
75+
git push
76+
echo "::endgroup::"

.github/workflows/checks.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: BC Check
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
8+
jobs:
9+
roave-bc-check:
10+
name: Roave BC Check
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v2
16+
17+
- name: Modify composer.json
18+
run: |
19+
sed -i -re 's/"require": \{/"minimum-stability": "dev","prefer-stable": true,"require": \{/' composer.json
20+
cat composer.json
21+
22+
git config --local user.email "github@async-aws.com"
23+
git config --local user.name "AsyncAws Bot"
24+
git commit -am "Allow unstable dependencies"
25+
26+
- name: Roave BC Check
27+
uses: docker://nyholm/roave-bc-check-ga

.github/workflows/ci.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
8+
jobs:
9+
10+
build:
11+
name: Build
12+
runs-on: ubuntu-latest
13+
strategy:
14+
max-parallel: 10
15+
matrix:
16+
php: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2']
17+
18+
steps:
19+
- name: Set up PHP
20+
uses: shivammathur/setup-php@v2
21+
with:
22+
php-version: ${{ matrix.php }}
23+
coverage: none
24+
25+
- name: Checkout code
26+
uses: actions/checkout@v2
27+
28+
- name: Initialize tests
29+
run: make initialize
30+
31+
- name: Download dependencies
32+
run: |
33+
composer config minimum-stability dev
34+
composer req symfony/phpunit-bridge --no-update
35+
composer update --no-interaction --prefer-dist --optimize-autoloader --prefer-stable
36+
37+
- name: Run tests
38+
run: ./vendor/bin/simple-phpunit

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/vendor/
2+
*.cache
3+
composer.lock

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Change Log
2+
3+
## NOT RELEASED
4+
5+
## 0.1.0
6+
7+
First version

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2022 Jérémy Derussé, Tobias Nyholm
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

Makefile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.EXPORT_ALL_VARIABLES:
2+
3+
initialize: start-docker
4+
start-docker:
5+
echo "Noop"
6+
7+
test: initialize
8+
./vendor/bin/simple-phpunit
9+
10+
clean: stop-docker
11+
stop-docker:
12+
echo "Noop"

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# AsyncAws Comprehend Client
2+
3+
![](https://github.com/async-aws/comprehend/workflows/Tests/badge.svg?branch=master)
4+
![](https://github.com/async-aws/comprehend/workflows/BC%20Check/badge.svg?branch=master)
5+
6+
An API client for Comprehend.
7+
8+
## Install
9+
10+
```cli
11+
composer require async-aws/comprehend
12+
```
13+
14+
## Documentation
15+
16+
See https://async-aws.com/clients/comprehend.html for documentation.
17+
18+
## Contribute
19+
20+
Contributions are welcome and appreciated. Please read https://async-aws.com/contribute/

composer.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"name": "async-aws/comprehend",
3+
"description": "Comprehend client, part of the AWS SDK provided by AsyncAws.",
4+
"license": "MIT",
5+
"type": "library",
6+
"keywords": [
7+
"aws",
8+
"amazon",
9+
"sdk",
10+
"async-aws",
11+
"comprehend"
12+
],
13+
"require": {
14+
"php": "^7.2.5 || ^8.0",
15+
"ext-json": "*",
16+
"async-aws/core": "^1.9"
17+
},
18+
"autoload": {
19+
"psr-4": {
20+
"AsyncAws\\Comprehend\\": "src"
21+
}
22+
},
23+
"autoload-dev": {
24+
"psr-4": {
25+
"AsyncAws\\Comprehend\\Tests\\": "tests/"
26+
}
27+
},
28+
"extra": {
29+
"branch-alias": {
30+
"dev-master": "0.1-dev"
31+
}
32+
}
33+
}

phpunit.xml.dist

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
4+
backupGlobals="false"
5+
colors="true"
6+
bootstrap="vendor/autoload.php"
7+
failOnRisky="true"
8+
failOnWarning="true"
9+
>
10+
<coverage>
11+
<include>
12+
<directory>./src</directory>
13+
</include>
14+
</coverage>
15+
<php>
16+
<ini name="error_reporting" value="-1"/>
17+
</php>
18+
<testsuites>
19+
<testsuite name="Test Suite">
20+
<directory>./tests/</directory>
21+
</testsuite>
22+
</testsuites>
23+
</phpunit>

src/ComprehendClient.php

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<?php
2+
3+
namespace AsyncAws\Comprehend;
4+
5+
use AsyncAws\Comprehend\Exception\InternalServerException;
6+
use AsyncAws\Comprehend\Exception\InvalidRequestException;
7+
use AsyncAws\Comprehend\Exception\TextSizeLimitExceededException;
8+
use AsyncAws\Comprehend\Input\DetectDominantLanguageRequest;
9+
use AsyncAws\Comprehend\Result\DetectDominantLanguageResponse;
10+
use AsyncAws\Core\AbstractApi;
11+
use AsyncAws\Core\AwsError\AwsErrorFactoryInterface;
12+
use AsyncAws\Core\AwsError\JsonRpcAwsErrorFactory;
13+
use AsyncAws\Core\Configuration;
14+
use AsyncAws\Core\RequestContext;
15+
16+
class ComprehendClient extends AbstractApi
17+
{
18+
/**
19+
* Determines the dominant language of the input text. For a list of languages that Amazon Comprehend can detect, see
20+
* Amazon Comprehend Supported Languages.
21+
*
22+
* @see https://docs.aws.amazon.com/comprehend/latest/dg/how-languages.html
23+
* @see https://docs.aws.amazon.com/comprehend/latest/dg/API_DetectDominantLanguage.html
24+
* @see https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-comprehend-2017-11-27.html#detectdominantlanguage
25+
*
26+
* @param array{
27+
* Text: string,
28+
* @region?: string,
29+
* }|DetectDominantLanguageRequest $input
30+
*
31+
* @throws InvalidRequestException
32+
* @throws TextSizeLimitExceededException
33+
* @throws InternalServerException
34+
*/
35+
public function detectDominantLanguage($input): DetectDominantLanguageResponse
36+
{
37+
$input = DetectDominantLanguageRequest::create($input);
38+
$response = $this->getResponse($input->request(), new RequestContext(['operation' => 'DetectDominantLanguage', 'region' => $input->getRegion(), 'exceptionMapping' => [
39+
'InvalidRequestException' => InvalidRequestException::class,
40+
'TextSizeLimitExceededException' => TextSizeLimitExceededException::class,
41+
'InternalServerException' => InternalServerException::class,
42+
]]));
43+
44+
return new DetectDominantLanguageResponse($response);
45+
}
46+
47+
protected function getAwsErrorFactory(): AwsErrorFactoryInterface
48+
{
49+
return new JsonRpcAwsErrorFactory();
50+
}
51+
52+
protected function getEndpointMetadata(?string $region): array
53+
{
54+
if (null === $region) {
55+
$region = Configuration::DEFAULT_REGION;
56+
}
57+
58+
switch ($region) {
59+
case 'us-iso-east-1':
60+
return [
61+
'endpoint' => 'https://comprehend.us-iso-east-1.c2s.ic.gov',
62+
'signRegion' => 'us-iso-east-1',
63+
'signService' => 'comprehend',
64+
'signVersions' => ['v4'],
65+
];
66+
case 'fips-us-east-1':
67+
return [
68+
'endpoint' => 'https://comprehend-fips.us-east-1.amazonaws.com',
69+
'signRegion' => 'us-east-1',
70+
'signService' => 'comprehend',
71+
'signVersions' => ['v4'],
72+
];
73+
case 'fips-us-east-2':
74+
return [
75+
'endpoint' => 'https://comprehend-fips.us-east-2.amazonaws.com',
76+
'signRegion' => 'us-east-2',
77+
'signService' => 'comprehend',
78+
'signVersions' => ['v4'],
79+
];
80+
case 'fips-us-gov-west-1':
81+
return [
82+
'endpoint' => 'https://comprehend-fips.us-gov-west-1.amazonaws.com',
83+
'signRegion' => 'us-gov-west-1',
84+
'signService' => 'comprehend',
85+
'signVersions' => ['v4'],
86+
];
87+
case 'fips-us-west-2':
88+
return [
89+
'endpoint' => 'https://comprehend-fips.us-west-2.amazonaws.com',
90+
'signRegion' => 'us-west-2',
91+
'signService' => 'comprehend',
92+
'signVersions' => ['v4'],
93+
];
94+
}
95+
96+
return [
97+
'endpoint' => "https://comprehend.$region.amazonaws.com",
98+
'signRegion' => $region,
99+
'signService' => 'comprehend',
100+
'signVersions' => ['v4'],
101+
];
102+
}
103+
}

0 commit comments

Comments
 (0)