MCPcopy Create free account
hub / github.com/ScienciaLAB/document-qa / NERClientGeneric

Class NERClientGeneric

document_qa/ner_client_generic.py:204–380  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

202
203
204class NERClientGeneric(ApiClient):
205 def __init__(self, config_path=None, ping=False):
206 self.config = None
207 if config_path is not None:
208 self.config = self._load_yaml_config_from_file(path=config_path)
209 super().__init__(self.config["grobid"]["server"])
210
211 if ping:
212 result = self.ping_service()
213 if not result:
214 raise Exception("Grobid is down.")
215
216 os.environ["NO_PROXY"] = "nims.go.jp"
217
218 @staticmethod
219 def _load_json_config_from_file(path="./config.json"):
220 """
221 Load the json configuration
222 """
223 config = {}
224 with open(path, "r") as fp:
225 config = json.load(fp)
226
227 return config
228
229 @staticmethod
230 def _load_yaml_config_from_file(path="./config.yaml"):
231 """
232 Load the YAML configuration
233 """
234 config = {}
235 try:
236 with open(path, "r") as the_file:
237 raw_configuration = the_file.read()
238
239 config = yaml.safe_load(raw_configuration)
240 except Exception as e:
241 print("Configuration could not be loaded: ", str(e))
242 exit(1)
243
244 return config
245
246 def set_config(self, config, ping=False):
247 self.config = config
248 if ping:
249 try:
250 result = self.ping_service()
251 if not result:
252 raise Exception("Grobid is down.")
253 except Exception as e:
254 raise Exception("Grobid is down or other problems were encountered. ", e)
255
256 def ping_service(self):
257 # test if the server is up and running...
258 ping_url = self.get_url("ping")
259
260 r = requests.get(ping_url)
261 status = r.status_code

Callers 1

init_nerFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected