Coverage for nlp_manager/processor_helpers.py: 70%
10 statements
« prev ^ index » next coverage.py v7.8.0, created at 2025-08-27 10:34 -0500
« prev ^ index » next coverage.py v7.8.0, created at 2025-08-27 10:34 -0500
1"""
2crate_anon/nlp_manager/processor_helpers.py
4===============================================================================
6 Copyright (C) 2015, University of Cambridge, Department of Psychiatry.
7 Created by Rudolf Cardinal (rnc1001@cam.ac.uk).
9 This file is part of CRATE.
11 CRATE is free software: you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
16 CRATE is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with CRATE. If not, see <https://www.gnu.org/licenses/>.
24===============================================================================
26**Helper functions to manage all NLP processor classes.**
28These use a delayed import, sorting out some circular import problems.
30"""
32# =============================================================================
33# Imports
34# =============================================================================
36from typing import Optional
38from crate_anon.nlp_manager.base_nlp_parser import TableMaker
41# =============================================================================
42# Helper functions
43# =============================================================================
46def make_nlp_parser_unconfigured(
47 classname: str, raise_if_absent: bool = True
48) -> Optional[TableMaker]:
49 """
50 Get a debugging (unconfigured) instance of an NLP parser.
52 Args:
53 classname: the name of the NLP parser class
54 raise_if_absent: raise ``ValueError`` if there is no match?
56 Returns:
57 the class, or ``None`` if there isn't one with that name
59 """
60 from crate_anon.nlp_manager.all_processors import (
61 get_nlp_parser_class,
62 ) # delayed import
64 cls = get_nlp_parser_class(classname)
65 if cls:
66 return cls(nlpdef=None, cfg_processor_name=None)
67 if raise_if_absent:
68 raise ValueError(f"Unknown NLP processor type: {classname!r}")
69 return None