@@ -77,7 +77,7 @@ class Engine:
77
77
def __init__ (
78
78
self ,
79
79
working_folder : Optional [PathLike ] = None ,
80
- analyzer_name : str = "parse-en-us" ,
80
+ analyzer_path : str = None ,
81
81
verbose : bool = False ,
82
82
initialize : bool = False ,
83
83
):
@@ -88,6 +88,7 @@ def __init__(
88
88
else :
89
89
self .tmpdir = None
90
90
self .working_folder = Path (working_folder )
91
+ self .analyzer_path = None
91
92
if initialize :
92
93
copytree (
93
94
Path (__file__ ).parent / "analyzers" , self .working_folder / "analyzers"
@@ -106,18 +107,29 @@ def __init__(
106
107
107
108
def analyze (self , text : str , analyzer_name : str ) -> Results :
108
109
"""Analyze text with the named analyzer."""
109
- self . analyzer_name = analyzer_name
110
+ analyzer_name = Path ( analyzer_name )
110
111
outdir = self .working_folder / "analyzers" / analyzer_name / "output"
111
- outtext = self .engine .analyze (analyzer_name , text )
112
+ if self .analyzer_path :
113
+ analyzer_name = Path (self .analyzer_path ) / analyzer_name
114
+ outdir = Path (self .analyzer_path ) / "analyzers" / analyzer_name / "output"
115
+ outtext = self .engine .analyze (str (analyzer_name ), text )
112
116
return Results (outtext , outdir )
113
117
114
118
def input_text (self , analyzer_name : str , file_name : str ) -> str :
115
119
"""Return the text from a file in the input directory."""
116
- file_path : str = self .working_folder / "analyzers" / analyzer_name / "input" / file_name
120
+ file_path = Path (self .analyzer_path ) / analyzer_name / "input" / file_name
121
+ if not file_path .is_file ():
122
+ raise EngineException (
123
+ f"File not found in input directory '{ file_path } '"
124
+ )
117
125
with open (file_path , "rt" , encoding = "utf-8" ) as file :
118
126
text = file .read ()
119
127
return text
120
128
129
+ def set_analyzers_folder (self , analyzer_name : str ):
130
+ """Set analyzers directory path."""
131
+ self .analyzer_path = analyzer_name
132
+
121
133
122
134
engine = Engine ()
123
135
@@ -138,6 +150,11 @@ def set_working_folder(working_folder: Optional[str] = None, initialize: bool =
138
150
engine = Engine (Path (working_folder ), initialize = initialize )
139
151
140
152
153
+ def set_analyzers_folder (analyzer_folder_path : str ):
154
+ """Run the analyzer named on the input string."""
155
+ engine .set_analyzers_folder (analyzer_folder_path )
156
+
157
+
141
158
def analyze (str : str , parser : str = "parse-en-us" ):
142
159
"""Run the analyzer named on the input string."""
143
160
return engine .analyze (str , parser ).output_text
0 commit comments