[ca4dac]: / example / ctakes / ctakes.py

Download this file

52 lines (39 with data), 1.6 kB

 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python
"""Demonstrates access to UMLS via CTAKES.
"""
__author__ = 'Paul Landes'
from dataclasses import dataclass, field
from pathlib import Path
import pandas as pd
from zensols.cli import CliHarness, ProgramNameConfigurator
from zensols.mednlp.ctakes import CTakesParserStash
# the definition of the application class executed from the CLI glue code
@dataclass
class Application(object):
"""Demonstrates how to use the cTAKES application wrapper.
"""
# tell the application not mistake the `uts_client` as an option when
# generating the online help with the -h option
CLI_META = {'option_excludes': {'ctakes_stash'}}
ctakes_stash: CTakesParserStash = field()
"""Runs the cTAKES CUI entity linker on a directory of medical notes."""
def entities(self, sent: str = None, output: Path = None):
"""Parse a sentence and print cTAKES entities.
:param sent: the sentence to parse and generate features
"""
if sent is None:
sent = 'He was diagnosed with kidney failure in the United States.'
self.ctakes_stash.set_documents([sent])
df: pd.DataFrame = self.ctakes_stash['0']
print(df)
if output is not None:
df.to_csv(output)
print(f'wrote: {output}')
if (__name__ == '__main__'):
CliHarness(
app_config_resource='ctakes.conf',
app_config_context=ProgramNameConfigurator(
None, default='ctakes').create_section(),
proto_args='',
proto_factory_kwargs={'reload_pattern': '^ctakes'},
).run()