-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
697946d
commit d39d593
Showing
4 changed files
with
42 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,20 @@ | ||
from dedoc.common.exceptions.structure_extractor_error import StructureExtractorError | ||
from dedoc.structure_extractors.patterns.abstract_pattern import AbstractPattern | ||
|
||
|
||
def get_pattern(pattern_parameters: dict) -> AbstractPattern: | ||
import dedoc.structure_extractors.patterns as patterns_module | ||
|
||
assert isinstance(pattern_parameters, dict) | ||
assert isinstance(pattern_parameters, dict), "Pattern configuration must be a dict" | ||
assert "name" in pattern_parameters, "Pattern parameter missing 'name'" | ||
|
||
supported_patterns = {pattern.name(): pattern for pattern in patterns_module.__all__} | ||
pattern_class = supported_patterns.get(pattern_parameters["name"]) | ||
if pattern_class is None: | ||
raise ValueError(f"Pattern {pattern_parameters['name']} is not found in supported patterns: {supported_patterns.keys()}") | ||
assert pattern_class is not None, f"Pattern {pattern_parameters['name']} is not found in supported patterns: {supported_patterns.keys()}" | ||
|
||
pattern_parameters.pop("name") | ||
pattern = pattern_class(**pattern_parameters) | ||
try: | ||
pattern = pattern_class(**pattern_parameters) | ||
except TypeError as e: | ||
raise StructureExtractorError(msg=str(e)) | ||
return pattern |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters