Exemplo n.º 1
0
 def __init__(self, label, location=None):
     self.label = label
     if not location:
         if isinstance(label, str):
             location = StandardTerminology.standardize_location(label)
         elif isinstance(label, (int, float)):
             location = depth_to_location(label)
         else:
             raise ValueError(
                 f'Unrecognized location designation: {label}; expected str, int, or float'
             )
     if isinstance(location, str):
         self.location = (location, )
     else:
         self.location = tuple(location)
Exemplo n.º 2
0
 def parse_finding(cls, s, prev_locations=None, source=None):
     key = None
     value = None
     if '-' in s:
         key, value = s.lower().split('-', maxsplit=1)
     if '—' in s:
         key, value = s.lower().split('—', maxsplit=1)
     elif ':' in s:
         key, value = s.lower().split(':', maxsplit=1)
     if not key or len(key) > 40:
         key = None
         value = s.lower()
     f = cls(source=source)
     # in size pattern
     value = f.extract_size(patterns.IN_SIZE_PATTERN, value)
     # look for location as an "at 10cm" expression
     value = f.extract_depth(patterns.AT_DEPTH_PATTERN, value)
     if not f.size:
         value = f.extract_size(patterns.SIZE_PATTERN, value)
     if not f.locations:
         # without at, require 2 digits and "CM"
         value = f.extract_depth(patterns.CM_DEPTH_PATTERN, value)
     # spelled-out locations
     for location in StandardTerminology.LOCATIONS:
         loc_pat = re.compile(fr'\b{location}\b', re.IGNORECASE)
         if key and loc_pat.search(key):
             f._locations.append(location)
         elif not key and loc_pat.search(value):
             logger.warning(
                 f'Possible unrecognized finding separator in "{s}"')
             f._locations.append(location)
     # update locations if none found
     if prev_locations and not f._locations:
         f._locations = prev_locations
     else:
         f._locations = StandardTerminology.standardize_locations(
             f._locations)
     # there should only be one
     f._count = max(
         NumberConvert.contains(
             value, ['polyp', 'polyps'], 3, split_on_non_word=True) + [0])
     f.removal = 'remove' in value or 'retriev' in value or 'biopsi' in value
     if not f._count and f.removal:
         f._count = 1
     return f
Exemplo n.º 3
0
 def locations_or_none(self):
     if self.locations:
         yield from StandardTerminology.filter_colon(self.locations)
     else:
         yield None
Exemplo n.º 4
0
 def add_histology(self, histology):
     self.histologies.append(StandardTerminology.histology(histology))
Exemplo n.º 5
0
 def add_locations(self, locations):
     self.locations += StandardTerminology.standardize_locations(locations)
Exemplo n.º 6
0
 def maybe_colon(self):
     return bool(set(StandardTerminology.filter_colon(self.locations)))
Exemplo n.º 7
0
 def is_colon(self):
     return len(set(self.locations)) == len(
         set(StandardTerminology.filter_colon(self.locations)))
Exemplo n.º 8
0
 def add_location(self, location):
     loc = StandardTerminology.standardize_location(location)
     self._locations.append(loc)
Exemplo n.º 9
0
 def add_locations(self, *locations):
     self._locations.extend(
         StandardTerminology.standardize_locations(locations))