# Path: safecity/apps/locate/location_parser.py
# def strip_punctuation(text):
#     return PUNCTUATION_REGEX.sub(' ', text)
# 
# WHITESPACE_REGEX = re.compile('\s+')


import csv
import logging
import os
from optparse import make_option
from django.conf import settings
from django.core.management.base import NoArgsCommand, CommandError
from safecity.apps.locate.location_parser import strip_punctuation, WHITESPACE_REGEX
from safecity.apps.locate.models import *
                canonical_alias = RoadAlias.objects.get(
                    name=canonical_name,
                    alias_type='CA'
                )
            except RoadAlias.DoesNotExist:
                log.debug('Skipping alias for "%s"--no such road.' % canonical_name)
                continue
            
            try:
                new_alias = RoadAlias.objects.get(
                    name=alias_name
                )
                
                log.debug('Skipping duplicate alias: %s (type %s). Storied type is %s.' % (alias_name, alias_type, new_alias.alias_type))
                continue
            except RoadAlias.DoesNotExist:
                new_alias = RoadAlias.objects.create(
                    name=alias_name,
                    alias_type=alias_type
                )
            
            for road in canonical_alias.roads.all():
                new_alias.roads.add(road)
                
            log.debug('Created alias %s for %s' % (alias_name, canonical_name))
            
    def format_alias_name(self, name):
        """
        Handles stripping punctuation and formatting whitespace.
        """

# Path: safecity/apps/locate/location_parser.py
# def strip_punctuation(text):
#     return PUNCTUATION_REGEX.sub(' ', text)
# 
# WHITESPACE_REGEX = re.compile('\s+')


# Path: safecity/apps/locate/management/commands/load_aliases.py
import csv
import logging
import os
from optparse import make_option
from django.conf import settings
from django.core.management.base import NoArgsCommand, CommandError
from safecity.apps.locate.location_parser import strip_punctuation, WHITESPACE_REGEX
from safecity.apps.locate.models import *

                canonical_alias = RoadAlias.objects.get(
                    name=canonical_name,
                    alias_type='CA'
                )
            except RoadAlias.DoesNotExist:
                log.debug('Skipping alias for "%s"--no such road.' % canonical_name)
                continue
            
            try:
                new_alias = RoadAlias.objects.get(
                    name=alias_name
                )
                
                log.debug('Skipping duplicate alias: %s (type %s). Storied type is %s.' % (alias_name, alias_type, new_alias.alias_type))
                continue
            except RoadAlias.DoesNotExist:
                new_alias = RoadAlias.objects.create(
                    name=alias_name,
                    alias_type=alias_type
                )
            
            for road in canonical_alias.roads.all():
                new_alias.roads.add(road)
                
            log.debug('Created alias %s for %s' % (alias_name, canonical_name))
            
    def format_alias_name(self, name):
        """
        Handles stripping punctuation and formatting whitespace.
        """

        result = strip_punctuation(name)