1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the core-library package. |
5
|
|
|
* |
6
|
|
|
* (c) 2020 WEBEWEB |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace WBW\Library\Core\ThirdParty\OcrLad\Model; |
13
|
|
|
|
14
|
|
|
use WBW\Library\Core\Geometry\Point; |
15
|
|
|
use WBW\Library\Core\Model\Attribute\IntegerPageTrait; |
16
|
|
|
use WBW\Library\Core\Model\Attribute\StringContentTrait; |
17
|
|
|
use WBW\Library\Core\Model\Attribute\StringTypeTrait; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Word. |
21
|
|
|
* |
22
|
|
|
* @author webeweb <https://github.com/webeweb> |
23
|
|
|
* @package WBW\Library\Core\ThirdParty\OcrLad\Model |
24
|
|
|
*/ |
25
|
|
|
class Word { |
26
|
|
|
|
27
|
|
|
use IntegerPageTrait; |
28
|
|
|
use StringContentTrait; |
29
|
|
|
use StringTypeTrait; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Type "line break". |
33
|
|
|
* |
34
|
|
|
* @var string |
35
|
|
|
*/ |
36
|
|
|
const TYPE_LINE_BREAK = "LB"; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Type "no line break". |
40
|
|
|
* |
41
|
|
|
* @var string |
42
|
|
|
*/ |
43
|
|
|
const TYPE_NO_LINE_BREAK = "NLB"; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* OCR confidence. |
47
|
|
|
* |
48
|
|
|
* @var float|null |
49
|
|
|
*/ |
50
|
|
|
private $ocrConfidence; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Parent. |
54
|
|
|
* |
55
|
|
|
* @var Page|null |
56
|
|
|
*/ |
57
|
|
|
private $parent; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Point 1. |
61
|
|
|
* |
62
|
|
|
* @var Point |
63
|
|
|
*/ |
64
|
|
|
private $point1; |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Point 2. |
68
|
|
|
* |
69
|
|
|
* @var Point |
70
|
|
|
*/ |
71
|
|
|
private $point2; |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Constructor. |
75
|
|
|
*/ |
76
|
|
|
public function __construct() { |
77
|
|
|
$this->setPoint1(new Point()); |
78
|
|
|
$this->setPoint2(new Point()); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Get the OCR confidence. |
83
|
|
|
* |
84
|
|
|
* @return float|null Returns the OCR confidence. |
85
|
|
|
*/ |
86
|
|
|
public function getOcrConfidence(): ?float { |
87
|
|
|
return $this->ocrConfidence; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Get the parent. |
92
|
|
|
* |
93
|
|
|
* @return Page|null Returns the parent. |
94
|
|
|
*/ |
95
|
|
|
public function getParent(): ?Page { |
96
|
|
|
return $this->parent; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Get the point 1. |
101
|
|
|
* |
102
|
|
|
* @return Point Returns the point 1 |
103
|
|
|
*/ |
104
|
|
|
public function getPoint1(): Point { |
105
|
|
|
return $this->point1; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Get the point 2. |
110
|
|
|
* |
111
|
|
|
* @return Point Returns the point 2. |
112
|
|
|
*/ |
113
|
|
|
public function getPoint2(): Point { |
114
|
|
|
return $this->point2; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Get the X1. |
119
|
|
|
* |
120
|
|
|
* @return float|null Returns the X1. |
121
|
|
|
*/ |
122
|
|
|
public function getX1(): ?float { |
123
|
|
|
return $this->getPoint1()->getX(); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Get the X2. |
128
|
|
|
* |
129
|
|
|
* @return float|null Returns the X2. |
130
|
|
|
*/ |
131
|
|
|
public function getX2(): ?float { |
132
|
|
|
return $this->getPoint2()->getX(); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* Get the Y1. |
137
|
|
|
* |
138
|
|
|
* @return float|null Returns the Y1. |
139
|
|
|
*/ |
140
|
|
|
public function getY1(): ?float { |
141
|
|
|
return $this->getPoint1()->getY(); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* Get the Y2. |
146
|
|
|
* |
147
|
|
|
* @return float|null Returns the Y2. |
148
|
|
|
*/ |
149
|
|
|
public function getY2(): ?float { |
150
|
|
|
return $this->getPoint2()->getY(); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* Set the OCR confidence. |
155
|
|
|
* |
156
|
|
|
* @param float|null $ocrConfidence The OCR confidence. |
157
|
|
|
* @return Word Returns this word. |
158
|
|
|
*/ |
159
|
|
|
public function setOcrConfidence(?float $ocrConfidence): Word { |
160
|
|
|
$this->ocrConfidence = $ocrConfidence; |
161
|
|
|
return $this; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* Set the parent. |
166
|
|
|
* |
167
|
|
|
* @param Page|null $parent The parent. |
168
|
|
|
* @return Word Returns this word. |
169
|
|
|
*/ |
170
|
|
|
public function setParent(Page $parent = null): Word { |
171
|
|
|
$this->parent = $parent; |
172
|
|
|
return $this; |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* Set the point 1. |
177
|
|
|
* |
178
|
|
|
* @param Point $point1 The point 1. |
179
|
|
|
* @return Word Returns this word. |
180
|
|
|
*/ |
181
|
|
|
protected function setPoint1(Point $point1): Word { |
182
|
|
|
$this->point1 = $point1; |
183
|
|
|
return $this; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* Set the point 2. |
188
|
|
|
* |
189
|
|
|
* @param Point $point2 The point 2. |
190
|
|
|
* @return Word Returns this word. |
191
|
|
|
*/ |
192
|
|
|
protected function setPoint2(Point $point2): Word { |
193
|
|
|
$this->point2 = $point2; |
194
|
|
|
return $this; |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* Set the X1. |
199
|
|
|
* |
200
|
|
|
* @param float|null $x1 The X1. |
201
|
|
|
* @return Word Returns this word. |
202
|
|
|
*/ |
203
|
|
|
public function setX1(?float $x1): Word { |
204
|
|
|
$this->getPoint1()->setX($x1); |
205
|
|
|
return $this; |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* Set the X2. |
210
|
|
|
* |
211
|
|
|
* @param float|null $x2 The X2. |
212
|
|
|
* @return Word Returns this word. |
213
|
|
|
*/ |
214
|
|
|
public function setX2(?float $x2): Word { |
215
|
|
|
$this->getPoint2()->setX($x2); |
216
|
|
|
return $this; |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
/** |
220
|
|
|
* Set the Y1. |
221
|
|
|
* |
222
|
|
|
* @param float|null $y1 The Y1. |
223
|
|
|
* @return Word Returns this word. |
224
|
|
|
*/ |
225
|
|
|
public function setY1(?float $y1): Word { |
226
|
|
|
$this->getPoint1()->setY($y1); |
227
|
|
|
return $this; |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
/** |
231
|
|
|
* Set the Y2. |
232
|
|
|
* |
233
|
|
|
* @param float|null $y2 The Y2. |
234
|
|
|
* @return Word Returns this word. |
235
|
|
|
*/ |
236
|
|
|
public function setY2(?float $y2): Word { |
237
|
|
|
$this->getPoint2()->setY($y2); |
238
|
|
|
return $this; |
239
|
|
|
} |
240
|
|
|
} |