Exemplo n.º 1
0
    def get_person_data(self):
        while True:
            response = requests.request(
                "GET", base_url + odm_people + "name=" + self.first_name +
                " " + self.last_name + "&user_key=" + user_key)
            if response.status_code != 401:  # Workaround: sometimes '401 - Unauthorized user_key'
                break

        response_json = json.loads(response.text)
        person_list = response_json["data"]["items"]

        for person in person_list:
            person = person["properties"]
            f_name = HumanName(
                person["first_name"] + " " + person["last_name"]
            ).first  # CB stores titles in the first_name field *sigh*
            if (self.first_name == f_name) & (self.last_name
                                              == person["last_name"]):
                if (utils.sim(self.organization, person["organization_name"],
                              2 / 3)
                        | utils.sim(self.organization, person["title"],
                                    2 / 3)):  # title = job
                    return person

        return dict()
Exemplo n.º 2
0
    def __call__(self, x, x_src, cg_edge_index, batch_src):
        """
        No edge_attr and no u on this one.

        Arguments :

            - x (node feature tensor, size [X, f_x]) : node features of the
                current graph
            - x_src (node feature tensor, size [X, f_x]) : node features of the
                other graph
            - cg_edge_index (edge index tensor, size [2, E]) : cross-graph edge
                index tensor, mapping nodes of the other graph (source) to the 
                current graph (dest)
            - batch (batch tensor, size [X]) : batch tensor mapping the nodes
                of the other graph to their respective graph in the batch.

        Returns :
            - attentions (size [X], node size of the other graph.)
        """
        src, dest = cg_edge_index
        # exp-cosine-similarity vector
        ecs = torch.exp(sim(x_src[src], x[dest]))
        # attentions
        a = ecs / (scatter_add(ecs, batch_src[src])[batch_src[src]])
        vec = x[dest] - x_src[src]  # to be multiplied by attentions
        mu = (a * vec.T)
        return scatter_add(mu,
                           dest).T  # see if we don't need mean instead here
Exemplo n.º 3
0
def create_f(a, b):
    f = np.zeros((len(a), len(b)))
    for j in xrange(len(b)):
        f[0, j] = d * j
    for i in xrange(len(a)):
        f[i, 0] = d * i
    for i in xrange(1, len(a)):
        for j in xrange(1, len(b)):
            match = f[i-1, j-1] + sim(a[i], b[j])
            delete = f[i-1, j] + d
            insert = f[i, j-1] + d
            f[i, j] = max(match, delete, insert)
    return f
Exemplo n.º 4
0
def get_contact_by_name(first_name, last_name, organization_name):
    ''' Get contact_ids matching first name '''
    rows = get(
        "contacts_values", "contact_id",
        "field_name = '{}' AND value = '{}'".format('first_name', first_name))
    if not rows:
        return tuple([None] * 4)  # Contact not in database

    first_name_contact_id_list = list(map(lambda x: x[0], rows))
    ''' Get contact_ids matching last name '''
    rows = get(
        "contacts_values", "contact_id",
        "field_name = '{}' AND value = '{}'".format('last_name', last_name))
    if not rows:
        return tuple([None] * 4)

    last_name_contact_id_list = list(map(lambda x: x[0], rows))
    name_contact_id_list = set(first_name_contact_id_list).intersection(
        last_name_contact_id_list)
    ''' Match the remaining contacts' organization field to get a contact-ID'''
    contact_id = None
    if len(name_contact_id_list) == 1:
        contact_id = list(name_contact_id_list)[0]
    for tmp_contact_id in name_contact_id_list:
        rows = get(
            "contacts_values", "value",
            "contact_id = '{}' AND field_name = '{}'".format(
                tmp_contact_id, 'orga_name'))
        if rows:
            if utils.sim(rows[0][0], organization_name, 2 / 3):
                contact_id = tmp_contact_id
                break

    if not contact_id:
        return tuple([None] * 4)

    # retrieve data from contacts table
    rows = get("contacts", "last_sync, sync_interval",
               "contact_id = '{}'".format(contact_id))
    if not rows:
        return tuple([None] * 4)
    contact_last_sync = rows[0][0]
    contact_sync_interval = rows[0][1]

    # retrieve all fields in contacts_values tables
    contact_data = get_contact_values("contacts_values",
                                      "contact_id = '{}'".format(contact_id))

    return contact_id, contact_data, contact_last_sync, contact_sync_interval
Exemplo n.º 5
0
def align(a, b):
    f = create_f(a, b)
    al_a = ''
    al_b = ''
    i = len(a) - 1
    j = len(b) - 1
    while i > 0 or j > 0:
        sim_val = sim(a[i], b[j])
        if i > 0 and j > 0 and f[i, j] == f[i-1, j-1] + sim_val:
            al_a = a[i] + al_a
            al_b = b[j] + al_b
            i -= 1
            j -= 1
        elif i > 0 and f[i, j] == f[i-1, j] + d:
            al_a = a[i] + al_a
            al_b = GAP + al_b
            i -= 1
        else:
            al_a = GAP + al_a
            al_b = b[j] + al_b
            j -= 1
    return al_a, al_b