Working Py

master
Debdut Karmakar 2020-08-19 11:56:16 +05:30
commit 28e30ba887
No known key found for this signature in database
GPG Key ID: 7780552A82396439
31 changed files with 801 additions and 0 deletions

1
.github/FUNDING.yml vendored Normal file
View File

@ -0,0 +1 @@
github: [philipperemy]

114
.gitignore vendored Normal file
View File

@ -0,0 +1,114 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
.idea/
.DS_Store
output/
*.tsv
*.tar.gz
*out*
credentials.json
*.json
nohup.out
*.out
*.txt
# C extensions
*.so
# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# Jupyter Notebook
.ipynb_checkpoints
# pyenv
.python-version
# celery beat schedule file
celerybeat-schedule
# SageMath parsed files
*.sage.py
# dotenv
.env
# virtualenv
.venv
venv/
ENV/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/

201
LICENSE Normal file
View File

@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

118
README.md Normal file
View File

@ -0,0 +1,118 @@
# name-dataset
> _A First and Last Name Dataset_
<img src='assets/logo.png'/>
## Features
- ~160k first names
- ~100k last names
- Find Names in Texts
- Hiigh Precision / Recall
- Worldwide Names
<!-- ## Installation
```
npm install name-dataset
```
## Usage
```js
const Names = require('name-dataset')
``` -->
```
echo -e "$(python main.py 'Brian is in the kitchen while Amanda is watching the TV on the sofa.\nThey are both waiting for Alfred to come.')"
```
<img src='assets/img_1.png'/>
## How reliable is it?
Well, it depends if you are looking for a high recall or a high precision. For example, the word Rose can be either a name or a noun. If we include it in the list, then we increase the precision but we decrease the recall. And vice versa, if it's not in the list. The library checks that the word starts with a capital letter. In our case, we emphasize more on precision. So I would say the best use case here is to check whether it's a name or not based on a prior knowledge that the customer has submitted a name.
Here is an example on a (old) text: [ALI BABA AND THE FORTY THIEVES](http://textfiles.com/stories/ab40thv.txt).
<img src='misc/img_2.png'/>
## License
I don't own the data obviously. It's fetched from the websites listed in:
https://github.com/philipperemy/name-dataset/blob/master/generation/generate.sh
So I guess the most strict software license should apply here.
## Sources and References
Exhaustive list of all the possible websites. Not all are used since there is a lot of garbage in the lists.
- Generator: http://listofrandomnames.com/index.cfm?generated
- https://www.sajari.com/public-data: 5000 names (First Names CSV)
- http://www.20000-names.com/ names around the world
- https://catalogue.data.gov.bc.ca/dataset/most-popular-boys-names-for-the-past-100-years UK
- https://catalogue.data.gov.bc.ca/dataset/most-popular-girl-names-for-the-past-100-years UK
- https://www.nrscotland.gov.uk/statistics-and-data/statistics/statistics-by-theme/vital-events/names/babies-first-names/full-lists-of-babies-first-names-2010-to-2014 Scotland
- https://gender-api.com/en/pricing
- https://github.com/OpenGenderTracking/globalnamedata/tree/master/assets
- From https://bocoup.com/blog/global-name-data
- https://github.com/MatthiasWinkelmann/firstname-database
- http://www.namepedia.org/en/firstname/Nabil/
- https://datasets.imdbws.com/
- https://www.imdb.com/interfaces/
- https://opendata.stackexchange.com/questions/46/multinational-list-of-popular-first-names-and-surnames
- ftp://ftp.heise.de/pub/ct/listings/0717-182.zip
- https://data.world/howarder/gender-by-name
- https://statbel.fgov.be/en/open-data/first-names-total-population-municipality
- https://www.ons.gov.uk/peoplepopulationandcommunity/birthsdeathsandmarriages/livebirths/bulletins/babynamesenglandandwales/previousReleases
- http://www.cs.cmu.edu/afs/cs/project/ai-repository/ai/areas/nlp/corpora/names/
- https://www.ssa.gov/oact/babynames/limits.html
- https://www.ssa.gov/OACT/babynames/
- https://www.ssa.gov/cgi-bin/popularnames.cgi
- https://github.com/hadley/data-baby-names/blob/master/baby-names.csv
- http://www.quietaffiliate.com/free-first-name-and-last-name-databases-csv-and-sql/
- https://stackoverflow.com/questions/1452003/plain-computer-parseable-lists-of-common-first-names
- http://mbejda.github.io/
- https://www2.census.gov/topics/genealogy/1990surnames/dist.all.last
- https://opendata.stackexchange.com/questions/1108/database-of-names-of-japanese-and-non-japanese-people
- https://opendata.stackexchange.com/questions/12234/name-and-gender-dataset
- https://opendata.stackexchange.com/questions/7071/people-names-by-country
- http://www.randomnames.com/all-boys-names.asp
- https://en.wikipedia.org/wiki/List_of_most_popular_given_names#cite_note-ahram2004-2
- http://www.avss.ucsb.edu/NameFema.HTM
- http://www.oxfordreference.com/view/10.1093/acref/9780198610601.001.0001/acref-9780198610601?btog=chap&hide=true&page=248&pageSize=10&skipEditions=true&sort=titlesort&source=%2F10.1093%2Facref%2F9780198610601.001.0001%2Facref-9780198610601
- https://github.com/dominictarr/random-name/blob/master/first-names.txt
- https://github.com/smashew/NameDatabases/tree/master/NamesDatabases/first%20names
- https://www.behindthename.com/names
- https://incompetech.com/named/multi.pl

BIN
assets/img_1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

BIN
assets/img_2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 476 KiB

BIN
assets/logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

45
evaluate.py Normal file
View File

@ -0,0 +1,45 @@
from names_dataset import NameDataset
# https://scikit-learn.org/stable/modules/generated/sklearn.metrics.precision_recall_fscore_support.html
# Precision: The precision is intuitively the ability of the classifier not to label as positive a sample that is negative.
# Recall: The recall is intuitively the ability of the classifier to find all the positive samples.
def read_dict_file(filename):
with open(filename, 'r', encoding='utf8') as r:
lines = r.read().strip().split('\n')
return lines
def main():
m = NameDataset()
names = read_dict_file('eng_dictionary/names-from-forbes-wp_users.txt')
not_names = read_dict_file('eng_dictionary/google-10000-english-no-names.txt')
not_names.extend(read_dict_file('eng_dictionary/1000-no-names.txt'))
names = sorted(set(names))
not_names = sorted(set(not_names))
# 0 => not a name
# 1 => name
targets = []
predictions = []
for q in names:
predictions.append(m.search_first_name(q))
targets.append(True)
for q in not_names:
predictions.append(m.search_first_name(q))
targets.append(False)
from sklearn.metrics import precision_score, recall_score, f1_score, accuracy_score
print('P', precision_score(y_true=targets, y_pred=predictions))
print('R', recall_score(y_true=targets, y_pred=predictions))
print('F', f1_score(y_true=targets, y_pred=predictions))
print('A', accuracy_score(y_true=targets, y_pred=predictions))
if __name__ == '__main__':
main()

28
generation/diff.py Normal file
View File

@ -0,0 +1,28 @@
import sys
def read_dict_file(filename):
with open(filename, 'r', encoding='utf8', errors='ignore') as r:
lines = r.read().strip().lower().split('\n')
return lines
def write_dict_file(filename, dicts):
with open(filename, 'w', encoding='utf8') as w:
for line in dicts:
w.write(line)
w.write('\n')
def main():
a = read_dict_file(sys.argv[1])
b = read_dict_file(sys.argv[2])
if sys.argv[4] == '-':
c = sorted(set(a) - set(b))
else:
c = sorted(set(a).union(set(b)))
write_dict_file(sys.argv[3], c)
if __name__ == '__main__':
main()

118
generation/generate.sh Executable file
View File

@ -0,0 +1,118 @@
#!/usr/bin/env bash
set -e
export LC_CTYPE=C
OUTPUT_DIR=output
mkdir -p ${OUTPUT_DIR}
rm -rf ${OUTPUT_DIR}
echo "--------------------------------------------------"
echo "Generating the whole dataset in ${OUTPUT_DIR}/..."
echo "It takes around 7min on a MacBookPro 2017."
echo "--------------------------------------------------"
DATASET=MatthiasWinkelmann_firstname-database
wget -nv --read-timeout=30 --tries=3 --waitretry=5 https://github.com/MatthiasWinkelmann/firstname-database/raw/master/firstnames.csv -P ${OUTPUT_DIR}/${DATASET}/
bash scripts/${DATASET}/transform.sh ${OUTPUT_DIR}/${DATASET}/
#DATASET=cs.cmu.edu.ai-repository
#wget -nv --read-timeout=30 --tries=3 --waitretry=5 http://www.cs.cmu.edu/afs/cs/project/ai-repository/ai/areas/nlp/corpora/names/female.txt -P ${OUTPUT_DIR}/${DATASET}
#wget -nv --read-timeout=30 --tries=3 --waitretry=5 http://www.cs.cmu.edu/afs/cs/project/ai-repository/ai/areas/nlp/corpora/names/male.txt -P ${OUTPUT_DIR}/${DATASET}
#wget -nv --read-timeout=30 --tries=3 --waitretry=5 http://www.cs.cmu.edu/afs/cs/project/ai-repository/ai/areas/nlp/corpora/names/other/family.txt -P ${OUTPUT_DIR}/${DATASET}
#wget -nv --read-timeout=30 --tries=3 --waitretry=5 http://www.cs.cmu.edu/afs/cs/project/ai-repository/ai/areas/nlp/corpora/names/other/names.txt -P ${OUTPUT_DIR}/${DATASET}
#bash scripts/${DATASET}/transform.sh ${OUTPUT_DIR}/${DATASET}/
DATASET=yorkshiretwist
wget -nv --read-timeout=30 --tries=3 --waitretry=5 https://raw.githubusercontent.com/yorkshiretwist/WTester/master/WTester/Helpers/CSV_Database_of_First_Names.csv -P ${OUTPUT_DIR}/${DATASET}
wget -nv --read-timeout=30 --tries=3 --waitretry=5 https://raw.githubusercontent.com/yorkshiretwist/WTester/master/WTester/Helpers/CSV_Database_of_Last_Names.csv -P ${OUTPUT_DIR}/${DATASET}
python scripts/${DATASET}/transform.py ${OUTPUT_DIR}/${DATASET}/CSV_Database_of_First_Names.csv
python scripts/${DATASET}/transform.py ${OUTPUT_DIR}/${DATASET}/CSV_Database_of_Last_Names.csv
DATASET=github_hadley_data-baby-names
wget -nv --read-timeout=30 --tries=3 --waitretry=5 https://raw.githubusercontent.com/hadley/data-baby-names/master/baby-names.csv -P ${OUTPUT_DIR}/${DATASET}
bash scripts/${DATASET}/transform.sh ${OUTPUT_DIR}/${DATASET}/
#DATASET=datasets_imdb
#wget -nv --read-timeout=30 --tries=3 --waitretry=5 https://datasets.imdbws.com/name.basics.tsv.gz -P ${OUTPUT_DIR}/${DATASET}
#gunzip ${OUTPUT_DIR}/${DATASET}/*
#bash scripts/${DATASET}/transform.sh ${OUTPUT_DIR}/${DATASET}/
DATASET=github_com_dominictarr_random-name
wget -nv --read-timeout=30 --tries=3 --waitretry=5 https://raw.githubusercontent.com/dominictarr/random-name/master/names.txt -P ${OUTPUT_DIR}/${DATASET}
bash scripts/${DATASET}/transform.sh ${OUTPUT_DIR}/${DATASET}/
DATASET=github_com_dominictarr_random-name
wget -nv --read-timeout=30 --tries=3 --waitretry=5 https://raw.githubusercontent.com/smashew/NameDatabases/master/NamesDatabases/first%20names/non-normalized/es.txt -P ${OUTPUT_DIR}/${DATASET}
bash scripts/${DATASET}/transform.sh ${OUTPUT_DIR}/${DATASET}/
DATASET=httpswwwsajaricompublic-data
wget -nv --read-timeout=30 --tries=3 --waitretry=5 https://www.sajari.com/free-data/CSV_Database_of_First_Names.csv -P ${OUTPUT_DIR}/${DATASET}
wget -nv --read-timeout=30 --tries=3 --waitretry=5 https://www.sajari.com/free-data/CSV_Database_of_Last_Names.csv -P ${OUTPUT_DIR}/${DATASET}
python scripts/${DATASET}/transform.py ${OUTPUT_DIR}/${DATASET}/CSV_Database_of_First_Names.csv
python scripts/${DATASET}/transform.py ${OUTPUT_DIR}/${DATASET}/CSV_Database_of_Last_Names.csv
DATASET=mbejda.github.io
wget -nv --read-timeout=30 --tries=3 --waitretry=5 https://gist.githubusercontent.com/mbejda/1e77ee4ad268916142a6/raw/22d1b475217be7240aba54c1a1b545557d624ba8/Hispanic-Female-Names.csv -P ${OUTPUT_DIR}/${DATASET}
wget -nv --read-timeout=30 --tries=3 --waitretry=5 https://gist.githubusercontent.com/mbejda/21fbbfe24efd2a114800/raw/52db651f79a716c87b21ef06c224ff443cb41f06/Hispanic-Male-Names.csv -P ${OUTPUT_DIR}/${DATASET}
wget -nv --read-timeout=30 --tries=3 --waitretry=5 https://gist.githubusercontent.com/mbejda/26ad0574eda7fca78573/raw/6936d1a8f5fa5220f2f60a51a06a35b172c50f93/White-Female-Names.csv -P ${OUTPUT_DIR}/${DATASET}
wget -nv --read-timeout=30 --tries=3 --waitretry=5 https://gist.githubusercontent.com/mbejda/61eb488cec271086632d/raw/6340b8045b28c2abc0b1d44cfbc80f40284ef890/Black-Male-Names.csv -P ${OUTPUT_DIR}/${DATASET}
wget -nv --read-timeout=30 --tries=3 --waitretry=5 https://gist.githubusercontent.com/mbejda/6c2293ba3333b7e76269/raw/60aa0c95e8ee9b11b915a26f47480fef5c3203ed/White-Male-Names.csv -P ${OUTPUT_DIR}/${DATASET}
wget -nv --read-timeout=30 --tries=3 --waitretry=5 https://gist.githubusercontent.com/mbejda/7f86ca901fe41bc14a63/raw/38adb475c14a3f44df9999c1541f3a72f472b30d/Indian-Male-Names.csv -P ${OUTPUT_DIR}/${DATASET}
wget -nv --read-timeout=30 --tries=3 --waitretry=5 https://gist.githubusercontent.com/mbejda/9b93c7545c9dd93060bd/raw/b582593330765df3ccaae6f641f8cddc16f1e879/Indian-Female-Names.csv -P ${OUTPUT_DIR}/${DATASET}
wget -nv --read-timeout=30 --tries=3 --waitretry=5 https://gist.githubusercontent.com/mbejda/9dc89056005a689a6456/raw/bb6ef2375f1289d0ef10dbd8e9469670ac23ceab/Black-Female-Names.csv -P ${OUTPUT_DIR}/${DATASET}
bash scripts/${DATASET}/transform.sh ${OUTPUT_DIR}/${DATASET}/
DATASET=most-popular-names-for-the-past-100-years
wget -nv --read-timeout=30 --tries=3 --waitretry=5 https://catalogue.data.gov.bc.ca/dataset/bfcdd4d7-056b-4069-a09e-5dbda4d11841/resource/2d8c478f-3223-4883-a300-1cac7a344ee3/download/bc-popular-boys-names.csv -P ${OUTPUT_DIR}/${DATASET}
wget -nv --read-timeout=30 --tries=3 --waitretry=5 https://catalogue.data.gov.bc.ca/dataset/db803d65-bcfa-44e8-b98d-76e7b02f3500/resource/c9a3af38-f374-412a-9cbe-0dd590f677f9/download/bc-popular-girls-names.csv -P ${OUTPUT_DIR}/${DATASET}
bash scripts/${DATASET}/transform.sh ${OUTPUT_DIR}/${DATASET}/
DATASET=OpenGenderTracking_globalnamedata
wget -nv --read-timeout=30 --tries=3 --waitretry=5 https://github.com/OpenGenderTracking/globalnamedata/raw/master/assets/uknames.csv -P ${OUTPUT_DIR}/${DATASET}
wget -nv --read-timeout=30 --tries=3 --waitretry=5 https://github.com/OpenGenderTracking/globalnamedata/raw/master/assets/ukprocessed.csv -P ${OUTPUT_DIR}/${DATASET}
wget -nv --read-timeout=30 --tries=3 --waitretry=5 https://github.com/OpenGenderTracking/globalnamedata/raw/master/assets/usnames.csv -P ${OUTPUT_DIR}/${DATASET}
wget -nv --read-timeout=30 --tries=3 --waitretry=5 https://github.com/OpenGenderTracking/globalnamedata/raw/master/assets/usprocessed.csv -P ${OUTPUT_DIR}/${DATASET}
bash scripts/${DATASET}/transform.sh ${OUTPUT_DIR}/${DATASET}/
DATASET=ssa.gov_oact_babynames_limits
wget -nv --read-timeout=30 --tries=3 --waitretry=5 https://www.ssa.gov/oact/babynames/names.zip -P ${OUTPUT_DIR}/${DATASET}
unzip ${OUTPUT_DIR}/${DATASET}/* -d ${OUTPUT_DIR}/${DATASET}
bash scripts/${DATASET}/transform.sh ${OUTPUT_DIR}/${DATASET}/
DATASET=www.nrscotland.gov.uk
wget -nv --read-timeout=30 --tries=3 --waitretry=5 https://www.nrscotland.gov.uk/files//statistics/babies-first-names-full-list/2010-2019/babies-first-names-17-historical-16.csv -P ${OUTPUT_DIR}/${DATASET}
wget -nv --read-timeout=30 --tries=3 --waitretry=5 https://www.nrscotland.gov.uk/files//statistics/babies-first-names-full-list/2010-2019/babies-first-names-17-historical-17.csv -P ${OUTPUT_DIR}/${DATASET}
wget -nv --read-timeout=30 --tries=3 --waitretry=5 https://www.nrscotland.gov.uk/files//statistics/babies-first-names-full-list/2010-2019/babies-first-names-2010.csv -P ${OUTPUT_DIR}/${DATASET}
wget -nv --read-timeout=30 --tries=3 --waitretry=5 https://www.nrscotland.gov.uk/files//statistics/babies-first-names-full-list/2010-2019/babies-first-names-2011.csv -P ${OUTPUT_DIR}/${DATASET}
wget -nv --read-timeout=30 --tries=3 --waitretry=5 https://www.nrscotland.gov.uk/files//statistics/babies-first-names-full-list/2010-2019/babies-first-names-2012.csv -P ${OUTPUT_DIR}/${DATASET}
wget -nv --read-timeout=30 --tries=3 --waitretry=5 https://www.nrscotland.gov.uk/files//statistics/babies-first-names-full-list/2010-2019/babies-first-names-2013.csv -P ${OUTPUT_DIR}/${DATASET}
wget -nv --read-timeout=30 --tries=3 --waitretry=5 https://www.nrscotland.gov.uk/files//statistics/babies-first-names-full-list/2010-2019/babies-first-names-2014.csv -P ${OUTPUT_DIR}/${DATASET}
wget -nv --read-timeout=30 --tries=3 --waitretry=5 https://www.nrscotland.gov.uk/files//statistics/babies-first-names-full-list/2010-2019/babies-first-names-2015.csv -P ${OUTPUT_DIR}/${DATASET}
export LC_ALL=C; bash scripts/${DATASET}/transform.sh ${OUTPUT_DIR}/${DATASET}/
DATASET=www2.census.gov.1990surnames
wget -nv --read-timeout=30 --tries=3 --waitretry=5 https://www2.census.gov/topics/genealogy/1990surnames/dist.all.last -P ${OUTPUT_DIR}/${DATASET}
bash scripts/${DATASET}/transform.sh ${OUTPUT_DIR}/${DATASET}/
#wget -nv --read-timeout=30 --tries=3 --waitretry=5 https://raw.githubusercontent.com/smashew/NameDatabases/master/NamesDatabases/first%20names/all.txt -P ${OUTPUT_DIR}/${DATASET}
#wget -nv --read-timeout=30 --tries=3 --waitretry=5 https://raw.githubusercontent.com/smashew/NameDatabases/master/NamesDatabases/first%20names/us.txt -P ${OUTPUT_DIR}/${DATASET}
#wget -nv --read-timeout=30 --tries=3 --waitretry=5 https://static1.squarespace.com/static/588c1f531e5b6c553fe26beb/t/59e8fd7d017db27f7ad2ef7a/1508441525530/F104B59A-C180-4DD1-982B-99A536ACA55F.jpeg-P ${OUTPUT_DIR}/${DATASET}
echo "Generating the first and last names files"
export LC_CTYPE=C; find ${OUTPUT_DIR} -name '*irst*.out' -print0 | xargs -0 cat | awk '{print tolower($0)}' | awk '{$1=$1};1' | grep -v '@' | grep -v '"' | grep -v '\.' | grep -v '+' | grep -v ' ' | sort | uniq > ${OUTPUT_DIR}/first_names.all.txt
export LC_CTYPE=C; find ${OUTPUT_DIR} -name '*last*.out' -print0 | xargs -0 cat | awk '{print tolower($0)}' | awk '{$1=$1};1' | grep -v '@' | grep -v '"' | grep -v '\.' | grep -v '+' | grep -v ' ' | sort | uniq > ${OUTPUT_DIR}/last_names.all.txt
python diff.py ${OUTPUT_DIR}/last_names.all.txt ../eng_dictionary/google-10000-english-no-names.txt ${OUTPUT_DIR}/last_names.all.txt -
python diff.py ${OUTPUT_DIR}/first_names.all.txt ../eng_dictionary/google-10000-english-no-names.txt ${OUTPUT_DIR}/first_names.all.txt -
echo "--------------------------------------------------"
echo "Done. Output directory is ${OUTPUT_DIR}/."
echo "> find ${OUTPUT_DIR} | grep '.out' to find the aux files."
echo " First names: ${OUTPUT_DIR}/first_names.all.txt."
echo " Last names: ${OUTPUT_DIR}/last_names.all.txt."
echo "--------------------------------------------------"

View File

@ -0,0 +1,12 @@
#!/usr/bin/env bash
cp output/first_names.all.txt ../names_dataset/
cp output/last_names.all.txt ../names_dataset/
cd ..
pip install . --upgrade
pip install scikit-learn
python evaluate.py english_common_words/1000.txt
python evaluate.py english_common_words/google-10000-english.txt

View File

@ -0,0 +1,2 @@
#!/usr/bin/env bash
cat $1/firstnames.csv | cut -d ';' -f 1 > $1/firstnames.csv.out

View File

@ -0,0 +1,2 @@
#!/usr/bin/env bash
cat $1/* | cut -d ',' -f 1 > $1/first_names.csv.out

View File

@ -0,0 +1,3 @@
#!/usr/bin/env bash
cp $1/names.txt $1/first-names.csv.out
cp $1/family.txt $1/last-names.csv.out

View File

@ -0,0 +1,14 @@
#!/usr/bin/env bash
# cat name.basics.tsv | grep -E "actor|actress" | cut -d$'\t' -f 2 | cut -d ' ' -f 1 > first_names.csv.out
#cat name.basics.tsv | grep -E "actor|actress" | cut -d$'\t' -f 2 | cut -d ' ' -f 2 > last_names.csv.out
# cat name.basics.tsv | awk -F"\t" '{print $2}' | grep " " | cut -d ' ' -f 1 > first_names.csv.out
# cat name.basics.tsv | awk -F"\t" '{print $2}' | grep " " | cut -d ' ' -f 2 > last_names.csv.out
# sort last_names.csv.out | uniq -c | sort -bgr > out
# cat out | grep -v ' 3' | grep -v ' 2' | grep -v ' 1' | grep -v ' 4' | awk '{$1=$1};1' | cut -d' ' -f 2 | grep -E "^[A-Za-z]+$" > last_names.csv.out
echo "Please be patient on this one..."
cat $1/name.basics.tsv | awk -F"\t" '{print $2}' | grep " " | cut -d ' ' -f 2 | sort | uniq -c | sort -bgr | grep -v ' 3 ' | grep -v ' 2 ' | grep -v ' 1 ' | grep -v ' 4 ' | awk '{$1=$1};1' | cut -d' ' -f 2 | grep -E "^[A-Za-z]+$" > $1/last_names.csv.out
cat $1/name.basics.tsv | awk -F"\t" '{print $2}' | grep " " | cut -d ' ' -f 1 | sort | uniq -c | sort -bgr | grep -v ' 3 ' | grep -v ' 2 ' | grep -v ' 1 ' | grep -v ' 4 ' | awk '{$1=$1};1' | cut -d' ' -f 2 | grep -E "^[A-Za-z]+$" > $1/first_names.csv.out

View File

@ -0,0 +1,2 @@
#!/usr/bin/env bash
cat $1/*.txt > $1/first_names.csv.out

View File

@ -0,0 +1 @@
cat *.txt | sort | uniq > first_names.csv.out

View File

@ -0,0 +1,2 @@
#!/usr/bin/env bash
awk '{gsub(/\"/,"")};1' $1/baby-names.csv | cut -d ',' -f 2 > $1/first_names.csv.out

View File

@ -0,0 +1,3 @@
import sys
open(sys.argv[1] + '.out', 'w').write('\n'.join([a.strip() for a in open(sys.argv[1], 'r').readlines()]))

View File

@ -0,0 +1,3 @@
#!/usr/bin/env bash
python transform.py CSV_Database_of_Last_Names.csv
python transform.py CSV_Database_of_First_Names.csv

View File

@ -0,0 +1,3 @@
#!/usr/bin/env bash
cat $1/* | cut -d , -f 1 > $1/last_names.csv.out
cat $1/* | cut -d , -f 2 > $1/first_names.csv.out

View File

@ -0,0 +1,4 @@
#!/usr/bin/env bash
export LC_CTYPE=C
cat $1/bc-popular-boys-names.csv | cut -d ',' -f 1 >> $1/firstnames.csv.out
cat $1/bc-popular-girls-names.csv | cut -d ',' -f 1 >> $1/firstnames.csv.out

View File

@ -0,0 +1,2 @@
#!/usr/bin/env bash
cat $1/*.txt | cut -d ',' -f 1 > $1/first_names.csv.out

View File

@ -0,0 +1,2 @@
#!/usr/bin/env bash
cat $1/* | cut -d ',' -f 2 > $1/first_names.csv.out

View File

@ -0,0 +1,2 @@
#!/usr/bin/env bash
cat $1/dist.all.last | cut -d ' ' -f 1 > $1/last_names.csv.out

View File

@ -0,0 +1,3 @@
import sys
open(sys.argv[1] + '.out', 'w').write('\n'.join([a.strip() for a in open(sys.argv[1], 'r').readlines()]))

View File

@ -0,0 +1,6 @@
#!/usr/bin/env bash
#cp $1/CSV_Database_of_First_Names.csv $1/CSV_Database_of_First_Names.csv.out
#cp $1/CSV_Database_of_Last_Names.csv $1/CSV_Database_of_Last_Names.csv.out
python $(pwd)/transform.py $1/CSV_Database_of_Last_Names.csv
python $(pwd)/transform.py $1/CSV_Database_of_First_Names.csv

34
main.py Normal file
View File

@ -0,0 +1,34 @@
import os
import sys
from evaluate import read_dict_file
from names_dataset import NameDataset
def main():
m = NameDataset()
if os.path.isfile(sys.argv[1]):
words = read_dict_file(sys.argv[1])
else:
words = [sys.argv[1]]
# cheap word tokenizer.
words = ' '.join(words).replace('.', ' ').replace('?', ' ').replace('\'', ' ').split(' ')
output = ''
for word in words:
if m.search_first_name(word, use_upper_case=True):
output += '\e[44m'
output += word
output += '\e[0m'
elif m.search_last_name(word, use_upper_case=True):
output += '\e[46m'
output += word
output += '\e[0m'
else:
output += word
output += ' '
print(output)
if __name__ == '__main__':
main()

View File

@ -0,0 +1,3 @@
from names_dataset.query import NameDataset
__version__ = '1.9.1'

52
names_dataset/query.py Normal file
View File

@ -0,0 +1,52 @@
import os
def _query(search_set, key, use_upper_case):
if use_upper_case and key.title() != key:
return False
return key.strip().lower() in search_set
class NameDataset:
FIRST_NAME_SEARCH = 0
LAST_NAME_SEARCH = 1
def __init__(self):
first_names_filename = os.path.join(os.path.dirname(__file__), 'first_names.all.txt')
with open(first_names_filename, 'r', errors='ignore', encoding='utf8') as r:
self.first_names = set(r.read().strip().split('\n'))
last_names_filename = os.path.join(os.path.dirname(__file__), 'last_names.all.txt')
with open(last_names_filename, 'r', errors='ignore', encoding='utf8') as r:
self.last_names = set(r.read().strip().split('\n'))
def search_first_name(self, first_name, use_upper_case=False):
return _query(self.first_names, first_name, use_upper_case)
def search_last_name(self, last_name, use_upper_case=False):
return _query(self.last_names, last_name, use_upper_case)
if __name__ == '__main__':
import sys
if sys.version_info < (3, 0):
print('Please use Python3+')
exit(1)
if len(sys.argv) < 2:
print('Give names separated by a comma as input.')
sys.exit(1)
m = NameDataset()
names_list = sys.argv[1].split(',')
print('----- First names ----')
print('Name'.ljust(30), 'Present?')
for name in names_list:
# ljust just for aesthetic reasons ;)
print(str(name).ljust(30), m.search_first_name(name))
print('----- Last names ----')
print('Name'.ljust(30), 'Present?')
for name in names_list:
# ljust just for aesthetic reasons ;)
print(str(name).ljust(30), m.search_last_name(name))
sys.exit(0)

21
setup.py Normal file
View File

@ -0,0 +1,21 @@
import os
from setuptools import setup, find_packages
VERSION = '1.9.1'
package_name = find_packages()[0]
setup(
name='names-dataset',
version=VERSION,
description='Probably the biggest dataset of Names, worldwide',
author='Philippe Remy',
license='MIT',
packages=[package_name],
include_package_data=True,
data_files=[(package_name, [
os.path.join(package_name, 'first_names.all.txt'),
os.path.join(package_name, 'last_names.all.txt')
])]
)