-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathInference.php
More file actions
89 lines (80 loc) · 2.33 KB
/
Copy pathInference.php
File metadata and controls
89 lines (80 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
namespace Mindee\V1\Parsing\Common;
use Mindee\V1\Parsing\Common\Extras\Extras;
/**
* Base Inference class for all predictions.
*/
abstract class Inference
{
/**
* @var Product Name and version of a given product, as sent back by the API.
*/
public Product $product;
/**
* @var string Name of the product's endpoint.
*/
public static string $endpointName;
/**
* @var string Version of the product's endpoint.
*/
public static string $endpointVersion;
/**
* @var Prediction A document's top-level Prediction.
*/
public Prediction $prediction;
/**
* @var array A document's pages.
*/
public array $pages;
/**
* @var boolean|null Whether the document has had any rotation applied to it.
*/
public ?bool $isRotationApplied;
/**
* @var integer|null Optional page id for page-level predictions.
*/
public ?int $pageId;
/**
* @var Extras|null Potential Extras fields sent back along with the prediction.
*/
public ?Extras $extras;
/**
* @param array $rawInference Raw inference array.
* @param integer|null $pageId Page number for multi pages document.
*/
public function __construct(array $rawInference, ?int $pageId = null)
{
$this->isRotationApplied = null;
if (array_key_exists('is_rotation_applied', $rawInference)) {
$this->isRotationApplied = $rawInference['is_rotation_applied'];
}
$this->product = new Product($rawInference['product']);
if (isset($pageId)) {
$this->pageId = $pageId;
}
if (array_key_exists('extras', $rawInference)) {
$this->extras = new Extras($rawInference['extras']);
}
}
/**
* @return string String representation.
*/
public function __toString(): string
{
$rotationApplied = $this->isRotationApplied ? 'Yes' : 'No';
$pagesStr = "";
if (count($this->pages)) {
$pagesStr = "\nPage Predictions\n================\n\n" . implode(
"\n",
array_map(fn ($page) => strval($page), $this->pages)
);
}
return "Inference
#########
:Product: $this->product
:Rotation applied: $rotationApplied
Prediction
==========
$this->prediction$pagesStr";
}
}