Skip to content

Commit a943f64

Browse files
Aleksey Shundrikhleb-albau
authored andcommitted
- add ability to bind non-existent AuthenticityCheckResultItem into RawAuthenticityCheckResultItem;
- add 'abstract' layer for authenticity results
1 parent 2010c87 commit a943f64

File tree

17 files changed

+329
-5
lines changed

17 files changed

+329
-5
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,5 @@ target/
6969

7070
#Ipython Notebook
7171
.ipynb_checkpoints
72+
73+
model.json

example/example.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@
5656
doc_number_mrz_validity = doc_number_field.source_validity(Source.MRZ)
5757
doc_number_mrz_visual_matching = doc_number_field.cross_source_comparison(Source.MRZ, Source.VISUAL)
5858

59+
doc_authenticity = response.authenticity
60+
61+
doc_ir_b900 = doc_authenticity.ir_b900_checks
62+
doc_ir_b900_blank = doc_ir_b900.checks_by_element(SecurityFeatureType.BLANK)
63+
64+
doc_image_pattern = doc_authenticity.image_pattern_checks
65+
doc_image_pattern_blank = doc_image_pattern.checks_by_element(SecurityFeatureType.BLANK)
66+
5967
# images fields example
6068
document_image = response.images.get_field(GraphicFieldType.DOCUMENT_FRONT).get_value()
6169
portrait_from_visual = response.images.get_field(GraphicFieldType.PORTRAIT).get_value(Source.VISUAL)

generator-templates/model.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@ class {{classname}}(object):
190190
"""Returns the real base class specified by the discriminator"""
191191
discriminator_key = self.attribute_map[self.discriminator]
192192
discriminator_value = data[discriminator_key]
193-
from regula.documentreader.webclient.ext.models import RawResultItem
194-
return self.discriminator_value_class_map.get(discriminator_value, RawResultItem.__name__)
193+
from regula.documentreader.webclient.ext.models import Raw{{classname}}
194+
return self.discriminator_value_class_map.get(discriminator_value, Raw{{classname}}.__name__)
195195

196196
{{/discriminator}}
197197
def to_dict(self):

regula/documentreader/webclient/ext/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
from regula.documentreader.webclient.ext.api.document_reader_api import DocumentReaderApi
2+
from regula.documentreader.webclient.ext.models.authenticity.authenticity_check_list import AuthenticityCheckList
3+
from regula.documentreader.webclient.ext.models.authenticity.fiber import FiberChecks
4+
from regula.documentreader.webclient.ext.models.authenticity.ident import IdentChecks
5+
from regula.documentreader.webclient.ext.models.authenticity.image_ident import ImageIdentChecks
6+
from regula.documentreader.webclient.ext.models.authenticity.ocr_security_text import OCRSecurityTextChecks
7+
from regula.documentreader.webclient.ext.models.authenticity.security_feature import SecurityFeatureChecks
28
from regula.documentreader.webclient.ext.models.images import Images, ImagesField
39
from regula.documentreader.webclient.ext.models.raw_result_item import RawResultItem
410
from regula.documentreader.webclient.ext.models.recognition_request import RecognitionRequest, RecognitionImage

regula/documentreader/webclient/ext/models/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1+
from regula.documentreader.webclient.ext.models.authenticity.authenticity_check_list import AuthenticityCheckList
2+
from regula.documentreader.webclient.ext.models.authenticity.fiber import FiberChecks
3+
from regula.documentreader.webclient.ext.models.authenticity.ident import IdentChecks
4+
from regula.documentreader.webclient.ext.models.authenticity.image_ident import ImageIdentChecks
5+
from regula.documentreader.webclient.ext.models.authenticity.ocr_security_text import OCRSecurityTextChecks
6+
from regula.documentreader.webclient.ext.models.authenticity.security_feature import SecurityFeatureChecks
17
from regula.documentreader.webclient.ext.models.images import Images, ImagesField
8+
from regula.documentreader.webclient.ext.models.raw_authenticity_result_item import RawAuthenticityCheckResultItem
29
from regula.documentreader.webclient.ext.models.raw_result_item import RawResultItem
310
from regula.documentreader.webclient.ext.models.recognition_request import RecognitionImage
411
from regula.documentreader.webclient.ext.models.recognition_request import RecognitionRequest
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from regula.documentreader.webclient.ext.models.authenticity.authenticity_check_list import AuthenticityCheckList
2+
from regula.documentreader.webclient.ext.models.authenticity.fiber import FiberChecks
3+
from regula.documentreader.webclient.ext.models.authenticity.ident import IdentChecks
4+
from regula.documentreader.webclient.ext.models.authenticity.image_ident import ImageIdentChecks
5+
from regula.documentreader.webclient.ext.models.authenticity.ocr_security_text import OCRSecurityTextChecks
6+
from regula.documentreader.webclient.ext.models.authenticity.security_feature import SecurityFeatureChecks
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
from typing import Optional
2+
3+
from regula.documentreader.webclient import gen, AuthenticityResultType
4+
from regula.documentreader.webclient.ext.models.authenticity.fiber import FiberChecks
5+
from regula.documentreader.webclient.ext.models.authenticity.ident import IdentChecks
6+
from regula.documentreader.webclient.ext.models.authenticity.image_ident import ImageIdentChecks
7+
from regula.documentreader.webclient.ext.models.authenticity.ocr_security_text import OCRSecurityTextChecks
8+
from regula.documentreader.webclient.ext.models.authenticity.security_feature import SecurityFeatureChecks
9+
10+
11+
class AuthenticityCheckList(gen.AuthenticityCheckList):
12+
13+
@property
14+
def uv_luminescence_checks(self) -> Optional[SecurityFeatureChecks]:
15+
return self.__result_by_type(AuthenticityResultType.UV_LUMINESCENCE, SecurityFeatureChecks)
16+
17+
@property
18+
def ir_b900_checks(self) -> Optional[SecurityFeatureChecks]:
19+
return self.__result_by_type(AuthenticityResultType.IR_B900, SecurityFeatureChecks)
20+
21+
@property
22+
def image_pattern_checks(self) -> Optional[IdentChecks]:
23+
return self.__result_by_type(AuthenticityResultType.IMAGE_PATTERN, IdentChecks)
24+
25+
@property
26+
def axial_protection_checks(self) -> Optional[SecurityFeatureChecks]:
27+
return self.__result_by_type(AuthenticityResultType.AXIAL_PROTECTION, SecurityFeatureChecks)
28+
29+
@property
30+
def uv_fiber_checks(self) -> Optional[FiberChecks]:
31+
return self.__result_by_type(AuthenticityResultType.UV_FIBERS, FiberChecks)
32+
33+
@property
34+
def ir_visibility_checks(self) -> Optional[IdentChecks]:
35+
return self.__result_by_type(AuthenticityResultType.IR_VISIBILITY, IdentChecks)
36+
37+
@property
38+
def ocr_security_text_checks(self) -> Optional[OCRSecurityTextChecks]:
39+
return self.__result_by_type(AuthenticityResultType.OCR_SECURITY_TEXT, OCRSecurityTextChecks)
40+
41+
@property
42+
def ipi_checks(self) -> Optional[ImageIdentChecks]:
43+
return self.__result_by_type(AuthenticityResultType.IPI, ImageIdentChecks)
44+
45+
@property
46+
def embed_image_checks(self) -> Optional[SecurityFeatureChecks]:
47+
return self.__result_by_type(AuthenticityResultType.PHOTO_EMBED_TYPE, SecurityFeatureChecks)
48+
49+
@property
50+
def holograms_checks(self) -> Optional[SecurityFeatureChecks]:
51+
return self.__result_by_type(AuthenticityResultType.HOLOGRAMS, SecurityFeatureChecks)
52+
53+
@property
54+
def photo_area_checks(self) -> Optional[SecurityFeatureChecks]:
55+
return self.__result_by_type(AuthenticityResultType.PHOTO_AREA, SecurityFeatureChecks)
56+
57+
@property
58+
def portrait_comparison_checks(self) -> Optional[IdentChecks]:
59+
return self.__result_by_type(AuthenticityResultType.PORTRAIT_COMPARISON, IdentChecks)
60+
61+
@property
62+
def barcode_format_checks(self) -> Optional[SecurityFeatureChecks]:
63+
return self.__result_by_type(AuthenticityResultType.BARCODE_FORMAT_CHECK, SecurityFeatureChecks)
64+
65+
@property
66+
def kinegram_checks(self) -> Optional[IdentChecks]:
67+
return self.__result_by_type(AuthenticityResultType.KINEGRAM, IdentChecks)
68+
69+
@property
70+
def letter_screen_checks(self) -> Optional[IdentChecks]:
71+
return self.__result_by_type(AuthenticityResultType.LETTER_SCREEN, IdentChecks)
72+
73+
def __result_by_type(self, authenticity_type: int, parent_class: type) -> Optional[gen.AuthenticityCheckResult]:
74+
for result in self.list:
75+
if result.type == authenticity_type:
76+
result.__class__ = parent_class
77+
return result
78+
return None
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from typing import List
2+
3+
from regula.documentreader.webclient import gen
4+
5+
6+
class FiberChecks(gen.AuthenticityCheckResult):
7+
8+
@gen.AuthenticityCheckResult.list.getter
9+
def list(self) -> List[gen.FiberResult]:
10+
# noinspection PyTypeChecker
11+
return super().list
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from typing import List, Optional
2+
3+
from regula.documentreader.webclient import gen
4+
5+
6+
class IdentChecks(gen.AuthenticityCheckResult):
7+
@gen.AuthenticityCheckResult.list.getter
8+
def list(self) -> List[gen.IdentResult]:
9+
# noinspection PyTypeChecker
10+
return super().list
11+
12+
# element_type is SecurityFeatureType
13+
def checks_by_element(self, element_type: int) -> List[gen.IdentResult]:
14+
return [check for check in self.list if check.element_type == element_type]
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from typing import List
2+
3+
from regula.documentreader.webclient import gen
4+
5+
6+
class ImageIdentChecks(gen.AuthenticityCheckResult):
7+
@gen.AuthenticityCheckResult.list.getter
8+
def list(self) -> List[gen.PhotoIdentResult]:
9+
# noinspection PyTypeChecker
10+
return super().list

0 commit comments

Comments
 (0)