Skip to content

Commit 6fa5231

Browse files
author
Chris Park
committed
Merge branch 'develop'
2 parents e802af2 + 39d1b8b commit 6fa5231

File tree

13 files changed

+263
-34
lines changed

13 files changed

+263
-34
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rosette/api",
3-
"version": "1.5.0",
3+
"version": "1.7.0",
44
"description": "Rosette API PHP client SDK",
55
"license": "Apache",
66
"keywords": [

examples/README.md

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,41 @@ PHP Examples
33

44
These examples are scripts that can be run independently to demonstrate the Rosette API functionality.
55

6-
You can now run your desired _endpoint_.php file to see it in action. Before running the examples
6+
You can now run your desired _endpoint_.php file to see it in action. Before running the examples
77
for the first time:
8-
1. cd examples
9-
2. composer update
8+
9+
1. ```cd examples```
10+
2. ```composer update```
11+
3. The examples are dual purpose in that they're used to test both source and packagist. In order to meet that requirement, the examples expect the vendor directory to be at the same level as examples/.
12+
```cp -r ./vendor/. ../vendor``` or you can edit the example to reference the vendor directory that is in the examples directory.
1013

1114
For example, run `php categories.php` if you want to see the categories functionality demonstrated.
1215

1316
All files require you to input your Rosette API User Key after `--key` to run.
14-
For example: `php ping.php --key 1234567890`
15-
All also allow you to input your own service URL if applicable.
17+
For example: `php ping.php --key 1234567890`
18+
All also allow you to input your own service URL if applicable.
1619
For example: `php ping.php --key 1234567890 --url http://www.myurl.com`
1720

1821

1922
Each example, when run, prints its output to the console.
2023

21-
| File Name | What it does |
22-
| ------------- |------------- |
23-
| categories.php | Gets the category of a document at a URL |
24-
| entities.php | Gets the entities from a piece of text |
25-
| info.php | Gets information about Rosette API |
26-
| language.php | Gets the language of a piece of text |
27-
| matched-name.php | Gets the similarity score of two names |
28-
| morphology_complete.php | Gets the complete morphological analysis of a piece of text|
29-
| morphology_compound-components.php | Gets the de-compounded words from a piece of text |
30-
| morphology_han-readings.php | Gets the Chinese words from a piece of text |
31-
| morphology_lemmas.php | Gets the lemmas of words from a piece of text |
32-
| morphology_parts-of-speech.php | Gets the part-of-speech tags for words in a piece of text |
33-
| ping.php | Pings the Rosette API to check for reachability |
24+
| File Name | What it does |
25+
| ------------- |------------- |
26+
| categories.php | Gets the category of a document at a URL |
27+
| entities.php | Gets the entities from a piece of text |
28+
| info.php | Gets information about Rosette API |
29+
| language.php | Gets the language of a piece of text |
30+
| morphology_complete.php | Gets the complete morphological analysis of a piece of text|
31+
| morphology_compound-components.php | Gets the de-compounded words from a piece of text |
32+
| morphology_han-readings.php | Gets the Chinese words from a piece of text |
33+
| morphology_lemmas.php | Gets the lemmas of words from a piece of text |
34+
| morphology_parts-of-speech.php | Gets the part-of-speech tags for words in a piece of text |
35+
| name_deduplication.php | Fuzzy deduplication of a list of names |
36+
| name_translation.php | Translates a name from one language to another |
37+
| name_similarity.php | Gets the similarity score of two names |
38+
| ping.php | Pings the Rosette API to check for reachability |
3439
| sentences.php | Gets the sentences from a piece of text |
35-
| sentiment.php | Gets the sentiment of a local file |
36-
| tokens.php | Gets the tokens (words) from a piece of text |
37-
| translated-name.php | Translates a name from one language to another |
40+
| sentiment.php | Gets the sentiment of a local file |
41+
| tokens.php | Gets the tokens (words) from a piece of text |
42+
| transliteration.php | Transliterates content |
3843

examples/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"require": {
3+
"rmccue/requests": ">1.0",
34
"rosette/api": ">=1.0"
45
}
56
}

examples/docker/Dockerfile

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,39 @@
1-
FROM php:5.5-cli
1+
FROM phusion/baseimage
22
MAINTAINER Fiona Hasanaj
3+
ENV TZ=America/New_York
4+
ENV LANGUAGE=php
35

46
# install necessary software
5-
RUN apt-get -y update && apt-get install -y vim && apt-get install -y git
7+
8+
RUN apt-get -y update && apt-get install -y \
9+
git \
10+
language-pack-en-base \
11+
libxslt1-dev \
12+
python-software-properties \
13+
vim \
14+
wget
15+
16+
RUN LC_ALL=en_US.UTF-8 add-apt-repository ppa:ondrej/php
17+
RUN apt-get -y update && apt-get install -y \
18+
php-dev \
19+
php-cli \
20+
php-curl \
21+
libapache2-mod-php
22+
23+
24+
RUN echo "memory_limit=-1" >> /etc/php/7.1/cli/php.ini && \
25+
echo "date.timezone=America/New_York" >> /etc/php/7.1/cli/php.ini
26+
27+
RUN wget -O /usr/local/bin/composer https://getcomposer.org/composer.phar && \
28+
chmod +x /usr/local/bin/composer && composer self-update
629

730
# install mbstring
8-
RUN docker-php-ext-install mbstring
31+
# RUN docker-php-ext-install mbstring
932

1033
COPY run_php.sh /php/examples/run_php.sh
1134
RUN chmod 755 /php/examples/run_php.sh
1235
WORKDIR /php/examples
1336

14-
# install composer.phar
15-
RUN curl -sS https://getcomposer.org/installer | php && mv composer.phar /usr/local/bin/composer && composer require "rosette/api: ~1.0.0"
16-
1737
# allow interactive bash inside docker container
1838
CMD ./run_php.sh $API_KEY $ALT_URL
1939

examples/docker/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
To simplify the running of the PHP examples, the Dockerfile will build an image and install the latest rosette-api library.
66

77
### Basic Usage
8-
Build the docker image, e.g. `docker build -t basistech/php:1.1 .`
8+
Build the docker image, e.g. `docker build -t basistech/php .`
99

1010
Run an example as `docker run -e API_KEY=api-key -v "path-to-example-source:/source" basistech/php:1.1`
1111

examples/docker/run_php.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ validateURL
8989

9090
#Copy the examples from the mounted content in /source to current WORKDIR
9191
cp /source/examples/*.* .
92+
composer install
93+
cp -r ./vendor/. ../vendor
9294

9395
#Run the examples
9496
if [ ! -z ${API_KEY} ]; then

examples/name_deduplication.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
/**
4+
* Example code to call Rosette API to deduplicate a list of names.
5+
**/
6+
require_once dirname(__FILE__) . '/../vendor/autoload.php';
7+
use rosette\api\Api;
8+
use rosette\api\Name;
9+
use rosette\api\NameDeduplicationParameters;
10+
use rosette\api\RosetteException;
11+
12+
$options = getopt(null, array('key:', 'url::'));
13+
if (!isset($options['key'])) {
14+
echo 'Usage: php ' . __FILE__ . " --key <api_key> --url=<alternate_url>\n";
15+
exit();
16+
}
17+
$name_dedupe_data = "John Smith,Johnathon Smith,Fred Jones";
18+
19+
$dedup_array = array();
20+
$threshold = 0.75;
21+
foreach (explode(',', $name_dedupe_data) as $name) {
22+
array_push($dedup_array, new Name($name));
23+
}
24+
$api = isset($options['url']) ? new Api($options['key'], $options['url']) : new Api($options['key']);
25+
$params = new NameDeduplicationParameters($dedup_array, $threshold);
26+
27+
try {
28+
$result = $api->nameDeduplication($params);
29+
var_dump($result);
30+
} catch (RosetteException $e) {
31+
error_log($e);
32+
}

examples/syntax_dependencies.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
$params = new DocumentParameters();
1919
$content = $syntax_dependencies_data;
2020
$params->set('content', $content);
21-
$params->set('genre', 'social-media');
2221

2322
try {
2423
$result = $api->syntaxDependencies($params, false);

examples/transliteration.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
/**
4+
* Example code to call Rosette API to transliterate content.
5+
**/
6+
require_once dirname(__FILE__) . '/../vendor/autoload.php';
7+
use rosette\api\Api;
8+
use rosette\api\DocumentParameters;
9+
use rosette\api\RosetteException;
10+
11+
$options = getopt(null, array('key:', 'url::'));
12+
if (!isset($options['key'])) {
13+
echo 'Usage: php ' . __FILE__ . " --key <api_key> --url=<alternate_url>\n";
14+
exit();
15+
}
16+
$transliteration_data = "معمر محمد أبو منيار القذاف";
17+
$api = isset($options['url']) ? new Api($options['key'], $options['url']) : new Api($options['key']);
18+
$params = new DocumentParameters();
19+
$params->set('content', $transliteration_data);
20+
21+
try {
22+
$result = $api->transliteration($params);
23+
var_dump($result);
24+
} catch (RosetteException $e) {
25+
error_log($e);
26+
}

source/rosette/api/Api.php

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class Api
3838
*
3939
* @var string
4040
*/
41-
private static $binding_version = '1.5.0';
41+
private static $binding_version = '1.7.0';
4242

4343
/**
4444
* User key (required for Rosette API).
@@ -126,7 +126,7 @@ public function __construct($user_key, $service_url = 'https://api.rosette.com/r
126126
$this->url_params = array();
127127
$this->customHeaders = array();
128128
}
129-
129+
130130
/**
131131
* Sets on override Request for mocking purposes
132132
*
@@ -365,7 +365,7 @@ public function getResponseHeader()
365365
{
366366
return $this->request->getResponseHeader();
367367
}
368-
368+
369369
/** Internal operations processor for most of the endpoints.
370370
*
371371
* @param $parameters
@@ -650,6 +650,20 @@ public function nameSimilarity($nameSimilarityParams)
650650
return $this->callEndpoint($nameSimilarityParams, 'name-similarity');
651651
}
652652

653+
/**
654+
* Calls the name deduplication endpoint.
655+
*
656+
* @param $nameDeduplicationParams
657+
*
658+
* @return mixed
659+
*
660+
* @throws RosetteException
661+
*/
662+
public function nameDeduplication($nameDeduplicationParams)
663+
{
664+
return $this->callEndpoint($nameDeduplicationParams, 'name-deduplication');
665+
}
666+
653667
/**
654668
* Calls the relationships endpoint.
655669
*
@@ -691,4 +705,18 @@ public function syntaxDependencies($params)
691705
{
692706
return $this->callEndpoint($params, 'syntax/dependencies');
693707
}
708+
709+
/**
710+
* Calls the transliteration endpoint
711+
*
712+
* @param $params
713+
*
714+
* @return mixed
715+
*
716+
* @throws RosetteException
717+
*/
718+
public function transliteration($params)
719+
{
720+
return $this->callEndpoint($params, 'transliteration');
721+
}
694722
}

0 commit comments

Comments
 (0)