def _recognizedParenthesizedParts(self, locationValues, expectedType): for i, locationValue in enumerate(locationValues): m = PARENTHESIZED.match(locationValue) if not m is None: head = m.group(1).strip() scope = m.group(2).strip() tail = m.group(3).strip() if scope in TYPE_MARKERS: type = TYPE_MARKERS[scope] if not expectedType or indexOf(expectedType, TYPE_PRECEDENCE) > indexOf(type, TYPE_PRECEDENCE): expectedType = type scope = None locationValues[i] = ', '.join(v for v in [head, scope, tail] if v) return locationValues, expectedType
def selectPit(self, queryResults, expectedType=None): pits = None for queryResult in queryResults: qrType, qrPits = queryResult if expectedType is None or qrType == expectedType: pits = qrPits break if pits is None: return None pits = sorted( pits, key=lambda pit: ( indexOf(type(pit.get('geometry')), SHAPE_PRECEDENCE), pit.get('hasEnd', '2030-00-00'), pit.get('hasBegin', '0000-00-00'), ), reverse=True) pit = first(pits) return pit
def _resultAsJson(self, result): d = dict(result=result) return dumps(d, indent=4, use_decimal=True, item_sort_key=lambda item: (indexOf(item[0], ['request', 'total', 'items', 'nextPage', 'facets', 'sruRequest']), item[0]))