Beispiel #1
0
 def test_nickname(self):
     name = 'Robert "Evan" Liebowitz'
     assert_true(who.match(name, 'Evan Liebowitz'))
     assert_true(who.match('Evan Liebowitz', name))
     assert_false(who.match(name, 'Wrongbert Lieobwitz'))
     assert_false(who.match(name, 'Robert Evan'))
     assert_false(who.match(name, 'Evan Liebowitz',
                            options={'check_nickname': False}))
Beispiel #2
0
 def test_suffixes(self):
     name = 'Robert Liebowitz Jr'
     assert_true(who.match(name, 'Robert Liebowitz'))
     assert_true(who.match(name, 'Robert Liebowitz Jr'))
     assert_true(who.match(name, 'Robert Liebowitz, PhD'))
     assert_false(who.match(name, 'Robert Liebowitz, Sr'))
     assert_false(who.match(name, 'Robert Liebowitz, Sr, PhD'))
     assert_true(who.match(name, 'Robert Liebowitz, Jr, PhD'))
Beispiel #3
0
def find_gaps(parkings, people_off):
    matches = []
    for parking in parkings:
        for person in people_off:
            if person['type'] == 'holiday':
                continue
            if who.match(parking['name'], person['name']):
                matches.append({
                    'name': person['name'],
                    'bay': parking['bay'],
                    'date_from': date_parser.parse(person['start']),
                    'date_to': date_parser.parse(person['end'])
                })

    return matches
Beispiel #4
0
def is_british(name):
    '''Returns whether a speaker is likely to be an MEP from the United Kingdom'''
    for possible_name in en_meps:
        if who.match(name, possible_name):
            return True
    return False
Beispiel #5
0
 def test_titles(self):
     name = 'Mr. Robert Liebowitz'
     assert_true(who.match(name, 'Robert Liebowitz'))
     assert_true(who.match(name, 'Sir Robert Liebowitz'))
     assert_true(who.match(name, 'Dr. Robert Liebowitz'))
     assert_false(who.match(name, 'Mrs. Robert Liebowitz'))
Beispiel #6
0
 def test_equivalent_suffixes(self):
     name = 'Robert Liebowitz Jr'
     assert_true(who.match(name, 'Robert Liebowitz Jnr'))
     assert_false(who.match(name, 'Robert Liebowitz Snr'))
Beispiel #7
0
 def test_short_names(self):
     assert_true(who.match(self.name, 'Rob Liebowitz'))
     # TODO: Should these be true?
     assert_false(who.match(self.name, 'Bert Liebowitz'))
     assert_false(who.match(self.name, 'Robbie Liebowitz'))
Beispiel #8
0
 def test_different_initials(self):
     assert_false(who.match(self.name, 'E. R. Liebowitz'))
     assert_false(who.match(self.name, 'E. Liebowitz'))
     assert_false(who.match(self.name, 'R. V. Liebowitz'))
     assert_false(who.match(self.name, 'O. E. Liebowitz'))
Beispiel #9
0
 def test_different_number_initials(self):
     assert_true(who.match(self.name, 'Robert Liebowitz'))
     assert_true(who.match(self.name, 'R. Liebowitz'))
     assert_false(who.match(self.name, 'Robert E. E. Liebowitz'))
     assert_false(who.match(self.name, 'R. E. E. Liebowitz'))
     assert_true(who.match('R.E.E. Liebowitz', 'R. E. E. Liebowitz'))
Beispiel #10
0
 def test_name_and_initials(self):
     assert_true(who.match(self.name, 'R. Evan Liebowitz'))
     assert_true(who.match(self.name, 'Robert E. Liebowitz'))
     assert_true(who.match(self.name, 'R. E. Liebowitz'))
Beispiel #11
0
 def test_unicode(self):
     name = self.name
     assert_true(who.match(name, 'attaché Robert Evan Liebowitz'))
     assert_true(who.match(name, 'Rōbért Èvān Lîęböwitz'))
     assert_false(who.match(name, 'Rōbért Èvān Lęîböwitz'))
Beispiel #12
0
 def test_string(self):
     # Only relevant for python 2.X
     assert_true(who.match(self.name, str('Robert Liebowitz')))
Beispiel #13
0
    def run(self):
        while self.input_queue.empty() == False:
            try:
                ceo_row = self.input_queue.get()
                ceo_year = ceo_row[1]
                ceo_id = ceo_row[2]
                ceo_name = ceo_row[4]
                ceo_company = ceo_row[7]
                ceo_company_name_first_word = (ceo_company.split())[0]

                ceo_name = ceo_name.replace("\'", "\'\'")
                ceo_company = ceo_company.replace("\'", "\'\'")

                #Find the possible company name of the CEO
                sql = 'SELECT cname, namefmac, compustatname, Acronym, year, exec_fullname from Company WHERE (cname = \"' + ceo_company + '\" OR namefmac = \"' + ceo_company + '\" OR compustatname = \"' + ceo_company + '\" OR Acronym = \"' + ceo_company + '\") AND (year=' + ceo_year + ');'
                #print(sql)

                self.cursor.execute(sql)
                results = self.cursor.fetchall()

                if (len(results) > 0):
                    print(
                        "Worker %d: in progress matching company,    length: %s"
                        % (self.id, len(results)))

                for row in results:
                    cname1 = row[0] if row[0] else "Condition never match"
                    cname2 = row[1] if row[1] else "Condition never match"
                    cname3 = row[2] if row[2] else "Condition never match"
                    cname4 = row[3] if row[3] else "Condition never match"
                    ceo_name = row[5]

                    cname1 = cname1.replace("\'", "\'\'")
                    cname2 = cname2.replace("\'", "\'\'")
                    cname3 = cname3.replace("\'", "\'\'")
                    cname4 = cname4.replace("\'", "\'\'")

                    cname_year1 = row[4]
                    cname_year2 = cname_year1 - 1

                    sql = 'SELECT Contrib from Donation WHERE Cycle in (' + str(
                        cname_year1
                    ) + ',' + str(
                        cname_year2
                    ) + ') AND ((Orgname in (\'' + cname1 + '\',\'' + cname2 + '\',\'' + cname3 + '\',\'' + cname4 + '\')) OR (Orgname LIKE \'' + ceo_company_name_first_word + ' %\')) AND Orgname <> \'\''

                    self.cursor.execute(sql)
                    donation_results = self.cursor.fetchall()
                    if (len(donation_results) > 0):
                        print(
                            "Worker %d: in progress finding donation,   job id: %d  CEO:  %d    Donation:  %d   Current: %d"
                            %
                            (self.id, self.input_queue.qsize(), len(results),
                             len(donation_results), self.output_queue.qsize()))
                    else:
                        print(
                            "Worker %d: in progress finding donation,   job id: %d  CEO:  %d    Current: %d"
                            % (self.id, self.input_queue.qsize(), len(results),
                               self.output_queue.qsize()))

                    for donation_result in donation_results:
                        donation_donor_name = donation_result[0]
                        donation_donor_name_in_sql_format = donation_donor_name.replace(
                            "\'", "\'\'")
                        if (who.match(ceo_name, donation_donor_name)):
                            sql = 'SELECT * from Donation WHERE Contrib = \"' + donation_donor_name_in_sql_format + '\";'
                            self.cursor.execute(sql)
                            name_matched_donation_results = self.cursor.fetchall(
                            )

                            if (len(name_matched_donation_results) > 0):
                                print(
                                    "Worker %d: in progress matching name,    length: %s"
                                    % (self.id,
                                       len(name_matched_donation_results)))

                            for name_matched_donation_result in name_matched_donation_results:
                                output_row = [
                                    ceo_id
                                ] + list(name_matched_donation_result)
                                self.output_queue.put(output_row)
            except Exception:
                traceback.print_exc()
            finally:
                # 處理資料
                print("Worker %d: %s" % (self.id, self.input_queue.qsize()))
        print("Worker %d  End" % (self.id))
def main():

    # 建立佇列
    my_queue = queue.Queue()

    # 將資料放入佇列
    with open('Ceo.csv', newline='') as csvfile:

        # 讀取 CSV 檔案內容
        rows = csv.reader(csvfile)
        next(rows, None)

        # 以迴圈輸出每一列
        for row in rows:
            my_queue.put(row)

    db = pymysql.connect("127.0.0.1", "wai", "123", "mm", charset='utf8')
    cursor = db.cursor()

    i = 0
    found = 0
    try:
        output_rows = []
        while not my_queue.empty():
            i += 1
            ceo_row = my_queue.get()
            ceo_year = ceo_row[1]
            ceo_id = ceo_row[2]
            ceo_name = ceo_row[4]
            ceo_company = ceo_row[7]
            ceo_company_name_first_word = (ceo_company.split())[0]

            ceo_name = ceo_name.replace("\'", "\'\'")
            ceo_company = ceo_company.replace("\'", "\'\'")

            #Find the possible company name of the CEO
            sql = 'SELECT cname, namefmac, compustatname, Acronym, year, exec_fullname from Company WHERE (cname = \"' + ceo_company + '\" OR namefmac = \"' + ceo_company + '\" OR compustatname = \"' + ceo_company + '\" OR Acronym = \"' + ceo_company + '\") AND (year=' + ceo_year + ');'
            #print(sql)

            cursor.execute(sql)
            results = cursor.fetchall()

            if (i % 1 == 0):
                print(i)

            for row in results:
                cname1 = row[0]
                cname2 = row[1]
                cname3 = row[2]
                cname4 = row[3]
                ceo_name = row[5]

                cname1 = cname1.replace("\'", "\'\'")
                cname2 = cname2.replace("\'", "\'\'")
                cname3 = cname3.replace("\'", "\'\'")
                cname4 = cname4.replace("\'", "\'\'")

                cname_year1 = row[4]
                cname_year2 = cname_year1 - 1

                sql = 'SELECT * from Donation WHERE Cycle in (' + str(
                    cname_year1
                ) + ',' + str(
                    cname_year2
                ) + ') AND (Orgname in (\'' + cname1 + '\',\'' + cname2 + '\',\'' + cname3 + '\',\'' + cname4 + '\') OR (Orgname LIKE \"' + ceo_company_name_first_word + '%\")) AND Orgname <> \'\''

                cursor.execute(sql)
                donation_results = cursor.fetchall()

                for donation_result in donation_results:
                    donation_donor_name = donation_result[3]
                    donation_donor_name = donation_donor_name.replace(
                        "\'", "\'\'")
                    if (who.match(ceo_name, donation_donor_name)):
                        sql = 'SELECT * from Donation WHERE RecipID = \"' + donation_donor_name + '\";'
                        cursor.execute(sql)
                        name_matched_donation_results = cursor.fetchall()

                        for name_matched_donation_result in name_matched_donation_results:
                            output_row = [
                                ceo_id
                            ] + list(name_matched_donation_result)
                            output_rows.append(output_row)
                            print("current found: ", found)
                            found += 1

        print("found: ", found)

        with open('output.csv', 'w', newline='') as csvfile:
            # 建立 CSV 檔寫入器
            writer = csv.writer(csvfile)

            writer.writerow([
                'execid', 'Cycle', 'Date', 'ContribID', 'Contrib', 'RecipID',
                'Orgname', 'UltOrg', 'Occupation', 'RealCode', 'Amount',
                'State', 'Zip', 'RecipCode', 'Type', 'Gender', 'reccode1',
                'reccode2'
            ])

            for output_row in output_rows:
                writer.writerow(output_row)

    except Exception:
        print(sql)
        traceback.print_exc()
    finally:
        db.close()
    """
Beispiel #15
0
def are_same_author(author1: str, author2: str) -> bool:
    return cast(bool, who.match(author1, author2))