diff --git a/docs/code_samples/v2_extraction_polling.txt b/docs/code_samples/v2_extraction_polling.txt index bdb7fecf..c4696e52 100644 --- a/docs/code_samples/v2_extraction_polling.txt +++ b/docs/code_samples/v2_extraction_polling.txt @@ -1,9 +1,9 @@ enqueueAndGetResult( - InferenceResponse::class, + ExtractionResponse::class, $inputSource, $inferenceParams ); diff --git a/docs/code_samples/v2_extraction_webhook.txt b/docs/code_samples/v2_extraction_webhook.txt index 51213116..63fe599e 100644 --- a/docs/code_samples/v2_extraction_webhook.txt +++ b/docs/code_samples/v2_extraction_webhook.txt @@ -1,7 +1,7 @@ nPages = $rawResponse['n_pages']; $this->filename = $rawResponse['name']; try { - $reflection = new \ReflectionClass($predictionType); + $reflection = new ReflectionClass($predictionType); $this->inference = $reflection->newInstance($rawResponse['inference']); - } catch (\ReflectionException $e) { + } catch (ReflectionException $e) { throw new MindeeApiException( "Unable to create custom product " . $predictionType, ErrorCode::INTERNAL_LIBRARY_ERROR, diff --git a/src/V1/Parsing/Common/Inference.php b/src/V1/Parsing/Common/Inference.php index ba8fcb5e..7b618946 100644 --- a/src/V1/Parsing/Common/Inference.php +++ b/src/V1/Parsing/Common/Inference.php @@ -10,7 +10,7 @@ abstract class Inference { /** - * @var \Mindee\V1\Parsing\Common\Product Name and version of a given product, as sent back by the API. + * @var Product Name and version of a given product, as sent back by the API. */ public Product $product; /** @@ -22,7 +22,7 @@ abstract class Inference */ public static string $endpointVersion; /** - * @var \Mindee\V1\Parsing\Common\Prediction A document's top-level Prediction. + * @var Prediction A document's top-level Prediction. */ public Prediction $prediction; /** @@ -38,7 +38,7 @@ abstract class Inference */ public ?int $pageId; /** - * @var \Mindee\V1\Parsing\Common\Extras\Extras|null Potential Extras fields sent back along with the prediction. + * @var Extras|null Potential Extras fields sent back along with the prediction. */ public ?Extras $extras; diff --git a/src/V1/Parsing/Common/OCR/OCR.php b/src/V1/Parsing/Common/OCR/OCR.php index 1b2648ba..9b610afb 100644 --- a/src/V1/Parsing/Common/OCR/OCR.php +++ b/src/V1/Parsing/Common/OCR/OCR.php @@ -8,7 +8,7 @@ class OCR { /** - * @var \Mindee\V1\Parsing\Common\OCR\MVisionV1 Mindee Vision v1 results. + * @var MVisionV1 Mindee Vision v1 results. */ public MVisionV1 $mvisionV1; diff --git a/src/V1/Parsing/Standard/PositionField.php b/src/V1/Parsing/Standard/PositionField.php index a85a5913..aa8f6d9d 100644 --- a/src/V1/Parsing/Standard/PositionField.php +++ b/src/V1/Parsing/Standard/PositionField.php @@ -11,23 +11,23 @@ class PositionField extends BaseField { /** - * @var \Mindee\Geometry\Polygon|null Polygon of cropped area, identical to the `polygon` property. + * @var Polygon|null Polygon of cropped area, identical to the `polygon` property. */ public $value; /** - * @var \Mindee\Geometry\Polygon|null Polygon of cropped area. + * @var Polygon|null Polygon of cropped area. */ public ?Polygon $polygon; /** - * @var \Mindee\Geometry\Polygon|null Quadrangle of cropped area (does not exceed the canvas). + * @var Polygon|null Quadrangle of cropped area (does not exceed the canvas). */ public ?Polygon $quadrangle; /** - * @var \Mindee\Geometry\Polygon|null Oriented rectangle of cropped area (may exceed the canvas). + * @var Polygon|null Oriented rectangle of cropped area (may exceed the canvas). */ public ?Polygon $rectangle; /** - * @var \Mindee\Geometry\Polygon|null Straight rectangle of cropped area (does not exceed the canvas). + * @var Polygon|null Straight rectangle of cropped area (does not exceed the canvas). */ public ?Polygon $boundingBox; @@ -36,7 +36,7 @@ class PositionField extends BaseField * * @param array $rawPrediction Raw prediction array. * @param string $key Key to use for the value. - * @return \Mindee\Geometry\Polygon|null + * @return Polygon|null */ private static function getQuadrilateral(array $rawPrediction, string $key): ?Polygon { @@ -52,7 +52,7 @@ private static function getQuadrilateral(array $rawPrediction, string $key): ?Po * * @param array $rawPrediction Raw prediction array. * @param string $key Key to use for the value. - * @return \Mindee\Geometry\Polygon|null + * @return Polygon|null */ private static function getPolygon(array $rawPrediction, string $key): ?Polygon { diff --git a/src/V2/Client.php b/src/V2/Client.php index 857e3470..a6b828e0 100644 --- a/src/V2/Client.php +++ b/src/V2/Client.php @@ -2,15 +2,15 @@ namespace Mindee\V2; +use Mindee\ClientOptions\PollingOptions; use Mindee\CustomSleepMixin; use Mindee\Error\MindeeException; use Mindee\Input\InputSource; use Mindee\V2\ClientOptions\BaseParameters; use Mindee\V2\HTTP\MindeeAPIV2; use Mindee\V2\Parsing\Inference\BaseResponse; -use Mindee\V2\Parsing\Inference\InferenceResponse; use Mindee\V2\Parsing\JobResponse; -use Mindee\V2\Product\Extraction\Params\InferenceParameters; +use Mindee\V2\Product\Extraction\Params\ExtractionParameters; /** * Mindee Client V2. @@ -37,15 +37,15 @@ public function __construct(?string $apiKey = null) /** * Send the document to an asynchronous endpoint and return its ID in the queue. * - * @param InputSource $inputSource File to parse. - * @param InferenceParameters $params Parameters relating to prediction options. + * @param InputSource $inputSource File to parse. + * @param ExtractionParameters $params Parameters relating to prediction options. * @return JobResponse A JobResponse containing the job (queue) corresponding to a document. * @throws MindeeException Throws if the input document is not provided. * @category Asynchronous */ public function enqueueInference( InputSource $inputSource, - InferenceParameters $params + ExtractionParameters $params ): JobResponse { return $this->enqueue($inputSource, $params); } @@ -65,17 +65,6 @@ public function enqueue( return $this->mindeeApi->reqPostEnqueue($inputSource, $params); } - /** - * Retrieves an inference. - * - * @param string $inferenceId ID of the queue to poll. - * @return InferenceResponse An InferenceResponse containing a Job. - * @category Asynchronous - */ - public function getInference(string $inferenceId): InferenceResponse - { - return $this->mindeeApi->reqGetInference($inferenceId); - } /** * @template T of BaseResponse @@ -118,40 +107,28 @@ public function getJob(string $jobId): JobResponse return $this->mindeeApi->reqGetJob($jobId); } - /** - * Send a document to an endpoint and poll the server until the result is sent or - * until the maximum number of tries is reached. - * - * @param InputSource $inputDoc Input document to parse. - * @param InferenceParameters $params Parameters relating to prediction options. - * @return InferenceResponse A response containing parsing results. - * @throws MindeeException Throws if enqueueing fails, job fails, or times out. - */ - public function enqueueAndGetInference( - InputSource $inputDoc, - InferenceParameters $params - ): InferenceResponse { - return $this->enqueueAndGetResult(InferenceResponse::class, $inputDoc, $params); - } - /** * Send a document to an endpoint and poll the server until the result is sent or * until the maximum number of tries is reached. * * @template T of BaseResponse - * @param string $responseClass The response class to construct. + * @param string $responseClass The response class to construct. * @phpstan-param class-string $responseClass - * @param InputSource $inputDoc Input document to parse. - * @param BaseParameters $params Parameters relating to prediction options. + * @param InputSource $inputDoc Input document to parse. + * @param BaseParameters $params Parameters relating to prediction options. + * @param PollingOptions|null $pollingOptions Options to apply to the polling. * @return BaseResponse A response containing parsing results. * @throws MindeeException Throws if enqueueing fails, job fails, or times out. */ public function enqueueAndGetResult( string $responseClass, InputSource $inputDoc, - BaseParameters $params + BaseParameters $params, + ?PollingOptions $pollingOptions = null ): BaseResponse { - $pollingOptions = $params->pollingOptions; + if (!$pollingOptions) { + $pollingOptions = new PollingOptions(); + } $enqueueResponse = $this->enqueue($inputDoc, $params); diff --git a/src/V2/ClientOptions/BaseParameters.php b/src/V2/ClientOptions/BaseParameters.php index 03cbd36b..f175d564 100644 --- a/src/V2/ClientOptions/BaseParameters.php +++ b/src/V2/ClientOptions/BaseParameters.php @@ -2,8 +2,6 @@ namespace Mindee\V2\ClientOptions; -use Mindee\ClientOptions\PollingOptions; - /** * Base parameters for running an inference. */ @@ -25,17 +23,11 @@ abstract class BaseParameters public array $webhooksIds; /** - * @var PollingOptions Polling options. + * @param string $modelId ID of the model. + * @param string|null $alias Optional file alias. + * @param array|null $webhooksIds List of webhook IDs. */ - public PollingOptions $pollingOptions; - - /** - * @param string $modelId ID of the model. - * @param string|null $alias Optional file alias. - * @param array|null $webhooksIds List of webhook IDs. - * @param PollingOptions|null $pollingOptions Polling options. - */ - public function __construct(string $modelId, ?string $alias, ?array $webhooksIds, ?PollingOptions $pollingOptions) + public function __construct(string $modelId, ?string $alias, ?array $webhooksIds) { $this->modelId = $modelId; @@ -47,10 +39,6 @@ public function __construct(string $modelId, ?string $alias, ?array $webhooksIds } else { $this->webhooksIds = []; } - if (!$pollingOptions) { - $pollingOptions = new PollingOptions(); - } - $this->pollingOptions = $pollingOptions; } /** diff --git a/src/V2/HTTP/MindeeAPIV2.php b/src/V2/HTTP/MindeeAPIV2.php index 90aa7cd5..0a68fb24 100644 --- a/src/V2/HTTP/MindeeAPIV2.php +++ b/src/V2/HTTP/MindeeAPIV2.php @@ -19,12 +19,13 @@ use Mindee\V2\ClientOptions\BaseParameters; use Mindee\V2\Parsing\ErrorResponse; use Mindee\V2\Parsing\Inference\BaseResponse; -use Mindee\V2\Parsing\Inference\InferenceResponse; use Mindee\V2\Parsing\JobResponse; +use Mindee\V2\Product\Extraction\ExtractionResponse; use ReflectionClass; use ReflectionException; use ReflectionProperty; +use const Mindee\V1\HTTP\API_KEY_ENV_NAME; use const Mindee\VERSION; // phpcs:disable @@ -230,22 +231,6 @@ private function processJobResponse(array $result): JobResponse } } - /** - * Requests the job of a queued document from the API. - * Throws an error if the server's response contains one. - * @param string $inferenceId ID of the inference. - * @return InferenceResponse - * @throws MindeeException Throws if the server's response contains an error. - * @throws MindeeException Throws if the inference ID is not provided. - */ - public function reqGetInference(string $inferenceId): InferenceResponse - { - if (!isset($inferenceId)) { - throw new MindeeException("Inference ID must be provided.", ErrorCode::USER_INPUT_ERROR); - } - return $this->reqGetResult(InferenceResponse::class, $inferenceId); - } - /** * Requests the job of a queued document from the API. * Throws an error if the server's response contains one. @@ -360,7 +345,7 @@ private function sendGetRequest(string $url): array * Starts a CURL session using POST. * * @param InputSource $inputSource File to upload. - * @param BaseParameters $params Inference parameters. + * @param BaseParameters $params Parameters. * @return array * @throws MindeeException Throws if the cURL operation doesn't go succeed. */ diff --git a/src/V2/Product/Classification/ClassificationClassifier.php b/src/V2/Product/Classification/ClassificationClassifier.php index c5570cd8..4adecf7d 100644 --- a/src/V2/Product/Classification/ClassificationClassifier.php +++ b/src/V2/Product/Classification/ClassificationClassifier.php @@ -2,7 +2,7 @@ namespace Mindee\V2\Product\Classification; -use Mindee\V2\Parsing\Inference\InferenceResponse; +use Mindee\V2\Product\Extraction\ExtractionResponse; /** * Classification of document type from the source file. @@ -15,9 +15,9 @@ class ClassificationClassifier public string $documentType; /** - * @var InferenceResponse|null $extractionResponse The extraction response associated with the classification. + * @var ExtractionResponse|null $extractionResponse The extraction response associated with the classification. */ - public ?InferenceResponse $extractionResponse; + public ?ExtractionResponse $extractionResponse; /** * @param array $rawPrediction Raw prediction array. @@ -26,7 +26,7 @@ public function __construct(array $rawPrediction) { $this->documentType = $rawPrediction['document_type']; $this->extractionResponse = isset($rawPrediction['extraction_response']) ? - new InferenceResponse($rawPrediction['extraction_response']) : null; + new ExtractionResponse($rawPrediction['extraction_response']) : null; } /** diff --git a/src/V2/Product/Classification/Params/ClassificationParameters.php b/src/V2/Product/Classification/Params/ClassificationParameters.php index 56f0702d..3d22d2cb 100644 --- a/src/V2/Product/Classification/Params/ClassificationParameters.php +++ b/src/V2/Product/Classification/Params/ClassificationParameters.php @@ -16,17 +16,15 @@ class ClassificationParameters extends BaseParameters public static string $slug = "classification"; /** - * @param string $modelId ID of the model. - * @param string|null $alias Optional file alias. - * @param array|null $webhooksIds List of webhook IDs. - * @param PollingOptions|null $pollingOptions Polling options. + * @param string $modelId ID of the model. + * @param string|null $alias Optional file alias. + * @param array|null $webhooksIds List of webhook IDs. */ public function __construct( string $modelId, ?string $alias = null, - ?array $webhooksIds = null, - ?PollingOptions $pollingOptions = null + ?array $webhooksIds = null ) { - parent::__construct($modelId, $alias, $webhooksIds, $pollingOptions); + parent::__construct($modelId, $alias, $webhooksIds); } } diff --git a/src/V2/Product/Crop/CropItem.php b/src/V2/Product/Crop/CropItem.php index 826d0d4f..4cb78886 100644 --- a/src/V2/Product/Crop/CropItem.php +++ b/src/V2/Product/Crop/CropItem.php @@ -3,7 +3,7 @@ namespace Mindee\V2\Product\Crop; use Mindee\V2\Parsing\Inference\Field\FieldLocation; -use Mindee\V2\Parsing\Inference\InferenceResponse; +use Mindee\V2\Product\Extraction\ExtractionResponse; /** * Result of a cropped document region. @@ -21,9 +21,9 @@ class CropItem public string $objectType; /** - * @var InferenceResponse|null $extractionResponse The extraction response associated with the crop. + * @var ExtractionResponse|null $extractionResponse The extraction response associated with the crop. */ - public ?InferenceResponse $extractionResponse; + public ?ExtractionResponse $extractionResponse; /** * @param array $rawResponse Raw server response array. */ @@ -32,7 +32,7 @@ public function __construct(array $rawResponse) $this->location = new FieldLocation($rawResponse['location']); $this->objectType = $rawResponse['object_type']; $this->extractionResponse = isset($rawResponse['extraction_response']) ? - new InferenceResponse($rawResponse['extraction_response']) : null; + new ExtractionResponse($rawResponse['extraction_response']) : null; } /** diff --git a/src/V2/Product/Crop/Params/CropParameters.php b/src/V2/Product/Crop/Params/CropParameters.php index 7b7f6758..077836e1 100644 --- a/src/V2/Product/Crop/Params/CropParameters.php +++ b/src/V2/Product/Crop/Params/CropParameters.php @@ -16,17 +16,15 @@ class CropParameters extends BaseParameters public static string $slug = "crop"; /** - * @param string $modelId ID of the model. - * @param string|null $alias Optional file alias. - * @param array|null $webhooksIds List of webhook IDs. - * @param PollingOptions|null $pollingOptions Polling options. + * @param string $modelId ID of the model. + * @param string|null $alias Optional file alias. + * @param array|null $webhooksIds List of webhook IDs. */ public function __construct( string $modelId, ?string $alias = null, - ?array $webhooksIds = null, - ?PollingOptions $pollingOptions = null + ?array $webhooksIds = null ) { - parent::__construct($modelId, $alias, $webhooksIds, $pollingOptions); + parent::__construct($modelId, $alias, $webhooksIds); } } diff --git a/src/V2/Parsing/Inference/Inference.php b/src/V2/Product/Extraction/ExtractionInference.php similarity index 71% rename from src/V2/Parsing/Inference/Inference.php rename to src/V2/Product/Extraction/ExtractionInference.php index 2bcbf0e8..b46f7587 100644 --- a/src/V2/Parsing/Inference/Inference.php +++ b/src/V2/Product/Extraction/ExtractionInference.php @@ -1,14 +1,15 @@ activeOptions = new InferenceActiveOptions($rawResponse['active_options']); - $this->result = new InferenceResult($rawResponse['result']); + $this->result = new ExtractionResult($rawResponse['result']); } /** diff --git a/src/V2/Parsing/Inference/InferenceResponse.php b/src/V2/Product/Extraction/ExtractionResponse.php similarity index 54% rename from src/V2/Parsing/Inference/InferenceResponse.php rename to src/V2/Product/Extraction/ExtractionResponse.php index f7651a5a..c6cfd4a2 100644 --- a/src/V2/Parsing/Inference/InferenceResponse.php +++ b/src/V2/Product/Extraction/ExtractionResponse.php @@ -1,16 +1,18 @@ inference = new Inference($rawResponse['inference']); + $this->inference = new ExtractionInference($rawResponse['inference']); } } diff --git a/src/V2/Parsing/Inference/InferenceResult.php b/src/V2/Product/Extraction/ExtractionResult.php similarity index 88% rename from src/V2/Parsing/Inference/InferenceResult.php rename to src/V2/Product/Extraction/ExtractionResult.php index 83ca9395..4f8394cd 100644 --- a/src/V2/Parsing/Inference/InferenceResult.php +++ b/src/V2/Product/Extraction/ExtractionResult.php @@ -1,13 +1,15 @@ |null $webhooksIds List of webhook IDs. - * @param string|null $textContext Additional text context used by the model during + * @param boolean|null $confidence Whether to calculate confidence scores for all fields. + * @param string|null $alias Optional file alias. + * @param array|null $webhooksIds List of webhook IDs. + * @param string|null $textContext Additional text context used by the model during * inference. - * @param DataSchema|string|array|null $dataSchema Additional text context used by the model during + * @param DataSchema|string|array|null $dataSchema Additional text context used by the model during * inference. - * @param PollingOptions|null $pollingOptions Polling options. */ public function __construct( string $modelId, @@ -74,9 +72,8 @@ public function __construct( ?array $webhooksIds = null, ?string $textContext = null, DataSchema|string|array|null $dataSchema = null, - ?PollingOptions $pollingOptions = null, ) { - parent::__construct($modelId, $alias, $webhooksIds, $pollingOptions); + parent::__construct($modelId, $alias, $webhooksIds); $this->rag = $rag; $this->rawText = $rawText; diff --git a/src/V2/Product/Ocr/Params/OcrParameters.php b/src/V2/Product/Ocr/Params/OcrParameters.php index 436920a1..c22cca44 100644 --- a/src/V2/Product/Ocr/Params/OcrParameters.php +++ b/src/V2/Product/Ocr/Params/OcrParameters.php @@ -16,17 +16,15 @@ class OcrParameters extends BaseParameters public static string $slug = "ocr"; /** - * @param string $modelId ID of the model. - * @param string|null $alias Optional file alias. - * @param array|null $webhooksIds List of webhook IDs. - * @param PollingOptions|null $pollingOptions Polling options. + * @param string $modelId ID of the model. + * @param string|null $alias Optional file alias. + * @param array|null $webhooksIds List of webhook IDs. */ public function __construct( string $modelId, ?string $alias = null, - ?array $webhooksIds = null, - ?PollingOptions $pollingOptions = null + ?array $webhooksIds = null ) { - parent::__construct($modelId, $alias, $webhooksIds, $pollingOptions); + parent::__construct($modelId, $alias, $webhooksIds); } } diff --git a/src/V2/Product/Split/Params/SplitParameters.php b/src/V2/Product/Split/Params/SplitParameters.php index d0be10d8..9571b7cc 100644 --- a/src/V2/Product/Split/Params/SplitParameters.php +++ b/src/V2/Product/Split/Params/SplitParameters.php @@ -16,17 +16,15 @@ class SplitParameters extends BaseParameters public static string $slug = "split"; /** - * @param string $modelId ID of the model. - * @param string|null $alias Optional file alias. - * @param array|null $webhooksIds List of webhook IDs. - * @param PollingOptions|null $pollingOptions Polling options. + * @param string $modelId ID of the model. + * @param string|null $alias Optional file alias. + * @param array|null $webhooksIds List of webhook IDs. */ public function __construct( string $modelId, ?string $alias = null, - ?array $webhooksIds = null, - ?PollingOptions $pollingOptions = null + ?array $webhooksIds = null ) { - parent::__construct($modelId, $alias, $webhooksIds, $pollingOptions); + parent::__construct($modelId, $alias, $webhooksIds); } } diff --git a/src/V2/Product/Split/SplitRange.php b/src/V2/Product/Split/SplitRange.php index 8b212ff8..4a1b5abf 100644 --- a/src/V2/Product/Split/SplitRange.php +++ b/src/V2/Product/Split/SplitRange.php @@ -2,7 +2,7 @@ namespace Mindee\V2\Product\Split; -use Mindee\V2\Parsing\Inference\InferenceResponse; +use Mindee\V2\Product\Extraction\ExtractionResponse; /** * A single document as identified when splitting a multi-document source file. @@ -21,9 +21,9 @@ class SplitRange public string $documentType; /** - * @var InferenceResponse|null $extractionResponse The extraction response associated with the split. + * @var ExtractionResponse|null $extractionResponse The extraction response associated with the split. */ - public ?InferenceResponse $extractionResponse; + public ?ExtractionResponse $extractionResponse; /** @@ -34,7 +34,7 @@ public function __construct(array $rawResponse) $this->pageRange = $rawResponse['page_range']; $this->documentType = $rawResponse['document_type']; $this->extractionResponse = isset($rawResponse['extraction_response']) ? - new InferenceResponse($rawResponse['extraction_response']) : null; + new ExtractionResponse($rawResponse['extraction_response']) : null; } /** diff --git a/tests/Input/LocalInputSourceTest.php b/tests/Input/LocalInputSourceTest.php index c2648307..413e4ad0 100644 --- a/tests/Input/LocalInputSourceTest.php +++ b/tests/Input/LocalInputSourceTest.php @@ -113,9 +113,6 @@ public function testPDFCutNPages(array $indexes) $cutPdf->useTemplate($cutPdf->importPage($pageNumber + 1)); $basePdf->AddPage(); $basePdf->useTemplate($basePdf->importPage($pageNumber + 1)); - // TODO: comparing extracted page bytes content turns out to be unreliable when using FPDF. - // This will be left here until a better solution is found within the limitations of licensing. - // $this->assertEquals($cutPdf->Output('', 'S'), $basePdf->Output('', 'S')); } $basePdf->Close(); $cutPdf->Close(); @@ -370,8 +367,6 @@ public function testSourceTextPDFCompression() $sizeOriginal = filesize(TestingUtilities::getFileTypesDir() . "/pdf/multipage.pdf"); $sizeTextCompressed = filesize(TestingUtilities::getRootDataDir() . "/output/text_multipage.pdf"); $this->assertEquals($sizeTextCompressed, $sizeOriginal); - // Note: Greater size when compressed is expected due to original not having any images, so the operation will - // be aborted. $this->assertEquals( str_repeat('*', 650), diff --git a/tests/V1/CLI/MindeeCLICommandTest.php b/tests/V1/CLI/MindeeCLICommandTest.php index fd222f94..27bac04e 100644 --- a/tests/V1/CLI/MindeeCLICommandTest.php +++ b/tests/V1/CLI/MindeeCLICommandTest.php @@ -20,8 +20,6 @@ protected function setUp(): void public function testInvalidFilePath() { $cmdOutput = MindeeCLITestingUtilities::executeTest(["financial-document", "invalid-file-path", "-k", $this->apiKey, "-D"]); - // Note : a direct comparison here would be too complicated due to the fact that the output of the command has - // formatting applied by Symfony CLI. $this->assertEquals(1, $cmdOutput["code"]); $this->assertTrue(str_contains($cmdOutput["output"][0], "Invalid path or url provided 'invalid-file-path'.")); } diff --git a/tests/V1/Input/LocalResponseV1Test.php b/tests/V1/Input/LocalResponseV1Test.php index a0abae30..faaea2b3 100644 --- a/tests/V1/Input/LocalResponseV1Test.php +++ b/tests/V1/Input/LocalResponseV1Test.php @@ -74,12 +74,10 @@ public function testValidStringLocalResponse() public function testValidStreamLocalResponse() { - // Create a stream from the file content $stream = fopen('php://memory', 'r+'); fwrite($stream, file_get_contents($this->filePath)); rewind($stream); - // Create LocalResponse instance with the stream $localResponse = new LocalResponse($stream); $this->assertNotNull($localResponse->toArray(), 'Local response file should not be null'); @@ -102,7 +100,7 @@ public function testValidStreamLocalResponse() 'Valid signature should be valid' ); - fclose($stream); // Close the stream after use + fclose($stream); } public function testValidFilePathLocalResponse() diff --git a/tests/V1/Parsing/Common/Extras/FullTextOcrExtraTest.php b/tests/V1/Parsing/Common/Extras/FullTextOcrExtraTest.php index efeeece1..124daa7e 100644 --- a/tests/V1/Parsing/Common/Extras/FullTextOcrExtraTest.php +++ b/tests/V1/Parsing/Common/Extras/FullTextOcrExtraTest.php @@ -7,7 +7,7 @@ class FullTextOCRTest extends TestCase { - private $extrasDir; // Adjust this path as needed + private $extrasDir; protected function setUp(): void { @@ -31,25 +31,4 @@ public function testGetsFullTextOCRResult() $this->assertEquals(trim($expectedText), trim(strval($fullTextOcr))); } - - // NOTE: disabled due to the current system used to manage pages of some APIs. - /* - private function loadPages() - { - $dummyClient = new \Mindee\Client("dummy-key"); - $localResponse = new \Mindee\Input\LocalResponse($this->extrasDir . '/full_text_ocr/complete.json'); - $response = $dummyClient->loadPrediction(InternationalIdV2::class, $localResponse); - return $response->document->inference->pages; - } - - public function testGetsFullTextOCRResultForPage() - { - $expectedText = file_get_contents($this->extrasDir . '/full_text_ocr/full_text_ocr.txt'); - - $pages = $this->loadPages(); - $page0Ocr = $pages[0]->extras->fullTextOcr->content; - - $this->assertEquals(implode("\n", explode("\n", $expectedText)), $page0Ocr); - } - */ } diff --git a/tests/V2/ClientV2Test.php b/tests/V2/ClientV2Test.php index 91360e5e..985f4430 100644 --- a/tests/V2/ClientV2Test.php +++ b/tests/V2/ClientV2Test.php @@ -8,9 +8,9 @@ use Mindee\Input\PathInput; use Mindee\V2\Client; use Mindee\V2\HTTP\MindeeAPIV2; -use Mindee\V2\Parsing\Inference\InferenceResponse; use Mindee\V2\Parsing\JobResponse; -use Mindee\V2\Product\Extraction\Params\InferenceParameters; +use Mindee\V2\Product\Extraction\ExtractionResponse; +use Mindee\V2\Product\Extraction\Params\ExtractionParameters; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; @@ -34,14 +34,14 @@ public function testEnqueuePostAsync(): void ->method('reqPostEnqueue') ->with( $this->isInstanceOf(LocalInputSource::class), - $this->isInstanceOf(InferenceParameters::class) + $this->isInstanceOf(ExtractionParameters::class) ) ->willReturn(new JobResponse(json_decode($syntheticResponse, true))); $mindeeClient = self::makeClientWithMockedApi($predictable); $input = new PathInput(\TestingUtilities::getFileTypesDir() . '/pdf/blank_1.pdf'); - $params = new InferenceParameters('dummy-model-id', textContext: 'dummy text context'); + $params = new ExtractionParameters('dummy-model-id', textContext: 'dummy text context'); $response = $mindeeClient->enqueueInference($input, $params); @@ -79,16 +79,19 @@ public function testDocumentGetInferenceAsync(): void $this->assertFileExists($jsonFile, 'Test resource file must exist'); $json = json_decode(file_get_contents($jsonFile), true); - $processing = new InferenceResponse($json); + $processing = new ExtractionResponse($json); $predictable->expects($this->once()) - ->method('reqGetInference') - ->with($this->equalTo('12345678-1234-1234-1234-123456789abc')) + ->method('reqGetResult') + ->with( + $this->equalTo(ExtractionResponse::class), + $this->equalTo('12345678-1234-1234-1234-123456789abc') + ) ->willReturn($processing); $mindeeClient = self::makeClientWithMockedApi($predictable); - $response = $mindeeClient->getInference('12345678-1234-1234-1234-123456789abc'); + $response = $mindeeClient->getResult(ExtractionResponse::class, '12345678-1234-1234-1234-123456789abc'); $this->assertNotNull($response, 'must have a response'); $this->assertNotNull($response->inference, 'inference must have a response'); @@ -114,10 +117,10 @@ public function testInferenceLoadsLocally(): void $this->assertFileExists($jsonFile, 'Test resource file must exist'); $localResponse = new LocalResponse($jsonFile); - $loaded = $localResponse->deserializeResponse(InferenceResponse::class); + $loaded = $localResponse->deserializeResponse(ExtractionResponse::class); - $this->assertNotNull($loaded, 'Loaded InferenceResponse must not be null'); - $this->assertInstanceOf(InferenceResponse::class, $loaded); + $this->assertNotNull($loaded, 'Loaded ExtractionResponse must not be null'); + $this->assertInstanceOf(ExtractionResponse::class, $loaded); $modelId = $loaded->inference->model->id ?? null; $this->assertEquals( @@ -143,8 +146,8 @@ public function testInvalidBaseUrlRaisesMindeeException(): void try { $client = new Client('dummy-key'); $input = new PathInput(\TestingUtilities::getFileTypesDir() . '/pdf/blank_1.pdf'); - $params = new InferenceParameters('dummy-model-id'); - $client->enqueueAndGetInference($input, $params); + $params = new ExtractionParameters('dummy-model-id'); + $client->enqueueAndGetResult(ExtractionResponse::class, $input, $params); } finally { if ($original === null) { putenv('MINDEE_V2_BASE_URL'); diff --git a/tests/V2/ClientV2TestFunctional.php b/tests/V2/ClientV2TestFunctional.php index de2d0fa9..e0a0d7e7 100644 --- a/tests/V2/ClientV2TestFunctional.php +++ b/tests/V2/ClientV2TestFunctional.php @@ -6,7 +6,8 @@ use Mindee\Input\PathInput; use Mindee\Input\URLInputSource; use Mindee\V2\Client; -use Mindee\V2\Product\Extraction\Params\InferenceParameters; +use Mindee\V2\Product\Extraction\ExtractionResponse; +use Mindee\V2\Product\Extraction\Params\ExtractionParameters; use PHPUnit\Framework\TestCase; use TestingUtilities; @@ -26,9 +27,9 @@ protected function setUp(): void public function testParseFileEmptyMultiPageMustSucceed(): void { $source = new PathInput(TestingUtilities::getFileTypesDir() . '/pdf/multipage_cut-2.pdf'); - $inferenceParams = new InferenceParameters($this->modelId, rag: false, rawText: true); + $inferenceParams = new ExtractionParameters($this->modelId, rag: false, rawText: true); - $response = $this->mindeeClient->enqueueAndGetInference($source, $inferenceParams); + $response = $this->mindeeClient->enqueueAndGetResult(ExtractionResponse::class, $source, $inferenceParams); $this->assertNotNull($response); $inference = $response->inference; $this->assertNotNull($inference); @@ -64,9 +65,9 @@ public function testParseFileFilledSinglePageMustSucceed(): void TestingUtilities::getV1DataDir() . '/products/financial_document/default_sample.jpg' ); - $inferenceParams = new InferenceParameters($this->modelId, rag: false, textContext: 'this is an invoice'); + $inferenceParams = new ExtractionParameters($this->modelId, rag: false, textContext: 'this is an invoice'); - $response = $this->mindeeClient->enqueueAndGetInference($source, $inferenceParams); + $response = $this->mindeeClient->enqueueAndGetResult(ExtractionResponse::class, $source, $inferenceParams); $this->assertNotNull($response); $inference = $response->inference; $this->assertNotNull($inference); @@ -97,7 +98,7 @@ public function testInvalidUUIDMustThrowError(): void $source = new PathInput(TestingUtilities::getFileTypesDir() . '/pdf/blank_1.pdf'); - $inferenceParams = new InferenceParameters('INVALID MODEL ID'); + $inferenceParams = new ExtractionParameters('INVALID MODEL ID'); try { $this->mindeeClient->enqueueInference($source, $inferenceParams); @@ -112,7 +113,7 @@ public function testUnknownModelMustThrowError(): void { $source = new PathInput(TestingUtilities::getFileTypesDir() . '/pdf/multipage_cut-2.pdf'); - $inferenceParams = new InferenceParameters('fc405e37-4ba4-4d03-aeba-533a8d1f0f21', textContext: 'this is invalid'); + $inferenceParams = new ExtractionParameters('fc405e37-4ba4-4d03-aeba-533a8d1f0f21', textContext: 'this is invalid'); try { $this->mindeeClient->enqueueInference($source, $inferenceParams); @@ -127,7 +128,7 @@ public function testUnknownModelMustThrowError(): void public function testInvalidJobMustThrowError(): void { try { - $this->mindeeClient->getInference('fc405e37-4ba4-4d03-aeba-533a8d1f0f21'); + $this->mindeeClient->getResult(ExtractionResponse::class, 'fc405e37-4ba4-4d03-aeba-533a8d1f0f21'); } catch (MindeeV2HttpException $e) { $this->assertStringStartsWith('404-', $e->errorCode); $this->assertNotEmpty($e->title); @@ -139,7 +140,7 @@ public function testInvalidWebhookIDsMustThrowError() { $source = new PathInput(TestingUtilities::getFileTypesDir() . '/pdf/multipage_cut-2.pdf'); - $inferenceParams = new InferenceParameters( + $inferenceParams = new ExtractionParameters( $this->modelId, null, null, @@ -163,9 +164,9 @@ public function testUrlInputSourceMustNotRaiseErrors(): void { $urlSource = new URLInputSource(getenv('MINDEE_V2_SE_TESTS_BLANK_PDF_URL')); - $inferenceParams = new InferenceParameters($this->modelId); + $inferenceParams = new ExtractionParameters($this->modelId); - $response = $this->mindeeClient->enqueueAndGetInference($urlSource, $inferenceParams); + $response = $this->mindeeClient->enqueueAndGetResult(ExtractionResponse::class, $urlSource, $inferenceParams); $this->assertNotNull($response); $inference = $response->inference; $this->assertNotNull($inference); @@ -187,9 +188,9 @@ public function testDataSchemaMustSucceed(): void TestingUtilities::getV2DataDir() . '/products/extraction/data_schema_replace_param.json' ); - $inferenceParams = new InferenceParameters($this->modelId, dataSchema: $dataSchemaReplace); + $inferenceParams = new ExtractionParameters($this->modelId, dataSchema: $dataSchemaReplace); - $response = $this->mindeeClient->enqueueAndGetInference($source, $inferenceParams); + $response = $this->mindeeClient->enqueueAndGetResult(ExtractionResponse::class, $source, $inferenceParams); $this->assertNotNull($response); $inference = $response->inference; $this->assertNotNull($inference); @@ -222,7 +223,7 @@ public function testMultipleWebhooksMustSucceed(): void TestingUtilities::getFileTypesDir() . '/pdf/blank_1.pdf' ); - $inferenceParams = new InferenceParameters($this->modelId, webhooksIds: [ + $inferenceParams = new ExtractionParameters($this->modelId, webhooksIds: [ getenv('MINDEE_V2_FAILURE_WEBHOOK_ID'), getenv('MINDEE_V2_SE_TESTS_FAILURE_WEBHOOK_ID')] ); diff --git a/tests/V2/FileOperations/CropFunctional.php b/tests/V2/FileOperations/CropFunctional.php index cc1ea6c6..6526ff1a 100644 --- a/tests/V2/FileOperations/CropFunctional.php +++ b/tests/V2/FileOperations/CropFunctional.php @@ -5,10 +5,10 @@ use Mindee\Input\PathInput; use Mindee\V2\Client; use Mindee\V2\FileOperations\Crop; -use Mindee\V2\Parsing\Inference\InferenceResponse; use Mindee\V2\Product\Crop\CropResponse; use Mindee\V2\Product\Crop\Params\CropParameters; -use Mindee\V2\Product\Extraction\Params\InferenceParameters; +use Mindee\V2\Product\Extraction\ExtractionResponse; +use Mindee\V2\Product\Extraction\Params\ExtractionParameters; use PHPUnit\Framework\TestCase; class CropFunctional extends TestCase @@ -44,7 +44,7 @@ protected function tearDown(): void } } - private function checkFindocReturn(InferenceResponse $findocResponse): void + private function checkFindocReturn(ExtractionResponse $findocResponse): void { $this->assertGreaterThan(0, strlen($findocResponse->inference->model->id)); @@ -71,9 +71,9 @@ public function testExtractCropsFromImageCorrectly(): void $this->assertEquals('default_sample.jpg_page0-1.jpg', $extractedImages[1]->filename); $extractionInput = $extractedImages[0]->asInputSource(); - $findocParams = new InferenceParameters($this->findocModelId); + $findocParams = new ExtractionParameters($this->findocModelId); - $invoice0 = $this->client->enqueueAndGetResult(InferenceResponse::class, $extractionInput, $findocParams); + $invoice0 = $this->client->enqueueAndGetResult(ExtractionResponse::class, $extractionInput, $findocParams); $this->checkFindocReturn($invoice0); diff --git a/tests/V2/FileOperations/SplitFunctional.php b/tests/V2/FileOperations/SplitFunctional.php index 83119fbf..501cbffd 100644 --- a/tests/V2/FileOperations/SplitFunctional.php +++ b/tests/V2/FileOperations/SplitFunctional.php @@ -5,8 +5,8 @@ use Mindee\Input\PathInput; use Mindee\V2\Client; use Mindee\V2\FileOperations\Split; -use Mindee\V2\Parsing\Inference\InferenceResponse; -use Mindee\V2\Product\Extraction\Params\InferenceParameters; +use Mindee\V2\Product\Extraction\ExtractionResponse; +use Mindee\V2\Product\Extraction\Params\ExtractionParameters; use Mindee\V2\Product\Split\Params\SplitParameters; use Mindee\V2\Product\Split\SplitResponse; use PHPUnit\Framework\TestCase; @@ -44,7 +44,7 @@ protected function tearDown(): void } } - private function checkFindocReturn(InferenceResponse $findocResponse): void + private function checkFindocReturn(ExtractionResponse $findocResponse): void { $this->assertGreaterThan(0, strlen($findocResponse->inference->model->id)); @@ -73,9 +73,9 @@ public function testExtractSplitsFromPDFCorrectly(): void $this->assertEquals('default_sample_002-002.pdf', $extractedSplits[1]->filename); $inferenceInput = $extractedSplits[0]->asInputSource(); - $findocParams = new InferenceParameters($this->findocModelId); + $findocParams = new ExtractionParameters($this->findocModelId); - $invoice0 = $this->client->enqueueAndGetResult(InferenceResponse::class, $inferenceInput, $findocParams); + $invoice0 = $this->client->enqueueAndGetResult(ExtractionResponse::class, $inferenceInput, $findocParams); $this->checkFindocReturn($invoice0); diff --git a/tests/V2/Input/InferenceParameterTest.php b/tests/V2/Input/InferenceParameterTest.php index 4d623d5d..2e32c100 100644 --- a/tests/V2/Input/InferenceParameterTest.php +++ b/tests/V2/Input/InferenceParameterTest.php @@ -4,7 +4,7 @@ use Mindee\V2\Product\Extraction\Params\DataSchema; -use Mindee\V2\Product\Extraction\Params\InferenceParameters; +use Mindee\V2\Product\Extraction\Params\ExtractionParameters; use PHPUnit\Framework\TestCase; class InferenceParameterTest extends TestCase @@ -21,14 +21,14 @@ protected function setUp(): void { } public function testDataSchemaShouldntReplaceWhenUnset() { - $params = new InferenceParameters('model_id', dataSchema: null); + $params = new ExtractionParameters('model_id', dataSchema: null); $this->assertFalse(isset($params->dataSchema)); } public function testDataSchemaShouldEquateNoMatterTheType(){ - $paramsDict = new InferenceParameters('model_id', dataSchema: $this->expectedSchemaDict); - $paramsString = new InferenceParameters('model_id', dataSchema: $this->expectedSchemaString); - $paramsObject = new InferenceParameters('model_id', dataSchema: $this->expectedSchemaObject); + $paramsDict = new ExtractionParameters('model_id', dataSchema: $this->expectedSchemaDict); + $paramsString = new ExtractionParameters('model_id', dataSchema: $this->expectedSchemaString); + $paramsObject = new ExtractionParameters('model_id', dataSchema: $this->expectedSchemaObject); $this->assertEquals(strval($paramsDict->dataSchema), $this->expectedSchemaString); $this->assertEquals(strval($paramsObject->dataSchema), $this->expectedSchemaString); $this->assertEquals(strval($paramsString->dataSchema), $this->expectedSchemaString); diff --git a/tests/V2/Input/LocalResponseV2Test.php b/tests/V2/Input/LocalResponseV2Test.php index 46026a58..5122fefa 100644 --- a/tests/V2/Input/LocalResponseV2Test.php +++ b/tests/V2/Input/LocalResponseV2Test.php @@ -3,7 +3,7 @@ namespace V2\Input; use Mindee\Input\LocalResponse; -use Mindee\V2\Parsing\Inference\InferenceResponse; +use Mindee\V2\Product\Extraction\ExtractionResponse; use PHPUnit\Framework\TestCase; class LocalResponseV2Test extends TestCase @@ -26,8 +26,8 @@ protected function assertLocalResponse(LocalResponse $localResponse): void $this->assertFalse($localResponse->isValidHMACSignature($fakeHMACSigning, "fake HMAC signature")); $this->assertEquals($signature, $localResponse->getHmacSignature($fakeHMACSigning)); $this->assertTrue($localResponse->isValidHMACSignature($fakeHMACSigning, $signature)); - $response = $localResponse->deserializeResponse(InferenceResponse::class); - $this->assertInstanceOf(InferenceResponse::class, $response); + $response = $localResponse->deserializeResponse(ExtractionResponse::class); + $this->assertInstanceOf(ExtractionResponse::class, $response); $this->assertNotNull($response->inference); $this->assertNotNull($response->inference->result); $this->assertNotNull($response->inference->result->fields); diff --git a/tests/V2/Parsing/InferenceResponseTest.php b/tests/V2/Parsing/ExtractionResponseTest.php similarity index 98% rename from tests/V2/Parsing/InferenceResponseTest.php rename to tests/V2/Parsing/ExtractionResponseTest.php index caca52de..a5d44c10 100644 --- a/tests/V2/Parsing/InferenceResponseTest.php +++ b/tests/V2/Parsing/ExtractionResponseTest.php @@ -10,8 +10,8 @@ use Mindee\V2\Parsing\Inference\Field\ListField; use Mindee\V2\Parsing\Inference\Field\ObjectField; use Mindee\V2\Parsing\Inference\Field\SimpleField; -use Mindee\V2\Parsing\Inference\InferenceResponse; use Mindee\V2\Parsing\JobResponse; +use Mindee\V2\Product\Extraction\ExtractionResponse; use PHPUnit\Framework\TestCase; use TestingUtilities; @@ -20,15 +20,15 @@ /** * InferenceV2 – field integrity checks */ -class InferenceResponseTest extends TestCase +class ExtractionResponseTest extends TestCase { - private function loadFromResource(string $resourcePath): InferenceResponse + private function loadFromResource(string $resourcePath): ExtractionResponse { $fullPath = TestingUtilities::getV2ProductDir() . "/$resourcePath"; $this->assertFileExists($fullPath, "Resource file must exist: $resourcePath"); $localResponse = new LocalResponse($fullPath); - return $localResponse->deserializeResponse(InferenceResponse::class); + return $localResponse->deserializeResponse(ExtractionResponse::class); } private function readFileAsString(string $path): string @@ -101,7 +101,7 @@ public function testAsyncPredictWhenCompleteMustExposeAllProperties(): void $inference = $response->inference; $this->assertNotNull($inference, 'Inference must not be null'); - $this->assertEquals('12345678-1234-1234-1234-123456789abc', $inference->id, 'Inference ID mismatch'); + $this->assertEquals('12345678-1234-1234-1234-123456789abc', $inference->id, 'ExtractionInference ID mismatch'); $model = $inference->model; $this->assertNotNull($model, 'Model must not be null'); diff --git a/tests/V2/Product/CropTest.php b/tests/V2/Product/CropTest.php index eee10c35..4d868040 100644 --- a/tests/V2/Product/CropTest.php +++ b/tests/V2/Product/CropTest.php @@ -8,8 +8,6 @@ use Mindee\V2\Product\Crop\CropResponse; use Mindee\Geometry\Point; -// Added for the polygon coordinate assertions - require_once(__DIR__ . "/../../TestingUtilities.php"); /** @@ -86,7 +84,6 @@ public function testCropWhenSingleMustHaveValidProperties(): void $polygon = $firstCrop->location->polygon; $this->assertCount(4, $polygon->getCoordinates()); - // Note: Using assertEquals here instead of assertSame to allow for object value comparison $this->assertEquals(new Point(0.214, 0.036), $polygon->getCoordinates()[0]); $this->assertEquals(new Point(0.476, 0.036), $polygon->getCoordinates()[1]); $this->assertEquals(new Point(0.476, 0.949), $polygon->getCoordinates()[2]); @@ -158,8 +155,6 @@ public function testRstDisplayMustBeAccessible(): void $inference = $response->inference; $this->assertNotNull($inference); - // Assumes your Inference class implements the __toString() magic method - // which maps to C#'s ToString() $this->assertEquals( self::normalizeLineEndings($rstReference), self::normalizeLineEndings((string)$inference) diff --git a/tests/V2/Product/OcrTest.php b/tests/V2/Product/OcrTest.php index 01d027b5..0d6b9808 100644 --- a/tests/V2/Product/OcrTest.php +++ b/tests/V2/Product/OcrTest.php @@ -68,7 +68,6 @@ public function testOcrWhenSingleMustHaveValidProperties(): void $firstWord = $firstPage->words[0]; $this->assertSame("Shipper:", $firstWord->content); - // Using the getCoordinates() logic from the corrected file $this->assertCount(4, $firstWord->polygon->getCoordinates()); $fifthWord = $firstPage->words[4];