def create_new_virtualauthor(orig_authornames_id, orig_name_string):
    '''
    Adds a new virtualauthor to the virtualauthors table;
    Adds original author name and original name string info to the
    virtualauthors_data table

    @param orig_authornames_id: authornames id of the virtual author
    @type orig_authornames_id: int
    @param orig_name_string: name string in authornames of the virtual author
    @type orig_name_string: string

    @return: the va_id of the first found virtual authors
    @rtype: int
    '''
    current_va_id = dat.increment_tracker("va_id_counter")
    dat.VIRTUALAUTHORS.append({'virtualauthorid': current_va_id,
                               'authornamesid': orig_authornames_id,
                               'p': 1,
                               'clusterid':-1})
    add_virtualauthor_record(current_va_id, 'orig_authorname_id',
                             orig_authornames_id)
    add_virtualauthor_record(current_va_id, 'orig_name_string',
                             orig_name_string)
    update_virtualauthor_record(current_va_id, 'updated', 'True')
    add_virtualauthor_record(current_va_id, 'connected', 'False')

    return current_va_id
Ejemplo n.º 2
0
def create_new_virtualauthor(orig_authornames_id, orig_name_string):
    '''
    Adds a new virtualauthor to the virtualauthors table;
    Adds original author name and original name string info to the
    virtualauthors_data table

    @param orig_authornames_id: authornames id of the virtual author
    @type orig_authornames_id: int
    @param orig_name_string: name string in authornames of the virtual author
    @type orig_name_string: string

    @return: the va_id of the first found virtual authors
    @rtype: int
    '''
    current_va_id = dat.increment_tracker("va_id_counter")
    dat.VIRTUALAUTHORS.append({
        'virtualauthorid': current_va_id,
        'authornamesid': orig_authornames_id,
        'p': 1,
        'clusterid': -1
    })
    add_virtualauthor_record(current_va_id, 'orig_authorname_id',
                             orig_authornames_id)
    add_virtualauthor_record(current_va_id, 'orig_name_string',
                             orig_name_string)
    update_virtualauthor_record(current_va_id, 'updated', 'True')
    add_virtualauthor_record(current_va_id, 'connected', 'False')

    return current_va_id
def create_new_realauthor(va_id):
    """
    Create a new real author connected to the given virtual author; the trust
    value for the virtual author is obviously 1 because this virtual author is
    incompatible with every other real author and is the first
    one in this new real author.

    RETURNS: the newly created realauthorid
    """
    current_ra_id = dat.increment_tracker("raid_counter")
    dat.REALAUTHORS.append({"realauthorid": current_ra_id, "virtualauthorid": va_id, "p": 1})
    dat.update_log("new_ras", current_ra_id)
    update_realauthor_data_by_vid(current_ra_id, va_id)
    #    update_realauthor_names(current_ra_id)

    return current_ra_id
def create_new_realauthor(va_id):
    """
    Create a new real author connected to the given virtual author; the trust
    value for the virtual author is obviously 1 because this virtual author is
    incompatible with every other real author and is the first
    one in this new real author.

    RETURNS: the newly created realauthorid
    """
    current_ra_id = dat.increment_tracker("raid_counter")
    dat.REALAUTHORS.append({'realauthorid': current_ra_id,
                         'virtualauthorid': va_id,
                         'p': 1})
    dat.update_log("new_ras", current_ra_id)
    update_realauthor_data_by_vid(current_ra_id, va_id)
#    update_realauthor_names(current_ra_id)

    return current_ra_id
def _get_clusterids_from_name(search_string, return_matching=False):
    '''
    Returns a list of cluster IDs, which are fitting for the parameter 'name'.
    First checks if, in general, a cluster for this name exists. If not,
    create one. If there is a cluster, try to find all other fitting clusters
    and add the found cluster IDs to the list to be returned

    @param name: The name to be on the lookout for.
    @type name: string
    @param return_matching: also return the reference name's matching cluster
    @type return_matching: boolean

    @return:
        if return_matching: list of 1) list of cluster IDs 2) the cluster ID
            matching the name
        if not return_matching: list of cluster IDs
    @rtype:
        if return_matching: list of (list of int, int)
        if not return_matching: list of int
    '''
    clusterids = set()
    newly_created_cluster_id = -1
    existing_initial_cluster_id = -1

    for row in dat.VIRTUALAUTHOR_CLUSTERS:
        if row['clustername'] == search_string:
            existing_initial_cluster_id = row['clusterid']
            break

    if existing_initial_cluster_id > -1:
        clusterids.add(existing_initial_cluster_id)
    else:
        newly_created_cluster_id = dat.increment_tracker('cluster_id')
        dat.VIRTUALAUTHOR_CLUSTERS.append(
                                        {"clusterid": newly_created_cluster_id,
                                         "clustername": search_string})
        clusterids.add(newly_created_cluster_id)

    name_matching_cluster = -1

    if (newly_created_cluster_id > -1):
        name_matching_cluster = newly_created_cluster_id
    else:
        name_matching_cluster = existing_initial_cluster_id

#    The follwing snippet finds every cluster matching the name
#        and any addition
#    as well as the parents.
#    E.g.(Additions): Ellis, John will find clusters for
#        Ellis, J; Ellis, J. R. and Ellis J. E.
#    E.g.(Parents): Ellis, John R. will find clusters for
#        Ellis, J. R. and Ellis, J.

    matching_ids = [row['clusterid'] for row in dat.VIRTUALAUTHOR_CLUSTERS
               if ((row['clustername'].startswith(search_string))
                   or (search_string.startswith(row['clustername'])))]

    for matching_id in matching_ids:
        clusterids.add(matching_id)

    clusterids = list(clusterids)

    if return_matching:
        return [clusterids, name_matching_cluster]
    else:
        return clusterids
Ejemplo n.º 6
0
def _get_clusterids_from_name(search_string, return_matching=False):
    '''
    Returns a list of cluster IDs, which are fitting for the parameter 'name'.
    First checks if, in general, a cluster for this name exists. If not,
    create one. If there is a cluster, try to find all other fitting clusters
    and add the found cluster IDs to the list to be returned

    @param name: The name to be on the lookout for.
    @type name: string
    @param return_matching: also return the reference name's matching cluster
    @type return_matching: boolean

    @return:
        if return_matching: list of 1) list of cluster IDs 2) the cluster ID
            matching the name
        if not return_matching: list of cluster IDs
    @rtype:
        if return_matching: list of (list of int, int)
        if not return_matching: list of int
    '''
    clusterids = set()
    newly_created_cluster_id = -1
    existing_initial_cluster_id = -1

    for row in dat.VIRTUALAUTHOR_CLUSTERS:
        if row['clustername'] == search_string:
            existing_initial_cluster_id = row['clusterid']
            break

    if existing_initial_cluster_id > -1:
        clusterids.add(existing_initial_cluster_id)
    else:
        newly_created_cluster_id = dat.increment_tracker('cluster_id')
        dat.VIRTUALAUTHOR_CLUSTERS.append({
            "clusterid": newly_created_cluster_id,
            "clustername": search_string
        })
        clusterids.add(newly_created_cluster_id)

    name_matching_cluster = -1

    if (newly_created_cluster_id > -1):
        name_matching_cluster = newly_created_cluster_id
    else:
        name_matching_cluster = existing_initial_cluster_id


#    The follwing snippet finds every cluster matching the name
#        and any addition
#    as well as the parents.
#    E.g.(Additions): Ellis, John will find clusters for
#        Ellis, J; Ellis, J. R. and Ellis J. E.
#    E.g.(Parents): Ellis, John R. will find clusters for
#        Ellis, J. R. and Ellis, J.

    matching_ids = [
        row['clusterid'] for row in dat.VIRTUALAUTHOR_CLUSTERS
        if ((row['clustername'].startswith(search_string)) or (
            search_string.startswith(row['clustername'])))
    ]

    for matching_id in matching_ids:
        clusterids.add(matching_id)

    clusterids = list(clusterids)

    if return_matching:
        return [clusterids, name_matching_cluster]
    else:
        return clusterids