Exemplo n.º 1
0
def update_tables(old_name, new_name):
    try:
        # use our connection values to establish a connection
        conn = psycopg2.connect(host='localhost', dbname='testpaperdb', user='******', password='******',
                                port='5433')
        # create a psycopg2 cursor that can execute queries
        cursor = conn.cursor()

        try:
            device = get_specific_device(old_name, cursor)
            device = DB_Device(device)
            device.name = new_name
            device.key = modify_name(new_name)
            devices = get_devices_from_db(cursor)
            possible_connections = check_new_connections(device, devices)
            for connection in possible_connections:
                print(connection[0].name)
                print(connection[1].name)
            update_rows(old_name, new_name, cursor, possible_connections)
                # add_connections(possible_connections, device.key, cursor)
        except Exception as e:
            print(e)
            pass
        cursor.close()
        conn.commit()
    except Exception as e:
        print(e)
    finally:
        if conn is not None:
            conn.close()
Exemplo n.º 2
0
 def __init__(self, title, ref_number):
     self.ref_number = ref_number
     self.title = title
     self.key = modify_name(title)
     self.authors = []
     self.publisher = init_publisher_dict()
     self.timesCited = 1
     self.locations_cited = []
Exemplo n.º 3
0
def init_device(name, pdf):
    new_device = Device(name, pdf)
    modified_name = modify_name(name)
    count = 1
    while modified_name in devices:
        modified_name = modified_name + ' (' +str(count) + ')'
        count += 1
    devices[modified_name] = new_device

    return new_device, modified_name
Exemplo n.º 4
0
def check_new_connections(updated_device, devices):
    possible_connections = [] # list of tuples of devices that referenced this device
    for device in devices:
        device = DB_Device(device)
        for ref in device.refs:
            tol = calculate_tol(updated_device.key, modify_name(ref['title']))
            if tol > 0.75:
                device.backward_refs.append({'target': updated_device.id, 'times_cited': ref['times_cited']})
                updated_device.forward_refs.append({'target': device.id, 'times_cited': ref['times_cited']})
                possible_connections.append((device, updated_device))

    return possible_connections
Exemplo n.º 5
0
 def __init__(self, name, pdf):
     self.name = name  # also the name of the folder it's in
     self.key = modify_name(name)
     self.refs = [] # a list of reference objects
     self.ref_titles = [] # a list of reference object titles
     self.forward_refs = []
     self.backward_refs = []
     self.authors = []
     self.affiliates = []
     self.abstract = ''
     self.date = ''
     self.publisher = ''
     self.sections = {} # name + '/Sections/Section.txt'
     self.figures = {} # name + '/Figures/'
     self.pdf = pdf
Exemplo n.º 6
0
def add_backward_ref(device, ref):
    ref_name = modify_name(ref.title)
    ref_occurance = ref.timesCited
    device.backward_ref[ref_name] = ref_occurance
Exemplo n.º 7
0
def update_name(new_name, device):
    device.name = new_name
    device.key = modify_name(new_name)