Diff of /example/uts/uts.py [000000] .. [ca4dac]

Switch to unified view

a b/example/uts/uts.py
1
#!/usr/bin/env python
2
3
"""Demonstrates access to UMLS via UTS.
4
5
"""
6
__author__ = 'Paul Landes'
7
8
from typing import Dict, List
9
from dataclasses import dataclass, field
10
from pprint import pprint
11
from zensols.cli import CliHarness ; CliHarness.add_sys_path('src/python')
12
from zensols.cli import ProgramNameConfigurator
13
from zensols.mednlp import UTSClient
14
15
16
# the definition of the application class executed from the CLI glue code
17
@dataclass
18
class Application(object):
19
    """Demonstrates access to UTS.
20
21
    """
22
    # tell the application not mistake the `uts_client` as an option when
23
    # generating the online help with the -h option
24
    CLI_META = {'option_excludes': {'uts_client'}}
25
26
    uts_client: UTSClient = field()
27
    """Queries UMLS data."""
28
29
    def lookup(self, term: str = 'heart'):
30
        """Look up a term, then return the entry based on the CUI of the first found
31
        term.
32
33
        :param term: the term to search on
34
35
        """
36
        # terms are returned as a list of pages with dictionaries of data
37
        pages: List[Dict[str, str]] = self.uts_client.search_term(term)
38
        # get all term dictionaries from the first page
39
        terms: Dict[str, str] = pages[0]
40
        # get the concept unique identifier
41
        cui: str = terms['ui']
42
43
        # print atoms of this concept
44
        print('atoms:')
45
        pprint(self.uts_client.get_atoms(cui))
46
47
        # print all relationships from the concept to all others in the
48
        # ontology
49
        print('a few relations:')
50
        pprint(self.uts_client.get_relations(cui)[:2])
51
52
53
if (__name__ == '__main__'):
54
    CliHarness(
55
        app_config_resource='uts.conf',
56
        app_config_context=ProgramNameConfigurator(
57
            None, default='uts').create_section(),
58
        proto_args='',
59
    ).run()