From ba751b07756ddef0d4ff3d3ca996f033909050cd Mon Sep 17 00:00:00 2001 From: Adam Soos Date: Fri, 12 Apr 2024 16:41:33 +0200 Subject: [PATCH 01/20] WS-3151: add indoc-coref to entities example --- examples/entities.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/examples/entities.php b/examples/entities.php index 6806db9..9591dcc 100644 --- a/examples/entities.php +++ b/examples/entities.php @@ -19,6 +19,11 @@ $content = $entities_text_data; $params->set('content', $content); +// Within a document, there may be multiple references to a single entity. +// indoc-coref server chains together all mentions to an entity. +// Uncomment the next line to enable the entity extraction to use the indoc-coref server +// $api->setOption('useIndocServer', true); + try { $result = $api->entities($params); var_dump($result); From e951831b6cf0982086e01ec95031c0120e6b39dc Mon Sep 17 00:00:00 2001 From: Adam Soos Date: Fri, 12 Apr 2024 17:33:33 +0200 Subject: [PATCH 02/20] WS-3151: add record similarity tag --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index e1ef361..41e8776 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,8 @@ "rosette", "sentiment", "text analytics", - "text embeddings" + "text embeddings", + "record-similarity" ], "authors": [ { From 55591b60a74a8b9f1466d8ab92ac7f587a936f26 Mon Sep 17 00:00:00 2001 From: Adam Soos Date: Fri, 12 Apr 2024 17:34:32 +0200 Subject: [PATCH 03/20] WS-3151: record-similarity --- examples/record_similarity.php | 65 +++++++++++++++ source/rosette/api/Api.php | 15 ++++ .../api/RecordSimilarityParameters.php | 83 +++++++++++++++++++ 3 files changed, 163 insertions(+) create mode 100644 examples/record_similarity.php create mode 100644 source/rosette/api/RecordSimilarityParameters.php diff --git a/examples/record_similarity.php b/examples/record_similarity.php new file mode 100644 index 0000000..524d900 --- /dev/null +++ b/examples/record_similarity.php @@ -0,0 +1,65 @@ + --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" => "1994304/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); +} diff --git a/source/rosette/api/Api.php b/source/rosette/api/Api.php index 9bf95a3..2d7fc39 100644 --- a/source/rosette/api/Api.php +++ b/source/rosette/api/Api.php @@ -701,6 +701,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. * diff --git a/source/rosette/api/RecordSimilarityParameters.php b/source/rosette/api/RecordSimilarityParameters.php new file mode 100644 index 0000000..d40fa2f --- /dev/null +++ b/source/rosette/api/RecordSimilarityParameters.php @@ -0,0 +1,83 @@ +fields = $fields; + $this->properties = $properties; + $this->records = $records; + } + + + + /** + * Validates parameters. + * + * @throws RosetteException + */ + public function validate() + { + if (empty($this->fields)) { + throw new RosetteException( + sprintf('Required record similarity parameter not supplied: fields'), + RosetteException::$BAD_REQUEST_FORMAT + ); + } + if (empty($this->properties)) { + throw new RosetteException( + sprintf('Required record similarity parameter not supplied: properties'), + RosetteException::$BAD_REQUEST_FORMAT + ); + } + if (empty($this->records)) { + throw new RosetteException( + sprintf('Required record similarity parameter not supplied: records'), + RosetteException::$BAD_REQUEST_FORMAT + ); + } + } +} \ No newline at end of file From 142dde22e8d1f41cd4cc405eaeaf9caff386cb97 Mon Sep 17 00:00:00 2001 From: Adam Soos Date: Mon, 15 Apr 2024 11:03:23 +0200 Subject: [PATCH 04/20] WS-3151: add events support --- examples/events.php | 36 +++++++++++++++++++ source/rosette/api/Api.php | 14 ++++++++ .../api/RecordSimilarityParameters.php | 2 +- 3 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 examples/events.php diff --git a/examples/events.php b/examples/events.php new file mode 100644 index 0000000..437fb63 --- /dev/null +++ b/examples/events.php @@ -0,0 +1,36 @@ + --url=\n"; + exit(); +} +$events_text_data = "I am looking for a flight to Los Angeles."; +$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', 'ONLY_NEGATIVE'); +// try { +// $result = $api->events($params); +// var_dump($result); +// } catch (RosetteException $e) { +// error_log($e); +// } + diff --git a/source/rosette/api/Api.php b/source/rosette/api/Api.php index 2d7fc39..3bbbd93 100644 --- a/source/rosette/api/Api.php +++ b/source/rosette/api/Api.php @@ -630,6 +630,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. diff --git a/source/rosette/api/RecordSimilarityParameters.php b/source/rosette/api/RecordSimilarityParameters.php index d40fa2f..9e1b2eb 100644 --- a/source/rosette/api/RecordSimilarityParameters.php +++ b/source/rosette/api/RecordSimilarityParameters.php @@ -16,7 +16,7 @@ * See the License for the specific language governing permissions and limitations under the License. **/ - namespace rosette\api; +namespace rosette\api; /** * Class RecordSimilarityParameters. From 5cc5289d2cf4dd9eb24f46aeacd1addd5e5fc4e4 Mon Sep 17 00:00:00 2001 From: Adam Soos Date: Mon, 15 Apr 2024 11:17:51 +0200 Subject: [PATCH 05/20] WS-3151: add unit tests --- spec/rosette/api/ApiSpec.php | 21 ++++++++++++ .../api/RecordSimilarityParametersSpec.php | 34 +++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 spec/rosette/api/RecordSimilarityParametersSpec.php diff --git a/spec/rosette/api/ApiSpec.php b/spec/rosette/api/ApiSpec.php index 418cead..c47d71b 100644 --- a/spec/rosette/api/ApiSpec.php +++ b/spec/rosette/api/ApiSpec.php @@ -157,6 +157,17 @@ public function it_calls_the_entities_endpoint($params, $request) $this->setMockRequest($request); $this->entities($params)->shouldHaveKeyWithValue('name', ApiSpec::$ResponseNameField); } + public function it_calls_the_events_endpoint($params, $request) + { + $params->beADoubleOf(ApiSpec::$DocumentParametersFullClassName); + $params->content = ApiSpec::$SampleContent; + $request->beADoubleOf(ApiSpec::$RosetteRequestFullClassName); + $request->makeRequest(Argument::any(), Argument::any(), Argument::any(), Argument::any(), Argument::any())->willReturn(true); + $request->getResponseCode()->willReturn(200); + $request->getResponse()->willReturn([ 'name' => ApiSpec::$ResponseNameField]); + $this->setMockRequest($request); + $this->events($params)->shouldHaveKeyWithValue('name', ApiSpec::$ResponseNameField); + } public function it_calls_the_categories_endpoint($params, $request) { $params->beADoubleOf(ApiSpec::$DocumentParametersFullClassName); @@ -221,6 +232,16 @@ public function it_calls_the_name_deduplication_endpoint($params, $request) $this->setMockRequest($request); $this->nameDeduplication($params)->shouldHaveKeyWithValue('name', ApiSpec::$ResponseNameField); } + public function it_calls_the_record_similarity_endpoint($params, $request) + { + $params->beADoubleOf('\rosette\api\RecordSimilarityParameters'); + $request->beADoubleOf(ApiSpec::$RosetteRequestFullClassName); + $request->makeRequest(Argument::any(), Argument::any(), Argument::any(), Argument::any(), Argument::any())->willReturn(true); + $request->getResponseCode()->willReturn(200); + $request->getResponse()->willReturn([ 'name' => ApiSpec::$ResponseNameField]); + $this->setMockRequest($request); + $this->recordSimilarity($params)->shouldHaveKeyWithValue('name', ApiSpec::$ResponseNameField); + } public function it_calls_the_relationships_endpoint($params, $request) { $params->beADoubleOf(ApiSpec::$DocumentParametersFullClassName); diff --git a/spec/rosette/api/RecordSimilarityParametersSpec.php b/spec/rosette/api/RecordSimilarityParametersSpec.php new file mode 100644 index 0000000..6db84c0 --- /dev/null +++ b/spec/rosette/api/RecordSimilarityParametersSpec.php @@ -0,0 +1,34 @@ +beConstructedWith($fields, $properties, $records); + $this->shouldNotThrow(RosetteConstants::$RosetteExceptionFullClassName)->duringValidate(); + } + + public function it_has_fields_undefined($fields, $properties, $records) + { + $this->beConstructedWith(null, $properties, $records); + $this->shouldThrow(RosetteConstants::$RosetteExceptionFullClassName)->duringValidate(); + } + + public function it_has_properties_undefined($fields, $properties, $records) + { + $this->beConstructedWith($fields, null, $records); + $this->shouldThrow(RosetteConstants::$RosetteExceptionFullClassName)->duringValidate(); + } + + public function it_has_records_undefined($fields, $properties, $records) + { + $this->beConstructedWith($fields, $properties, null); + $this->shouldThrow(RosetteConstants::$RosetteExceptionFullClassName)->duringValidate(); + } +} From 00c11ee4ab14b348d0c734e8823930142d35194c Mon Sep 17 00:00:00 2001 From: Adam Soos Date: Mon, 15 Apr 2024 11:18:16 +0200 Subject: [PATCH 06/20] WS-3151: change to jenkins uid:gid --- CI.Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CI.Jenkinsfile b/CI.Jenkinsfile index 9906753..f0883fe 100644 --- a/CI.Jenkinsfile +++ b/CI.Jenkinsfile @@ -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 /source\"" } node ("docker-light") { From 8f4749fb8611e45b39d2cfa407a309ce8777c7f6 Mon Sep 17 00:00:00 2001 From: Adam Soos Date: Mon, 15 Apr 2024 11:28:04 +0200 Subject: [PATCH 07/20] WS-3151: fix descriptions --- examples/events.php | 2 +- examples/record_similarity.php | 2 +- source/rosette/api/RecordSimilarityParameters.php | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/events.php b/examples/events.php index 437fb63..aa71325 100644 --- a/examples/events.php +++ b/examples/events.php @@ -1,7 +1,7 @@ Date: Mon, 15 Apr 2024 11:36:43 +0200 Subject: [PATCH 08/20] WS-3151: fix example --- examples/record_similarity.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/record_similarity.php b/examples/record_similarity.php index cc9caa0..88bf488 100644 --- a/examples/record_similarity.php +++ b/examples/record_similarity.php @@ -48,7 +48,7 @@ "dob" => array("date" => "1993-04-16"), "primaryName" => "Ivan R", "addr" => array("address" => "123 Roadlane Ave"), - "dob2" => array("date" => "1994304/16") + "dob2" => array("date" => "1993/04/16") ) ) From 2985caf3428473720c09bd8737bc59e17ff62068 Mon Sep 17 00:00:00 2001 From: Adam Soos Date: Mon, 15 Apr 2024 11:46:43 +0200 Subject: [PATCH 09/20] WS-3151: skip running examples in jenkins --- CI.sh | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/CI.sh b/CI.sh index c4793bb..94c6084 100755 --- a/CI.sh +++ b/CI.sh @@ -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!" From fa8d28adcf8673f049dc7ce1dc410d4cc426b16c Mon Sep 17 00:00:00 2001 From: Adam Soos Date: Mon, 15 Apr 2024 11:48:49 +0200 Subject: [PATCH 10/20] WS-3151: fix mounted volume path --- CI.Jenkinsfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CI.Jenkinsfile b/CI.Jenkinsfile index f0883fe..27b1d78 100644 --- a/CI.Jenkinsfile +++ b/CI.Jenkinsfile @@ -37,7 +37,7 @@ def runVersion(sourceDir, ver) { ${sonarExec} && \ echo && \ echo [INFO] Re-permission files for cleanup. && \ - chown -R 9960:9960 /source\"" + chown -R 9960:9960 /php-source\"" } node ("docker-light") { From d76c9d2034593ea17a7330667a54322e730e96d6 Mon Sep 17 00:00:00 2001 From: Adam Soos Date: Mon, 15 Apr 2024 12:08:27 +0200 Subject: [PATCH 11/20] WS-3151: fix record similarity test --- spec/rosette/api/RecordSimilarityParametersSpec.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/rosette/api/RecordSimilarityParametersSpec.php b/spec/rosette/api/RecordSimilarityParametersSpec.php index 6db84c0..80209eb 100644 --- a/spec/rosette/api/RecordSimilarityParametersSpec.php +++ b/spec/rosette/api/RecordSimilarityParametersSpec.php @@ -6,7 +6,7 @@ use Prophecy\Argument; use rosette\api\RosetteConstants; -class RecordSimilarityParameterSpec extends ObjectBehavior +class RecordSimilarityParametersSpec extends ObjectBehavior { public function it_passes_validation($fields, $properties, $records) { From 7a33c79fe1d68923d6f2afbd4bfb93034ba84481 Mon Sep 17 00:00:00 2001 From: Adam Soos Date: Mon, 15 Apr 2024 12:52:55 +0200 Subject: [PATCH 12/20] WS-3151: update versions to 1.29.0 --- composer.json | 2 +- source/rosette/api/Api.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 41e8776..a06f653 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "rosette/api", - "version": "1.26.0", + "version": "1.29.0", "description": "PHP Interface for Rosette Text Analytics", "type": "library", "license": "Apache-2.0", diff --git a/source/rosette/api/Api.php b/source/rosette/api/Api.php index 3bbbd93..ccfe0a9 100644 --- a/source/rosette/api/Api.php +++ b/source/rosette/api/Api.php @@ -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). From 26832722234f3bf6ac9e742d0723504448d861e5 Mon Sep 17 00:00:00 2001 From: Seth Gransky Date: Mon, 15 Apr 2024 17:28:37 -0500 Subject: [PATCH 13/20] WS-3151: Clarify indoc comment in example. Metadata updates. --- README.md | 7 ++----- composer.json | 27 +++++++++++++++++++-------- examples/entities.php | 5 ++--- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index d7daab5..fab19e1 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,11 @@ - + --- [![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) diff --git a/composer.json b/composer.json index a06f653..06c5926 100644 --- a/composer.json +++ b/composer.json @@ -6,9 +6,17 @@ "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", @@ -16,23 +24,26 @@ "ner", "nlp", "parts of speech", + "record similarity", "relationships", "rosette", - "sentiment", + "semantic similarity", + "semantic vectors", + "sentiment analysis", "text analytics", "text embeddings", - "record-similarity" + "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": { diff --git a/examples/entities.php b/examples/entities.php index 9591dcc..f908aef 100644 --- a/examples/entities.php +++ b/examples/entities.php @@ -19,9 +19,8 @@ $content = $entities_text_data; $params->set('content', $content); -// Within a document, there may be multiple references to a single entity. -// indoc-coref server chains together all mentions to an entity. -// Uncomment the next line to enable the entity extraction to use the indoc-coref server +// 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 { From 828e7d5dde02e356fdda0151bf48ace1404b7217 Mon Sep 17 00:00:00 2001 From: seth-mg Date: Tue, 16 Apr 2024 17:27:11 -0500 Subject: [PATCH 14/20] Update README.md Update links and logo formatting. --- README.md | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index fab19e1..68c681e 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,8 @@ - - ---- + +# 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 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 @@ -13,7 +11,9 @@ Rosette uses natural language processing, statistical modeling, and machine lear ## Quick Start #### Installation -`composer require "rosette/api"` +``` +composer require "rosette/api" +``` #### Examples View small example programs for each Rosette endpoint @@ -21,11 +21,10 @@ in the [examples](https://github.com/rosette-api/php/tree/develop/examples) dire #### 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 From 70694bd1db6c0aa4e4c6c46653ed3ba3a8cadcf4 Mon Sep 17 00:00:00 2001 From: Seth Gransky Date: Tue, 16 Apr 2024 17:54:45 -0500 Subject: [PATCH 15/20] WS-3151: Tweak events example for negation. --- examples/events.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/examples/events.php b/examples/events.php index aa71325..c003ea3 100644 --- a/examples/events.php +++ b/examples/events.php @@ -13,7 +13,8 @@ echo 'Usage: php ' . __FILE__ . " --key --url=\n"; exit(); } -$events_text_data = "I am looking for a flight to Los Angeles."; + +$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; @@ -26,11 +27,11 @@ error_log($e); } -// $api->setOption('negation', 'ONLY_NEGATIVE'); -// 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); +} From 2dbd6122beb048f8cfb3dbf512ea1be79c12bbfe Mon Sep 17 00:00:00 2001 From: Seth Gransky Date: Wed, 17 Apr 2024 11:41:17 -0500 Subject: [PATCH 16/20] WS-3151: Accept IDE suggestions. --- .../rosette/api/RecordSimilarityParameters.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/source/rosette/api/RecordSimilarityParameters.php b/source/rosette/api/RecordSimilarityParameters.php index 1523357..5fe7cb8 100644 --- a/source/rosette/api/RecordSimilarityParameters.php +++ b/source/rosette/api/RecordSimilarityParameters.php @@ -26,17 +26,17 @@ class RecordSimilarityParameters extends RosetteParamsSetBase /** * @var array */ - public $fields; + public array $fields; /** * @var array */ - public $properties; + public array $properties; /** * @var array */ - public $records; + public array $records; /** * constructor @@ -45,7 +45,7 @@ class RecordSimilarityParameters extends RosetteParamsSetBase * @param array $properties - the properties of the comparison * @param array $records - the records to compare */ - public function __construct($fields, $properties, $records) + public function __construct(array $fields, array $properties, array $records) { $this->fields = $fields; $this->properties = $properties; @@ -59,23 +59,23 @@ public function __construct($fields, $properties, $records) * * @throws RosetteException */ - public function validate() + public function validate(): void { if (empty($this->fields)) { throw new RosetteException( - sprintf('Required record similarity parameter not supplied: fields'), + 'Required record similarity parameter not supplied: fields', RosetteException::$BAD_REQUEST_FORMAT ); } if (empty($this->properties)) { throw new RosetteException( - sprintf('Required record similarity parameter not supplied: properties'), + 'Required record similarity parameter not supplied: properties', RosetteException::$BAD_REQUEST_FORMAT ); } if (empty($this->records)) { throw new RosetteException( - sprintf('Required record similarity parameter not supplied: records'), + 'Required record similarity parameter not supplied: records', RosetteException::$BAD_REQUEST_FORMAT ); } From 3494bf64717d772000673c7eb1b10be7b2bfab77 Mon Sep 17 00:00:00 2001 From: Seth Gransky Date: Wed, 17 Apr 2024 11:49:08 -0500 Subject: [PATCH 17/20] WS-3151: Drop 7.3 and add 8.3. --- CI.Jenkinsfile | 2 +- examples/README.md | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CI.Jenkinsfile b/CI.Jenkinsfile index 27b1d78..e99d7aa 100644 --- a/CI.Jenkinsfile +++ b/CI.Jenkinsfile @@ -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}" diff --git a/examples/README.md b/examples/README.md index e8339de..f13115b 100644 --- a/examples/README.md +++ b/examples/README.md @@ -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. @@ -15,7 +15,7 @@ A note on prerequisites. Rosette API only supports TLS 1.2 so ensure your toolc ``` git clone git@github.com: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 @@ -37,7 +37,7 @@ php ping.php --key $API_KEY ``` git clone git@github.com: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:78.2-cli apt-get update apt-get install -y git zip From f32e7fd62e1674b2821684c348ab6536d2a48497 Mon Sep 17 00:00:00 2001 From: Seth Gransky Date: Wed, 17 Apr 2024 12:33:58 -0500 Subject: [PATCH 18/20] WS-3151: Fix unit test and typo. --- examples/README.md | 2 +- spec/rosette/api/RecordSimilarityParametersSpec.php | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/README.md b/examples/README.md index f13115b..2461406 100644 --- a/examples/README.md +++ b/examples/README.md @@ -37,7 +37,7 @@ php ping.php --key $API_KEY ``` git clone git@github.com:rosette-api/php.git cd php -docker run -it -v $(pwd):/source --entrypoint bash php:78.2-cli +docker run -it -v $(pwd):/source --entrypoint bash php:8.2-cli apt-get update apt-get install -y git zip diff --git a/spec/rosette/api/RecordSimilarityParametersSpec.php b/spec/rosette/api/RecordSimilarityParametersSpec.php index 80209eb..0933e7b 100644 --- a/spec/rosette/api/RecordSimilarityParametersSpec.php +++ b/spec/rosette/api/RecordSimilarityParametersSpec.php @@ -10,25 +10,25 @@ class RecordSimilarityParametersSpec extends ObjectBehavior { public function it_passes_validation($fields, $properties, $records) { - $this->beConstructedWith($fields, $properties, $records); + $this->beConstructedWith((array)$fields, (array)$properties, (array)$records); $this->shouldNotThrow(RosetteConstants::$RosetteExceptionFullClassName)->duringValidate(); } public function it_has_fields_undefined($fields, $properties, $records) { - $this->beConstructedWith(null, $properties, $records); + $this->beConstructedWith((array)null, (array)$properties, (array)$records); $this->shouldThrow(RosetteConstants::$RosetteExceptionFullClassName)->duringValidate(); } public function it_has_properties_undefined($fields, $properties, $records) { - $this->beConstructedWith($fields, null, $records); + $this->beConstructedWith((array)$fields, (array)null, (array)$records); $this->shouldThrow(RosetteConstants::$RosetteExceptionFullClassName)->duringValidate(); } public function it_has_records_undefined($fields, $properties, $records) { - $this->beConstructedWith($fields, $properties, null); + $this->beConstructedWith((array)$fields, (array)$properties, (array)null); $this->shouldThrow(RosetteConstants::$RosetteExceptionFullClassName)->duringValidate(); } } From 9a58ca11f6874fff0f4b8d6ecb681412b2fcbbee Mon Sep 17 00:00:00 2001 From: Seth Gransky Date: Wed, 17 Apr 2024 12:44:07 -0500 Subject: [PATCH 19/20] WS-3151: Code smells. --- source/rosette/api/Api.php | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/source/rosette/api/Api.php b/source/rosette/api/Api.php index ccfe0a9..41967f1 100644 --- a/source/rosette/api/Api.php +++ b/source/rosette/api/Api.php @@ -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"; @@ -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); } /** @@ -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); } /** @@ -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 $resultObject = $this->getHttp($url, $this->headers); } /** From 312e3d315ceb53cbc8796c2b15abece69364bb3c Mon Sep 17 00:00:00 2001 From: Seth Gransky Date: Wed, 17 Apr 2024 12:47:32 -0500 Subject: [PATCH 20/20] WS-3151: Whoops. --- source/rosette/api/Api.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/rosette/api/Api.php b/source/rosette/api/Api.php index 41967f1..528e534 100644 --- a/source/rosette/api/Api.php +++ b/source/rosette/api/Api.php @@ -531,7 +531,7 @@ private function postHttp($url, $headers, $data) public function ping() { $url = $this->service_url . 'ping'; - return $resultObject = $this->getHttp($url, $this->headers); + return $this->getHttp($url, $this->headers); } /**