-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathisa51_decoder_agg.py
29 lines (24 loc) · 1.1 KB
/
isa51_decoder_agg.py
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
from typing import List, Optional
from base_decoder import ISA51Decoder
from data_types import ISA51Id
from letter_based_decoder import LetterBasedDecoder, UserChoiceMap
from table_based_decoder import ISA51AllowedTableBasedDecoder
class ISA51DecoderAggregator(ISA51Decoder):
"""
Aggregates multiple ISA51 decoders for decoding tasks.
The class serves as an orchestrator for different ISA51 decoders by
aggregating their functionality. It iterates through a list of decoders
and attempts to decode a given ISA51 code using each decoder sequentially
until a valid result is obtained. This allows leveraging different decoding
strategies to handle ISA51 codes effectively.
"""
def __init__(self, user_choices_map: Optional[UserChoiceMap] = None):
self.decoders = [
ISA51AllowedTableBasedDecoder(),
LetterBasedDecoder(user_choices_map),
]
def decode_isa_51(self, code: str) -> List[ISA51Id]:
for decoder in self.decoders:
result = decoder.decode_isa_51(code)
if len(result) > 0:
return result