Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to support bulk input #1

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
499 changes: 261 additions & 238 deletions README.md

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "havenondemand/havenondemand",
"description": "This library allows you to quickly and easily make requests to Haven OnDemand's APIs.",
"version": "1.0.1",
"homepage": "https://github.com/HPE-Haven-OnDemand/havenondemand-php",
"license": "MIT",
"keywords": ["HavenOnDemand", "havenondemand", "machine learning", "haven", "ondemand"],
"require": {
"php": ">=5.3"
},
"type": "library",
"autoload": {
"psr-0": {"havenondemand": "lib/"}
}
}
30 changes: 15 additions & 15 deletions examples/entityextractionwithcallbackfunction.php
Original file line number Diff line number Diff line change
@@ -1,32 +1,29 @@
<?php
include "libs/hodclient.php";
include "libs/hodresponseparser.php";

$hodClient = new HODClient("34a54d30-ddaa-4294-8e45-ebe07eefe55e");
$hodClient = new HODClient("API_KEY");

// implement callback function
function requestCompletedWithContent($response) {
global $hodClient;

if ($response == null)
{
$errors = $hodClient->getLastError();
$err = $errors[0];
echo ("Error code: " . $err->error."</br>Error reason: " . $err->reason . "</br>Error detail: " . $err->detail);
} else {
$resp = new HODResponseParser($response);
if ($resp->error != null){
echo ("Error code: ".$resp->error->error."</br>Error reason: ".$resp->error->reason."</br>Error detail: ".$resp->error->detail);
} elseif ($resp->status == "finished") {
$people = "";
$places = "";
$companies = "";
$entities = $response->entities;
$entities = $resp->payloadObj->entities;
for ($i = 0; $i < count($entities); $i++) {
$entity = $entities[$i];
if ($entity->type == "people_eng") {
$people .= $entity->normalized_text . "; ";
$people .= $entity->normalized_text . "</br>";
// parse any other interested information about this person ...
} else if ($entity->type == "places_eng") {
$places .= $entity->normalized_text . "; ";
$places .= $entity->normalized_text . "</br>";
// parse any other interested information about this place ...
} else if ($entity->type == "companies_eng") {
$companies .= $entity->normalized_text . "; ";
$companies .= $entity->normalized_text . "</br>";
// parse any other interested information about this place ...
}
}
Expand All @@ -43,6 +40,9 @@ function requestCompletedWithContent($response) {
"entity_type" => ["people_eng", "places_eng", "companies_eng"],
"unique_entities" => "true"
);
$hodClient->GetRequest($paramArr, HODApps::ENTITY_EXTRACTION, REQ_MODE::SYNC, 'requestCompletedWithContent');

try {
$hodClient->GetRequest($paramArr, HODApps::ENTITY_EXTRACTION, false, 'requestCompletedWithContent');
}catch (Exception $ex){
echo $ex.getMessage();
}
?>
64 changes: 33 additions & 31 deletions examples/entityextractionwithdirectresponse.php
Original file line number Diff line number Diff line change
@@ -1,42 +1,44 @@
<?php
include "libs/hodclient.php";
include "libs/hodresponseparser.php";

$hodClient = new HODClient("34a54d30-ddaa-4294-8e45-ebe07eefe55e");
$hodClient = new HODClient("API_KEY");

$paramArr = array(
'url' => ["http://www.bbc.com","http://www.cnn.com"],
"entity_type" => ["people_eng", "places_eng", "companies_eng"],
"unique_entities" => "true"
);
$response = $hodClient->GetRequest($paramArr, HODApps::ENTITY_EXTRACTION, REQ_MODE::SYNC);

if ($response == null)
{
$errors = $hodClient->getLastError();
$err = $errors[0];
echo ("Error code: " . $err->error."</br>Error reason: " . $err->reason . "</br>Error detail: " . $err->detail);
} else {
$people = "";
$places = "";
$companies = "";
$entities = $response->entities;
for ($i = 0; $i < count($entities); $i++) {
$entity = $entities[$i];
if ($entity->type == "people_eng") {
$people .= $entity->normalized_text . "; ";
// parse any other interested information about this person ...
} else if ($entity->type == "places_eng") {
$places .= $entity->normalized_text . "; ";
// parse any other interested information about this place ...
} else if ($entity->type == "companies_eng") {
$companies .= $entity->normalized_text . "; ";
// parse any other interested information about this place ...
}
}
echo "PEOPLE: " . $people;
echo "</br>";
echo "PLACES: " . $places;
echo "</br>";
echo "COMPANIES: " . $companies;
try {
$response = $hodClient->GetRequest($paramArr, HODApps::ENTITY_EXTRACTION, false);
$resp = new HODResponseParser($response);
if ($resp->error != null){
echo ("Error code: ".$resp->error->error."</br>Error reason: ".$resp->error->reason."</br>Error detail: ".$resp->error->detail);
} elseif ($resp->status == "finished") {
$people = "";
$places = "";
$companies = "";
$entities = $resp->payloadObj->entities;
for ($i = 0; $i < count($entities); $i++) {
$entity = $entities[$i];
if ($entity->type == "people_eng") {
$people .= $entity->normalized_text . "</br>";
// parse any other interested information about this person ...
} else if ($entity->type == "places_eng") {
$places .= $entity->normalized_text . "</br>";
// parse any other interested information about this place ...
} else if ($entity->type == "companies_eng") {
$companies .= $entity->normalized_text . "</br>";
// parse any other interested information about this place ...
}
}
echo "PEOPLE: " . $people;
echo "</br>";
echo "PLACES: " . $places;
echo "</br>";
echo "COMPANIES: " . $companies;
}
}catch (Exception $ex){
echo $ex.getMessage();
}
?>
64 changes: 41 additions & 23 deletions examples/ocrdocumentwithcallbackfunction.php
Original file line number Diff line number Diff line change
@@ -1,43 +1,57 @@
<?php
include "libs/hodclient.php";
include "libs/hodresponseparser.php";


$hodClient = new HODClient("34a54d30-ddaa-4294-8e45-ebe07eefe55e");
$hodClient = new HODClient("API_KEY");

// implement callback function
function requestCompletedWithJobId($jobID) {
function requestCompletedWithJobId($response) {
global $hodClient;
if ($jobID == null)
{
$errors = $hodClient->getLastError();
$err = $errors[0];
echo ($err->error." / " . $err->reason . " / " . $err->detail);
} else {
$hodClient->GetJobStatus($jobID, 'requestCompletedWithContent');
$resp = new HODJobIDParser($response);
if ($resp->error != null) {
echo (json_encode($resp->error));
}else {
try {
$hodClient->GetJobStatus($resp->jobID, 'requestCompletedWithContent');
}catch (Exception $ex){
echo $ex.getMessage();
}
}
}

// implement callback function
function requestCompletedWithContent($response)
{
global $hodClient;
if ($response == null)
{
$errors = $hodClient->getLastError();
$err = $errors[0];
if ($err->error == ErrorCode::QUEUED) {
$resp = new HODResponseParser($response);
if ($resp->error != null){
$err = $resp->error;
if ($err->error == HODErrorCode::QUEUED) {
error_log("queued:".$err->jobID);
sleep(2);
$hodClient->GetJobStatus($err->jobID, 'requestCompletedWithContent');
} else if ($err->error == ErrorCode::IN_PROGRESS) {
try {
$hodClient->GetJobStatus($err->jobID, 'requestCompletedWithContent');
}catch (Exception $ex){
echo $ex.getMessage();
}
} else if ($err->error == HODErrorCode::IN_PROGRESS) {
error_log("in progress:".$err->jobID);
sleep(5);
$hodClient->GetJobStatus($err->jobID, 'requestCompletedWithContent');
try {
$hodClient->GetJobStatus($err->jobID, 'requestCompletedWithContent');
}catch (Exception $ex){
echo $ex.getMessage();
}
} else {
echo ("Error code: " . $err->error."</br>Error reason: " . $err->reason . "</br>Error detail: " . $err->detail . "JobID: " . $err->jobID);
$error = "<b>Error:</b></br>";
$error .= $resp->error->error . "</br>";
$error .= $resp->error->reason . "</br>";
$error .= $resp->error->detail . "</br>";
echo $error;
}
}
else {
} elseif ($resp->status == "finished") {
$result = "";
$textBlocks = $response->text_block;
$textBlocks = $resp->payloadObj->text_block;
for ($i = 0; $i < count($textBlocks); $i++) {
$block = $textBlocks[$i];
$result .= "<html><body><p>";
Expand All @@ -52,5 +66,9 @@ function requestCompletedWithContent($response)
'file' => "0005r005.gif",
'mode' => "document_photo"
);
$hodClient->PostRequest($paramArr, HODApps::OCR_DOCUMENT, REQ_MODE::ASYNC, 'requestCompletedWithJobId');
try {
$hodClient->PostRequest($paramArr, HODApps::OCR_DOCUMENT, true, 'requestCompletedWithJobId');
}catch (Exception $ex){
echo $ex.getMessage();
}
?>
57 changes: 30 additions & 27 deletions examples/ocrdocumentwithdirectresponse.php
Original file line number Diff line number Diff line change
@@ -1,38 +1,41 @@
<?php
include "libs/hodclient.php";
include "libs/hodresponseparser.php";


$hodClient = new HODClient("34a54d30-ddaa-4294-8e45-ebe07eefe55e");
$hodClient = new HODClient("API_KEY");

$paramArr = array(
'file' => "0005r005.gif",
'mode' => "document_photo"
);

$jobID = $hodClient->PostRequest($paramArr, HODApps::OCR_DOCUMENT, REQ_MODE::ASYNC);

if ($jobID == null)
{
$errors = $hodClient->getLastError();
$err = $errors[0];
echo ($err->error." / " . $err->reason . " / " . $err->detail);
} else {
$response = $hodClient->GetJobResult($jobID);
if ($response == null)
{
$errors = $hodClient->getLastError();
$err = $errors[0];
echo ("Error code: " . $err->error."</br>Error reason: " . $err->reason . "</br>Error detail: " . $err->detail . "JobID: " . $err->jobID);
} else {
$result = "";
$textBlocks = $response->text_block;
for ($i = 0; $i < count($textBlocks); $i++) {
$block = $textBlocks[$i];
$result .= "<html><body><p>";
$result .= preg_replace("/\n+/", "</br>", $block->text);
$result .= "</p></body></html>";
}
echo "RECOGNIZED TEXT: " . $result;
}
try {
$response = $hodClient->PostRequest($paramArr, HODApps::OCR_DOCUMENT, true);
$resp = new HODJobIDParser($response);
if ($resp->error != null) {
echo (json_encode($resp->error));
} else {
$response = $hodClient->GetJobResult($resp->jobID);
$resp = new HODResponseParser($response);
if ($resp->error != null) {
$error = "<b>Error:</b></br>";
$error .= $resp->error->error . "</br>";
$error .= $resp->error->reason . "</br>";
$error .= $resp->error->detail . "</br>";
echo $error;
} elseif ($resp->status == "finished") {
$result = "";
$textBlocks = $resp->payloadObj->text_block;
for ($i = 0; $i < count($textBlocks); $i++) {
$block = $textBlocks[$i];
$result .= "<html><body><p>";
$result .= preg_replace("/\n+/", "</br>", $block->text);
$result .= "</p></body></html>";
}
echo "RECOGNIZED TEXT: " . $result;
}
}
}catch (Exception $ex){
echo $ex.getMessage();
}
?>
Loading