Skip to content

Latest commit

 

History

History
52 lines (40 loc) · 1.88 KB

README.rst

File metadata and controls

52 lines (40 loc) · 1.88 KB

japanesenames

What's this

japanesnames is a python package to help you name your loving child. It works on Python 2.x.

Be sure to call make_data.py before you play. It scrapes tons of names via websites and write data to files.

By using Collection classes, you can query names giving kanji characters or a part of furigana.

For example, you want to give one of kanji in your name to child's name. You do :

>>> # import collection class
>>> from japanesenames.collection import BoysNameCollection as BNC
>>> # make collection class to perform query
>>> q = BNC()
>>> # find names containing character '淳'.
>>> q.contains(u'')
>>> # print number of items in current collection.
>>> print len(q)
61
>>> # give one more word restriction to query
>>> q.contains_in_furigana(u'')
>>> print len(q)
40

The collection object itself returns iterator. Let's make list out of it to see selected items.

>>> print list(q)
[Name(name=u'淳夢', furigana=u'あつむ'), ...]
>>> # remove items which are furigana is 'あつし'
>>> [x for x in q if x.furigana != u'あつし']
[Name(name=u'淳夢', furigana=u'あつむ'), ...]

Each objects representing names are Name objects. They ara hashable, which menas instances can be included in sets. You can do set operation among collections by converting collection to set.

>>> q1 = BNC()
>>> q1.contains(u'')
>>> q2 = BNC()
>>> q2.contains_in_furigana(u'あつ')
>>> # avoid names containing similar furigana as 'あつし'
>>> set(q1) - set(q2)
set([Name(name=u'淳規', furigana=u'じゅんき'), Name(name=u'淳平', furigana=u'じゅんぺい')...])

Name object has kakusu() method. You can calculate kakusu easily.

>>> # show kakusu of each name
>>> [(x, x.kakusu()) for x in set(q1) - set(q2)]
[(Name(name=u'淳規', furigana=u'じゅんき'), 22), (Name(name=u'淳平', furigana=u'じゅんぺい'), 16)....]