示例#1
0
 def fill_stop(self, stop, node, kind):
     """Returns stop in the correct entity group"""
     stop.stop_type = kind
     stop.location = db.GeoPt(lat=node.lat, lon=node.lon)
     stop.update_location()
     stop.names = [node.name]
     gov = []
     for k,v in node.attr.items():
         if k in ['alt_name', 'nat_name', 'old_name', 'reg_name', 'loc_name', 'official_name']:
             stop.names.append(v)
         if k.startswith('name:'):
             # language specific
             stop.names.append(v)
         # adminstrative regions
         if k.startswith('is_in:country'):
             country = Country.get_or_insert(v, name=v, ascii_names=Normalize.normalize(v))
             stop.country = country
         if k.startswith('is_in:region') or k.startswith('is_in:state'):
             # find the region with the best match (but must have some similarity to tag)
             region_match = (0.6, "<no match>", "-")
             for short_name,long_name in settings.REGIONS:
                 ndiff = difflib.SequenceMatcher(None,long_name,v)
                 if ndiff.ratio() > region_match[0]:
                     region_match = (ndiff.ratio(), unicode(long_name), unicode(short_name))
             if region_match[1] != "<no match>":
                 logging.debug("Match %f for %s and %s" % region_match)
                 region = Region.get_or_insert(region_match[2],
                                               name=region_match[1],
                                               short_name=region_match[2],
                                               ascii_names = Normalize.normalize("%s %s" % (long_name, short_name)))
                 region.put()
                 stop.region = region
             else:
                 logging.warning("Unknown region, state or Bundesland: %s" % v)
         if k.startswith('is_in:city') or k.startswith('is_in:municipality'):
             comuna = Comuna.get_or_insert(v, name=v, ascii_names=Normalize.normalize(v))
             stop.comuna = comuna
     stop.ascii_names = []
     for name in stop.names:
         if name != "<no name>":
             stop.ascii_names.extend(Normalize.normalize(name))
     return stop