def _do_geocode(self, location_string): sides = intersection_re.split(location_string) if len(sides) != 2: raise ParsingError("Couldn't parse intersection: %r" % location_string) # Parse each side of the intersection to a list of possibilities. # Let the ParseError exception propagate, if it's raised. left_side = parse(sides[0]) right_side = parse(sides[1]) all_results = [] seen_intersections = set() for street_a in left_side: street_a['street'] = StreetMisspelling.objects.make_correction(street_a['street']) for street_b in right_side: street_b['street'] = StreetMisspelling.objects.make_correction(street_b['street']) for result in self._db_lookup(street_a, street_b): if result["intersection_id"] not in seen_intersections: seen_intersections.add(result["intersection_id"]) all_results.append(result) if not all_results: raise DoesNotExist("Geocoder db couldn't find this intersection: %r" % location_string) elif len(all_results) == 1: return all_results.pop() else: raise AmbiguousResult(list(all_results), "Intersections DB returned %s results" % len(all_results))
def _do_geocode(self, location_string): sides = intersection_re.split(location_string) if len(sides) != 2: raise ParsingError("Couldn't parse intersection: %r" % location_string) # Parse each side of the intersection to a list of possibilities. # Let the ParseError exception propagate, if it's raised. left_side = parse(sides[0]) right_side = parse(sides[1]) all_results = [] seen_intersections = set() for street_a in left_side: street_a['street'] = StreetMisspelling.objects.make_correction( street_a['street']) for street_b in right_side: street_b['street'] = StreetMisspelling.objects.make_correction( street_b['street']) for result in self._db_lookup(street_a, street_b): if result["intersection_id"] not in seen_intersections: seen_intersections.add(result["intersection_id"]) all_results.append(result) if not all_results: raise DoesNotExist( "Geocoder db couldn't find this intersection: %r" % location_string) elif len(all_results) == 1: return all_results.pop() else: raise AmbiguousResult( list(all_results), "Intersections DB returned %s results" % len(all_results))
def assertParseContains(self, location, contains): # Because the parser is overly greedy and gives many possible # responses, it keeps the unit tests tidier and less brittle if we # just list one important parse result that we expect, rather than # listing every single test result. try: actual = [dict(result) for result in parse(location)] except ParsingError, e: self.fail(e)
def assertParseContains(self, location, contains): # Because the parser is overly greedy and gives many possible # responses, it keeps the unit tests tidier and less brittle if we # just list one important parse result that we expect, rather than # listing every single test result. try: actual = [dict(result) for result in parse(location)] except ParsingError, e: self.fail(e)
def _do_geocode(self, location_string): # Parse the address. try: locations = parse(location_string) except ParsingError, e: raise
def _do_geocode(self, location_string): # Parse the address. try: locations = parse(location_string) except ParsingError, e: raise