id_contexts package¶
Submodules¶
id_contexts.id_context module¶
This file contains the abstraction of all ID contexts, which contain the necessary information and settings specific to a particular ID document type.
-
class
id_contexts.id_context.
FieldType
[source]¶ Bases:
enum.Enum
An enumerator used to specify the field type for extracted ID information.
-
DATE_HYPHENATED
= 3¶
-
MIXED
= 2¶
-
NUMERIC_ONLY
= 1¶
-
TEXT_ONLY
= 0¶
-
-
class
id_contexts.id_context.
IDContext
(match_contexts)[source]¶ Bases:
abc.ABC
This class is an abstraction of all ID contexts. The ID contexts serve to contain the necessary information and settings specific to a particular ID document type for operations such as extracting information from an ID OCR string.
- Attributes:
- match_contexts (list): A list of dictionaries that contain the contextual information used in the process of
retrieving field values from the OCR output string. e.g. {
‘field’: ‘surname’, // The field name - can be set to any string one desires. ‘find’: ‘surname’, // A string to be used for matching field names.
// in the OCR output string (used to know what to look for).- ‘field_type’: // Indicates if the field value is to be treated as alphanumeric or
- FieldType.TEXT_ONLY // just numeric or just alphabetical characters.
- // (e.g. indicates that all numbers from field value should be removed // if the field type is TEXT_ONLY).
- ‘line_type’: TITLED_NEWLINE // Indicates the type of line to be considered when looking for the
- // field value relative to the ‘find’ value. // (e.g. TITLED_NEWLINE indicates that the field value is preceded // by a field name/title and a newline).
‘multi_line’: True, // Indicates that the field value spans multiple lines. ‘multi_line_end’: ‘names’ // (Optional, unless multi_line is true) A string identifying the next
// field name that indicates the end of the multi-line field value.- ‘to_uppercase’: False, // (Optional) Indicates that the retrieved field value must be
- // converted to uppercase.
}
-
get_id_info
(id_string, barcode_data=None, ignore_fields=None, fuzzy_min_ratio=60.0, max_multi_line=2)[source]¶ Responsible for filtering undesirable fields to be retrieved as well as delegating the responsibility of extracting ID information from an OCR string and housing said information in a convenient dictionary. Some type checking is done to reduce the likelihood of errors further down the call stack.
- Args:
id_string (str): A string containing some ID information. barcode_data (dict, Optional): A dictionary object containing information extracted from a barcode. ignore_fields (list, Optional): A list containing fields which are to be ignored during extraction. fuzzy_min_ratio (float): The threshold ratio for a minimum, acceptable ratio of fuzziness when comparing
two strings.- max_multi_line (int): Specifies the maximum number of lines that is to be extracted from fields that are
- noted as running onto multiple lines.
- Returns:
- (dict): A dictionary object containing the relevant, extracted ID information.
- Raises:
- TypeError: If id_string is not a string. TypeError: If barcode_data is not a dictionary.
id_contexts.sa_id module¶
This file contains the abstraction and high-level logic of South African ID contexts.
-
class
id_contexts.sa_id.
SAID
(match_contexts)[source]¶ Bases:
id_contexts.id_context.IDContext
An abstract class for South African IDs. Contains the high-level logic that is relevant to all South African IDs.
-
POST_PROCESS_MIN_FUZZY_RATIO
= 70.0¶
-
VALID_ID_LENGTH
= 13¶
-
validate_id_number
(id_number)[source]¶ Determines whether a given id number is valid or not.
- Args:
- id_number (str): An ID number that is to be validated.
- Returns:
- (bool): True if the id number is valid, False otherwise.
- Raises:
- TypeError: If id_number is not a string containing only numeric characters.
-
id_contexts.sa_id_book module¶
This file contains the logic for South African ID book (post 1994) context.
-
class
id_contexts.sa_id_book.
SAIDBook
[source]¶ Bases:
id_contexts.sa_id.SAID
A class that represents an ID context for a South African ID book (post 1994). It supplies some of the concrete information, such as the match contexts, to the classes higher up in inheritance hierarchy and implements abstract methods defined by its parent.
id_contexts.sa_id_book_old module¶
This file contains the logic for South African ID book (pre 1994) context.
-
class
id_contexts.sa_id_book_old.
SAIDBookOld
[source]¶ Bases:
id_contexts.sa_id.SAID
A class that represents an ID context for a South African ID book (pre 1994). It supplies some of the concrete information, such as the match contexts, to the classes higher up in inheritance hierarchy and implements abstract methods defined by its parent.
id_contexts.sa_id_card module¶
This file contains the logic for South African ID card context.
-
class
id_contexts.sa_id_card.
SAIDCard
[source]¶ Bases:
id_contexts.sa_id.SAID
A class that represents an ID context for a South African ID card. It supplies some of the concrete information, such as the match contexts, to the classes higher up in inheritance hierarchy and implements abstract methods defined by its parent.
id_contexts.up_student_card module¶
This file contains the logic for University of Pretoria ID card context. It is mainly intended for demonstration purposes.
-
class
id_contexts.up_student_card.
UPStudentCard
[source]¶ Bases:
id_contexts.id_context.IDContext
A class that represents an ID context for a University of Pretoria ID card.