Skip to content

Commit

Permalink
Merge pull request #82 from rosette-api/WS-3151-1.29.0-updates
Browse files Browse the repository at this point in the history
Ws 3151 1.29.0 updates
  • Loading branch information
seth-mg authored Apr 17, 2024
2 parents bf350a3 + 312e3d3 commit 686c7db
Show file tree
Hide file tree
Showing 12 changed files with 329 additions and 54 deletions.
4 changes: 2 additions & 2 deletions CI.Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// These are Debian images.
def php_versions = [7.3, 7.4, 8.0, 8.1, 8.2]
def php_versions = [7.4, 8.0, 8.1, 8.2, 8.3]

def runVersion(sourceDir, ver) {
mySonarOpts = "-Dsonar.host.url=${env.SONAR_HOST_URL} -Dsonar.login=${env.SONAR_AUTH_TOKEN}"
Expand Down Expand Up @@ -37,7 +37,7 @@ def runVersion(sourceDir, ver) {
${sonarExec} && \
echo && \
echo [INFO] Re-permission files for cleanup. && \
chown -R jenkins:jenkins /source\""
chown -R 9960:9960 /php-source\""
}

node ("docker-light") {
Expand Down
32 changes: 16 additions & 16 deletions CI.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,21 @@ else
bin/phpspec run --config=phpspec.yml --bootstrap=./vendor/autoload.php --no-interaction --format=pretty
fi

echo "*** [${this_script}] Running examples"
pushd examples
for example in $(ls *.php); do
echo "*** [${this_script}] Running ${example} with PHP ${version}"
php ${example} --key ${ROSETTE_API_KEY} > "${example}-output.txt" 2>&1
# Disable error mode for grep
set +e
if grep -q Exception "${example}-output.txt"; then
echo "*** [${this_script}] ${example} failed!"
cat "${example}-output.txt"
rm -f "${example}-output.txt"
exit 1
fi
set -e
rm -f "${example}-output.txt"
done
#echo "*** [${this_script}] Running examples"
#pushd examples
#for example in $(ls *.php); do
# echo "*** [${this_script}] Running ${example} with PHP ${version}"
# php ${example} --key ${ROSETTE_API_KEY} > "${example}-output.txt" 2>&1
# # Disable error mode for grep
# set +e
# if grep -q Exception "${example}-output.txt"; then
# echo "*** [${this_script}] ${example} failed!"
# cat "${example}-output.txt"
# rm -f "${example}-output.txt"
# exit 1
# fi
# set -e
# rm -f "${example}-output.txt"
#done

echo "*** [${this_script}] Finished!"
22 changes: 9 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,30 @@
<a href="https://www.babelstreet.com/rosette"><img src="https://s3.amazonaws.com/styleguide.basistech.com/logos/rosette-logo.png" width="181" height="47" /></a>

---
<a href="https://www.babelstreet.com/rosette"><img src="https://charts.babelstreet.com/icon.png" width="47" height="60"/></a>
# Rosette by Babel Street

[![Packagist](https://img.shields.io/packagist/v/rosette/api.svg?colorB=bright%20green&style=flat)](https://packagist.org/packages/rosette/api)

## Rosette API
The Rosette Text Analytics Platform uses natural language processing, statistical modeling, and machine learning to
analyze unstructured and semi-structured text across 364 language-encoding-script combinations, revealing valuable
information and actionable data. Rosette provides endpoints for extracting entities and relationships, translating and
comparing the similarity of names, categorizing and adding linguistic tags to text and more.
Rosette uses natural language processing, statistical modeling, and machine learning to analyze unstructured and semi-structured text across hundreds of language-script combinations, revealing valuable information and actionable data. Rosette provides endpoints for extracting entities and relationships, translating and comparing the similarity of names, categorizing and adding linguistic tags to text and more. Rosette Server is the on-premises installation of Rosette, with access to Rosette's functions as RESTful web service endpoints. This solves cloud security worries and allows customization (models/indexes) as needed for your business.

## Rosette API Access
- Rosette Cloud [Sign Up](https://developer.rosette.com/signup)

## Quick Start

#### Installation
`composer require "rosette/api"`
```
composer require "rosette/api"
```

#### Examples
View small example programs for each Rosette endpoint
in the [examples](https://github.com/rosette-api/php/tree/develop/examples) directory.

#### Documentation & Support
- [Binding API](https://rosette-api.github.io/php/)
- [Rosette Platform API](https://developer.rosette.com/features-and-functions)
- [Rosette Platform API](https://docs.babelstreet.com/API/en/index-en.html)
- [Binding Release Notes](https://github.com/rosette-api/php/wiki/Release-Notes)
- [Rosette Platform Release Notes](https://support.rosette.com/hc/en-us/articles/360018354971-Release-Notes)
- [Binding/Rosette Platform Compatibility](https://developer.rosette.com/features-and-functions?php#)
- [Support](https://support.rosette.com)
- [Rosette Platform Release Notes](https://babelstreet.my.site.com/support/s/article/Rosette-Cloud-Release-Notes)
- [Support](https://babelstreet.my.site.com/support/s/)
- [Binding License: Apache 2.0](https://github.com/rosette-api/php/blob/develop/LICENSE.txt)

## Binding Developer Information
Expand Down
30 changes: 21 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,37 +1,49 @@
{
"name": "rosette/api",
"version": "1.26.0",
"version": "1.29.0",
"description": "PHP Interface for Rosette Text Analytics",
"type": "library",
"license": "Apache-2.0",
"keywords": [
"address similarity",
"cateogories",
"analyze language",
"babel street",
"categories",
"coreference",
"entity extraction",
"lemmas",
"entity linking",
"event extraction",
"fuzzy matching",
"langauge identification",
"lemmatization",
"match identity",
"morphology",
"name deduplication",
"name similarity",
"name translation",
"ner",
"nlp",
"parts of speech",
"record similarity",
"relationships",
"rosette",
"sentiment",
"semantic similarity",
"semantic vectors",
"sentiment analysis",
"text analytics",
"text embeddings"
"text embeddings",
"tokenization"
],
"authors": [
{
"name": "Babel Street Rosette Ltd",
"email": "php@rosette.com",
"homepage": "https://developer.rosette.com"
"email": "rosette-php@babelstreet.com",
"homepage": "https://babelstreet.com/rosette"
}
],
"support": {
"email": "support@rosette.com",
"issues": "https://github.com/rosette-api/php/issues",
"email": "helpdesk@babelstreet.com",
"issues": "https://babelstreet.my.site.com/support/s/",
"source": "https://github.com/rosette-api/php"
},
"require": {
Expand Down
6 changes: 3 additions & 3 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ These examples are scripts that can be run independently to demonstrate the Rose

Each example file demonstrates one of the capabilities of the Rosette Platform. Each example, when run, prints its output to the console.

Here are some methods for running the examples. Each example will also accept an optional `--url` parameter for
Here are some methods for running the examples. Each example will also accept an optional `--url=` parameter for
overriding the default URL.

Also, the examples are dual purpose in that they're used to test both source and packagist. The instructions include steps to address this depending on what you are testing.
Expand All @@ -15,7 +15,7 @@ A note on prerequisites. Rosette API only supports TLS 1.2 so ensure your toolc
```
git clone [email protected]:rosette-api/php.git
cd php
docker run -it -v $(pwd):/source --entrypoint bash php:7.3-cli
docker run -it -v $(pwd):/source --entrypoint bash php:8.2-cli
apt-get update
apt-get install -y git zip
Expand All @@ -37,7 +37,7 @@ php ping.php --key $API_KEY
```
git clone [email protected]:rosette-api/php.git
cd php
docker run -it -v $(pwd):/source --entrypoint bash php:7.3-cli
docker run -it -v $(pwd):/source --entrypoint bash php:8.2-cli
apt-get update
apt-get install -y git zip
Expand Down
4 changes: 4 additions & 0 deletions examples/entities.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
$content = $entities_text_data;
$params->set('content', $content);

// Starting with 1.29.0, an alternate, in-document coreference server was added. It can be accessed
// using the option below. See the documentation for more information.
// $api->setOption('useIndocServer', true);

try {
$result = $api->entities($params);
var_dump($result);
Expand Down
37 changes: 37 additions & 0 deletions examples/events.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

/**
* Example code to call Rosette API to get events from a piece of text.
**/
require_once dirname(__FILE__) . '/../vendor/autoload.php';
use rosette\api\Api;
use rosette\api\DocumentParameters;
use rosette\api\RosetteException;

$options = getopt('', array('key:', 'url::'));
if (!isset($options['key'])) {
echo 'Usage: php ' . __FILE__ . " --key <api_key> --url=<alternate_url>\n";
exit();
}

$events_text_data = "Alice has a flight to Budapest. She has not booked a hotel.";
$api = isset($options['url']) ? new Api($options['key'], $options['url']) : new Api($options['key']);
$params = new DocumentParameters();
$content = $events_text_data;
$params->set('content', $content);

try {
$result = $api->events($params);
var_dump($result);
} catch (RosetteException $e) {
error_log($e);
}

$api->setOption('negation', 'BOTH');
try {
$result = $api->events($params);
var_dump($result);
} catch (RosetteException $e) {
error_log($e);
}

65 changes: 65 additions & 0 deletions examples/record_similarity.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

/**
* Example code to call Rosette API to compare two lists of records and return a similarity score for each pair of records
**/
require_once dirname(__FILE__) . '/../vendor/autoload.php';
use rosette\api\Api;
use rosette\api\RecordSimilarityParameters;
use rosette\api\RosetteException;

$options = getopt('', array('key:', 'url::'));
if (!isset($options['key'])) {
echo 'Usage: php ' . __FILE__ . " --key <api_key> --url=<alternate_url>\n";
exit();
}

$fields = array(
"primaryName" => array("type" => "rni_name", "weight" => 0.5),
"dob" => array("type" => "rni_date", "weight" => 0.2),
"addr" => array("type" => "rni_address", "weight" => 0.5),
"dob2" => array("type" => "rni_date", "weight" => 0.1)
);

$properties = array(
"threshold" => 0.7,
"includeExplainInfo" => true,
);

$records = array(
"left" => array(
array(
"primaryName" => array("text" => "Ethan R", "language" => "eng", "script" => "Latn", "entityType" => "PERSON", "languageOfOrigin" => "eng"),
"dob" => "1993-04-16",
"addr" => "123 Roadlane Ave",
"dob2" => array("date" => "1993/04/16")
),
array(
"dob" => array("date" => "1993-04-16"),
"primaryName" => array("text" => "Evan R")
)
),
"right" => array(
array(
"dob" => array("date" => "1993-04-16"),
"primaryName" => array("text" => "Seth R", "language" => "eng"),
),
array(
"dob" => array("date" => "1993-04-16"),
"primaryName" => "Ivan R",
"addr" => array("address" => "123 Roadlane Ave"),
"dob2" => array("date" => "1993/04/16")
)

)
);

$api = isset($options['url']) ? new Api($options['key'], $options['url']) : new Api($options['key']);
$params = new RecordSimilarityParameters($fields, $properties, $records);

try {
$result = $api->recordSimilarity($params);
var_dump($result);
} catch (RosetteException $e) {
error_log($e);
}
45 changes: 34 additions & 11 deletions source/rosette/api/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Api
*
* @var string
*/
private static $binding_version = '1.26.0';
private static $binding_version = '1.29.0';

/**
* User key (required for Rosette API).
Expand Down Expand Up @@ -428,7 +428,7 @@ private function callEndpoint($parameters, $subUrl)
// create multipart
$clrf = "\r\n";
$multi = '';
$boundary = md5(time());
$boundary = hash('sha256', (time()));
$multi .= '--' . $boundary . $clrf;
$multi .= 'Content-Type: application/json' . "\r\n";
$multi .= 'Content-Disposition: mixed; name="request"' . "\r\n" . "\r\n";
Expand Down Expand Up @@ -496,9 +496,7 @@ private function makeRequest($url, $headers, $data, $method)
private function getHttp($url, $headers)
{
$method = 'GET';
$response = $this->makeRequest($url, $headers, null, $method);

return $response;
return $this->makeRequest($url, $headers, null, $method);
}

/**
Expand All @@ -520,9 +518,7 @@ private function getHttp($url, $headers)
private function postHttp($url, $headers, $data)
{
$method = 'POST';
$response = $this->makeRequest($url, $headers, $data, $method);

return $response;
return $this->makeRequest($url, $headers, $data, $method);
}

/**
Expand All @@ -535,9 +531,7 @@ private function postHttp($url, $headers, $data)
public function ping()
{
$url = $this->service_url . 'ping';
$resultObject = $this->getHttp($url, $this->headers);

return $resultObject;
return $this->getHttp($url, $this->headers);
}

/**
Expand Down Expand Up @@ -630,6 +624,20 @@ public function entities($params)
return $this->callEndpoint($params, 'entities');
}

/**
* Calls the events endpoint.
*
* @param $params
*
* @return mixed
*
* @throws RosetteException
*/
public function events($params)
{
return $this->callEndpoint($params, 'events');
}


/**
* Calls the categories endpoint.
Expand Down Expand Up @@ -701,6 +709,21 @@ public function nameDeduplication($nameDeduplicationParams)
return $this->callEndpoint($nameDeduplicationParams, 'name-deduplication');
}

/**
* Calls the record similarity endpoint.
*
* @param $recordSimilarityParams
*
* @return mixed
*
* @throws RosetteException
*/
public function recordSimilarity($recordSimilarityParams)
{
return $this->callEndpoint($recordSimilarityParams, 'record-similarity');
}


/**
* Calls the relationships endpoint.
*
Expand Down
Loading

0 comments on commit 686c7db

Please sign in to comment.