Example #1
0
    def set_parsed_name(self):
        if not self.name:
            self.parsed_name = None
            return

        name = HumanName(self.name)
        self.parsed_name = name.as_dict()
Example #2
0
    def set_parsed_name(self):
        if not self.name:
            self.parsed_name = None
            return

        name = HumanName(self.name)
        self.parsed_name = name.as_dict()
Example #3
0
def transform(row):
    """
    transforms the raw row into a row that looks like the congress legislators data
    """
    parsed_name = HumanName(row['name'])
    return {
        'id': {
            'nga': row['url']
        },
        'name': {
            'original': row['name'],
            'full': str(parsed_name),
            **parsed_name.as_dict(include_empty=False),
        },
        'bio': {
            'birthday': row['birthday']
        },
        'terms': [
            {
                'type': 'gov',
                'start': term['start'],
                'end': term['end'],
                'party': row['party'],
                'state': row['state'],
            }
            for term in row['terms']
        ]
    }
Example #4
0
def parse(name):
  try:
    parsed_name = HumanName(name)
    parsed_name.capitalize(force=True)

    return jsonify(parsed_name.as_dict())
  except Exception as e:
    return jsonify(str(e))
Example #5
0
def parse_row(row: str, record: dict, county: str):
    entry = row.split(':')
    if entry[0].strip() == 'Name':
        entry.pop(0)
        n = HumanName(':'.join(entry).strip())
        name = n.as_dict()
        name['original'] = n.original
        record['name'] = name
    if entry[0].strip() == 'Social Security Number':
        entry.pop(0)
        record['ssn'] = ':'.join(entry)
    if entry[0].strip() == 'Birth Date':
        entry.pop(0)
        d = dateparser.parse(':'.join(entry).strip())
        date = {
            'day': d.day,
            'month': d.month,
            'year': d.year,
            'original': ':'.join(entry).strip()
        }
        record['birth_date'] = date
    if entry[0].strip() == 'Issue Year':
        entry.pop(0)
        record['issue_year'] = ':'.join(entry).strip()
    if entry[0].strip() == 'Issue State':
        entry.pop(0)
        record['issue_state'] = ':'.join(entry).strip()
    if entry[0].strip() == 'Last Residence':
        entry.pop(0)
        original = ':'.join(entry).strip()
        parts = original.split(', ')

        try:
            int(parts[0])
            zip = str(parts[0])
        except Exception:
            zip = False

        addr = {'zip': zip, 'original': original, 'county': county}

        record['last_residence'] = addr
    if entry[0].strip() == 'Death Date':
        entry.pop(0)
        d = dateparser.parse(':'.join(entry).strip())
        date = {
            'day': d.day,
            'month': d.month,
            'year': d.year,
            'original': ':'.join(entry).strip()
        }
        record['death_date'] = date

    return record
    def run_variations(self, name):
        """ Run several variations

        This is a separate function so that individual non-parametrized tests can be
        added if desired.
        """
        hn = HumanName(name)
        if len(hn.suffix_list) > 1:
            hn = HumanName("{title} {first} {middle} {last} {suffix}".format(
                **hn.as_dict()).split(",")[0])
        # format strings below require empty string
        hn.C.empty_attribute_default = ""
        hn_dict = hn.as_dict()
        nocomma = HumanName(
            "{title} {first} {middle} {last} {suffix}".format(**hn_dict))
        lastnamecomma = HumanName(
            "{last}, {title} {first} {middle} {suffix}".format(**hn_dict))
        if hn.suffix:
            suffixcomma = HumanName(
                "{title} {first} {middle} {last}, {suffix}".format(**hn_dict))
        if hn.nickname:
            nocomma = HumanName(
                "{title} {first} {middle} {last} {suffix} ({nickname})".format(
                    **hn_dict))
            lastnamecomma = HumanName(
                "{last}, {title} {first} {middle} {suffix} ({nickname})".
                format(**hn_dict))
            if hn.suffix:
                suffixcomma = HumanName(
                    "{title} {first} {middle} {last}, {suffix} ({nickname})".
                    format(**hn_dict))
        for attr in hn._members:
            assert getattr(hn, attr) == getattr(nocomma, attr)
            assert getattr(hn, attr) == getattr(lastnamecomma, attr)
            if hn.suffix:
                assert getattr(hn, attr) == getattr(suffixcomma, attr)
Example #7
0
def show_representatives():
    form = AddressLookup()
    if form.validate_on_submit():
        session['address'] = form.address.data
        return redirect(url_for('main.show_representatives'))

    address = session.get('address')
    form.address.data = address
    representatives = {}
    if address:
        representatives =\
            get_representativeinfo(session.get('address'),
                                   current_app.config['ELECTION_API_KEY'])
        for representative in representatives['officials']:
            human_name = HumanName(representative['name'])
            logging.debug(human_name.as_dict())
            representative['first_name'] = human_name.first
            representative['last_name'] = human_name.last
    return render_template('show_representativeinfo.html',
                           representatives=representatives,
                           lookupform=form)
Example #8
0
def show_representatives():
    form = AddressLookup()
    if form.validate_on_submit():
        session['address'] = form.address.data
        return redirect(url_for('main.show_representatives'))

    address = session.get('address')
    form.address.data = address
    representatives = {}
    if address:
        representatives =\
            get_representativeinfo(session.get('address'),
                                   current_app.config['ELECTION_API_KEY'])
        for representative in representatives['officials']:
            human_name = HumanName(representative['name'])
            logging.debug(human_name.as_dict())
            representative['first_name'] = human_name.first
            representative['last_name'] = human_name.last
    return render_template('show_representativeinfo.html',
                           representatives=representatives,
                           lookupform=form)
Example #9
0
def process_results(items: list, location: dict, death_year: int, birth_year: int, ua: str, proxies: dict):
    results = read_results(location['state'], location['county'], location['zip_code'], death_year, birth_year)
    for item in items:
        name = item['record']['name']
        n = HumanName(name)
        name = n.as_dict()
        name['original'] = n.original
        birth = {}
        death = {}
        for field in item['record']['display_fields']:
            if field['name'] == 'birth':
                b = dateparser.parse(field['value'])
                birth = {
                    'day': b.day,
                    'month': b.month,
                    'year': b.year,
                    'original': field['value']
                }
            if field['name'] == 'death':
                d = dateparser.parse(field['value'])
                death = {
                    'day': d.day,
                    'month': d.month,
                    'year': d.year,
                    'original': field['value']
                }
        person = {
            'name': name,
            'location': location,
            'birth': birth,
            'death': death
        }
        results.append(person)

        if location['state'] == 'MI':
            michigan.hunt_mi_zombie(person, ua, proxies)

    save_results(results, location['state'], location['county'], location['zip_code'], death_year, birth_year)
Example #10
0
def parse_name(name):
    parsed = HumanName(name)
    capitalize = request.args.get("capitalize", False)
    if capitalize and capitalize == "true":
        parsed.capitalize()
    return jsonify(parsed.as_dict())
#!/usr/bin/python
# -*- coding: utf-8 -*-

from nameparser import HumanName
name = HumanName("Dr. Juan Q. Xavier de la Vega III (Doc Vega)")
#name
print(name.last)
print(name.as_dict())
print(str(name))
name.string_format = "{first} {last}"
print(str(name))
Example #12
0
def catch_all(path):
    name = request.args.get('name')

    parsedName = HumanName(name)

    return jsonify(parsedName.as_dict())
 def process_row(self, row):
     new_row = row.copy()
     hn = HumanName(row[self.fieldname])
     new_data = {'parsed_{}'.format(k): v for k, v in hn.as_dict().items()}
     new_row.update(new_data)
     return new_row
Example #14
0
    print(name_org)

    #keep the original metaphone
    metaphone_name_org = jf.metaphone(name_org)
    metaphone_name_org_set = metaphone_name_org.split(' ')

    #generate list of dict
    temp_words, lev1_des_set = edits1(name_org)

    set_pos = 0
    #keep the original keys
    org_keys = []

    #the original sequence
    name_org_json = HumanName(name_org)
    name_org_dict_org = name_org_json.as_dict()
    keys_org = name_org_dict_org.keys()
    name_org_dict = {}

    #keep all the variations of the same name_org
    name_dict_population = {}

    #cleansed the dict
    for key in keys_org:
        if len(name_org_dict_org[key].strip()) > 0:
            name_org_dict[key] = name_org_dict_org[key]
    name_org_keys = list(name_org_dict.keys())

    for name in temp_words:
        name_n_list = []
        des_n_list = []
Example #15
0
 def post(self, request, format=None):
     name = HumanName(str(request.data['name']))
     request.data['response'] = name.as_dict()
     return Response(request.data, status=status.HTTP_201_CREATED)
def index(name):
    try:
        return_name = HumanName(name)
        return jsonify(return_name.as_dict())
    except Exception as e:
        return jsonify(str(e))
Example #17
0
csv_writer.writeheader()
#read the extracted author-names from the clean data and convert data from list to string
with open("extracted_advisor.csv", 'r', encoding="utf-8") as f:
      for lines in f:
          list_string = lines
          #converting author list in string
          def listExtractedString(list_string):
              str1 = ""
              return(str1.join(list_string))
          
          #saved the result of the author list to string convertion
          authorListtoString = listExtractedString(list_string)
          #print(authorListtoString)
          #CONSTANTS.string_format = "{first} {middle} {last} ({suffix})"
          name = HumanName(authorListtoString)
          first = name.as_dict()["first"]
          middle = name.as_dict()["middle"]
          last = name.as_dict()["last"]
          #print(last.strip("']"))
          data = [{'first_name1': first.strip("'['").strip("]"),
                      'middle_name1': middle,
                      'last_name1': last.strip("']") 
                  }
          ]
          #print(data)
          for row in data:
              #print(row)
              csv_writer.writerow(row)
 
csvfile.close()