Exemplo n.º 1
0
def add(unknown_names):
    """ Add one or more entries to the unknown names list.

        'unknown_names' is a list of unknown names to add to the list, where
        each item in this list is a (name, context, source) tuple.  The entries
        in this tuple are as follows:

            'name'

                The name to add to the unknown names list.

            'context'

                A string identifying the context in which this name was used.
                The following context values are currently supported:

                    "unstructured"
                    "country"
                    "state"
                    "metro"
                    "region"
                    "county"
                    "city"
                    "locality"
                    "zipCode"

            'source'

                The 3taps code for the data source, or None if no data source
                was provided.
    """
    # FIXME
    context = context.lower()
    name    = encode_name(name).lower().strip()

    if name == "": return # Ignore blanks.

    lock = _get_lock()
    lock.acquire()
    try:

        try:
            unknownName = UnknownName.objects.get(context=context, name=name)
        except UnknownName.DoesNotExist:
            unknownName = None

        if unknownName != None:
            unknownName.numOccurrences = unknownName.numOccurrences + 1
        else:
            unknownName = UnknownName()
            unknownName.context        = context
            unknownName.name           = name
            unknownName.numOccurrences = 1
            unknownName.rejected       = False

        unknownName.save()
    finally:
        lock.release()
Exemplo n.º 2
0
def add(context, name):
    """ Add an entry to the list of unknown names.

        'context' is a string identifying the context in which this name was
        used, and 'name' is the name itself.  The following contexts are
        currently supported:

            "unstructured"
            "country"
            "state"
            "metro"
            "region"
            "county"
            "city"
            "locality"
            "zipCode"

        We update the "unknown name" database table to include this new entry.
        In particular, if a record already exists for this name and context, we
        update the number of occurrences.  Otherwise, we add a new entry to the
        database.

        Note that we use a Lock object to ensure that two processes don't try
        to add a name at the same time.
    """
    context = context.lower()
    name    = encode_name(name).lower().strip()

    if name == "": return # Ignore blanks.

    lock = _get_lock()
    lock.acquire()
    try:

        try:
            unknownName = UnknownName.objects.get(context=context, name=name)
        except UnknownName.DoesNotExist:
            unknownName = None

        if unknownName != None:
            unknownName.numOccurrences = unknownName.numOccurrences + 1
        else:
            unknownName = UnknownName()
            unknownName.context        = context
            unknownName.name           = name
            unknownName.numOccurrences = 1
            unknownName.rejected       = False

        unknownName.save()
    finally:
        lock.release()