Skip to content

Commit

Permalink
Random Hebrew names by gender and ethnicity (#2)
Browse files Browse the repository at this point in the history
Random Hebrew names by gender and ethnicity
  • Loading branch information
alumag authored Jan 13, 2023
1 parent c485a43 commit 254e042
Show file tree
Hide file tree
Showing 38 changed files with 187 additions and 94,517 deletions.
2 changes: 1 addition & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[run]
source = names
source = hebrew_names
branch = 1

[report]
Expand Down
37 changes: 37 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: Lint

on:
push:
branches: [ $default-branch ]
pull_request:
branches: [ $default-branch ]

jobs:
build:

runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10"]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
35 changes: 35 additions & 0 deletions .github/workflows/upload-python-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

# GitHub recommends pinning actions to a commit SHA.
# To get a newer version, you will need to update the SHA.
# You can also reference a tag or branch, but the action may change without warning.

name: Upload Python Package

on:
release:
types: [published]

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build
- name: Build package
run: python -m build
- name: Publish package
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
15 changes: 0 additions & 15 deletions .travis.yml

This file was deleted.

3 changes: 1 addition & 2 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
Authors
=======

- Trey Hunner <http://treyhunner.com>
- Simeon Visser <http://simeonvisser.com>
- Aluma Gelbard <https://github.com/alumag>
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Changes
tip (unreleased)
----------------

- Add Hebrew dataset for last names
- Add Hebrew dataset for first names
- Modified names.get_first_name to only accept 'male' and 'female' gender values

0.3.0 (2013-05-14)
Expand Down
4 changes: 4 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
Copyright for portions of project "Hebrew-Names" are held by Trey Hunner, 2013 as part of project "Names".
All other copyright for project "Hebrew-Names" are held by Aluma Gelbard, 2022.

The MIT License (MIT)
Copyright © 2022 Aluma Gelbard
Copyright © 2013 Trey Hunner

Permission is hereby granted, free of charge, to any person obtaining a copy
Expand Down
6 changes: 5 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
include *.rst
include names/dist.all.last names/dist.female.first names/dist.male.first
include hebrew_names/dist.jew.last hebrew_names/dist.jew.female.first hebrew_names/dist.jew.male.first
include hebrew_names/dist.muslim.last hebrew_names/dist.muslim.female.first hebrew_names/dist.muslim.male.first
include hebrew_names/dist.christian.last hebrew_names/dist.christian.female.first hebrew_names/dist.christian.male.first
include hebrew_names/dist.druze.last hebrew_names/dist.druze.female.first hebrew_names/dist.druze.male.first
include hebrew_names/dist.other.last hebrew_names/dist.other.female.first hebrew_names/dist.other.male.first
Binary file modified README.rst
Binary file not shown.
83 changes: 83 additions & 0 deletions hebrew_names/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
from os.path import abspath, join, dirname
import itertools
import codecs
import random


__title__ = 'hebrew-names'
__version__ = '0.0.1'
__author__ = 'Aluma Gelbard'
__license__ = 'MIT'


def full_path(filename):
return abspath(join(dirname(__file__), filename))


ETHNICITIES = ('jew', 'muslim', 'christian', 'druze', 'other')
GENDERS = ('male', 'female')

FILES = {
f'first:{ethnicity}:{gender}': full_path(f'dist.{ethnicity}.{gender}.first')
for (ethnicity, gender) in itertools.product(ETHNICITIES, GENDERS)
}

FILES.update({
f'last:{ethnicity}': full_path(f'dist.{ethnicity}.last')
for ethnicity in ETHNICITIES
})

FILES['cumulatives.all'] = full_path('dist.cumulatives.all')

CUMULATIVES = None


def load_cumulatives():
with codecs.open(FILES['cumulatives.all'], 'r', 'utf-16') as cumulatives_file:
global CUMULATIVES
CUMULATIVES = {
file: float(last_cumulative) for (file, last_cumulative) in (line.split('\t') for line in cumulatives_file)
}


def get_name(file):
if (not CUMULATIVES):
load_cumulatives()

selected = random.random() * CUMULATIVES[file]
with codecs.open(FILES[file], 'r', 'utf-16') as name_file:
for line in name_file:
name, _, _, cumulative, _ = line.split('\t')
if float(cumulative) >= selected:
return name
return "" # Return empty string if file is empty


def select_gender(gender=None):
gender = gender or random.choice(GENDERS)
if gender not in GENDERS:
raise ValueError("Only 'male' and 'female' are supported as gender")
return gender


def select_ethnicity(ethnicity=None):
ethnicity = ethnicity or random.choice(ETHNICITIES)
if ethnicity not in ETHNICITIES:
raise ValueError("Only 'jew', 'muslim', 'christian', 'druze' and 'other' are supported as ethnicity")
return ethnicity


def get_first_name(ethnicity=None, gender=None):
ethnicity = select_ethnicity(ethnicity)
gender = select_gender(gender)
return get_name(f'first:{ethnicity}:{gender}')


def get_last_name(ethnicity=None):
ethnicity = select_ethnicity(ethnicity)
return get_name(f'last:{ethnicity}')


def get_full_name(ethnicity=None, gender=None):
ethnicity = select_ethnicity(ethnicity)
return f'{get_first_name(ethnicity, gender)} {get_last_name(ethnicity)}'.strip()
Binary file added hebrew_names/dist.christian.female.first
Binary file not shown.
Binary file added hebrew_names/dist.christian.last
Binary file not shown.
Binary file added hebrew_names/dist.christian.male.first
Binary file not shown.
Binary file added hebrew_names/dist.cumulatives.all
Binary file not shown.
Binary file added hebrew_names/dist.druze.female.first
Binary file not shown.
Binary file added hebrew_names/dist.druze.last
Binary file not shown.
Binary file added hebrew_names/dist.druze.male.first
Binary file not shown.
Binary file added hebrew_names/dist.jew.female.first
Binary file not shown.
Binary file added hebrew_names/dist.jew.last
Binary file not shown.
Binary file added hebrew_names/dist.jew.male.first
Binary file not shown.
Binary file added hebrew_names/dist.muslim.female.first
Binary file not shown.
Binary file added hebrew_names/dist.muslim.last
Binary file not shown.
Binary file added hebrew_names/dist.muslim.male.first
Binary file not shown.
Binary file added hebrew_names/dist.other.female.first
Binary file not shown.
File renamed without changes.
Binary file added hebrew_names/dist.other.male.first
Binary file not shown.
3 changes: 1 addition & 2 deletions names/main.py → hebrew_names/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from __future__ import print_function
from names import get_full_name
from hebrew_names import get_full_name


def main():
Expand Down
45 changes: 0 additions & 45 deletions names/__init__.py

This file was deleted.

Loading

0 comments on commit 254e042

Please sign in to comment.