Chinese Kinship Calculator - Used for calculating family titles, kinship addresses, and generational relationships.
Project description
简介
这是中国亲戚关系计算器的python实现版,用于家庭称谓、亲戚称呼、辈分关系的计算。
原始版本为js代码实现,查看更多信息、了解具体算法原理等,请查看原仓库说明 —— https://github.com/mumuy/relationship
安装
使用pip 或者 uv
# pip
pip install python3-relationship
# uv
uv add python3-relationship
使用
-
通用方法: 唯一的计算方法
relationship.- 选项模式
relationship(options:Dict | ParameterOptions)
参数
options结构为:options = { "text": "", # 目标对象:目标对象的称谓汉字表达,称谓间用‘的’字分隔 "target": "", # 相对对象:相对对象的称谓汉字表达,称谓间用‘的’字分隔,空表示自己 "sex": -1, # 本人性别:0表示女性,1表示男性 "type": "default", # 转换类型:'default'计算称谓,'chain'计算关系链,'pair'计算关系合称 "reverse": False, # 称呼方式:True对方称呼我,False我称呼对方 "mode": "default", # 模式选择:使用set_mode方法定制不同地区模式,在此选择自定义模式 "optimal": False, # 最短关系:计算两者之间的最短关系 }
代码示例:
from relationship import Relationship from relationship.options import OptionType rel = Relationship() # 如:我应该叫外婆的哥哥什么? rel.relationship({"text": "妈妈的妈妈的哥哥"}) # => ['舅外公'] # 如:七舅姥爷应该叫我什么? rel.relationship({"text": "七舅姥爷", "reverse": True, "sex": 1}) # => ['甥外孙'] # 如:舅公是什么亲戚 rel.relationship({"text": "舅公", "type": OptionType.CHAIN}) # => ['爸爸的妈妈的兄弟', '妈妈的妈妈的兄弟', '老公的妈妈的兄弟'] # 如:舅妈如何称呼外婆? rel.relationship({"text": "外婆", "target": "舅妈", "sex": 1}) # => ['婆婆'] # 如:外婆和奶奶之间是什么关系? rel.relationship({"text": "外婆", "target": "奶奶", "type": OptionType.PAIR}) # => ['儿女亲家']
- 语句模式
relationship(exptession: str)
参数
exptession句式可以为:xxx是xxx的什么人、xxx叫xxx什么、xxx如何称呼xxx等. 代码示例:# 如:舅妈如何称呼外婆? rel.relationship('舅妈如何称呼外婆?') # => ['婆婆'] # 如:外婆和奶奶之间是什么关系? rel.relationship('外婆和奶奶之间是什么关系?') # => ['儿女亲家']
- 选项模式
-
内部属性:获取当前数据表
rel.data. -
内部方法:获取当前数据量
rel.data_count(). -
内部方法:用户自定义模式
rel.set_mode(mode: OptionMode, extra_data: dict[str, list[str]] = {}). 代码示例(可参考数据表格式对数据进行覆盖):from relationship.options import OptionMode rel.set_mode(OptionMode.GUANG_DONG)
# 关系解析语法 # 【关系链】f:父,m:母,h:夫,w:妻,s:子,d:女,xb:兄弟,ob:兄,lb:弟,xs:姐妹,os:姐,ls:妹 # 【修饰符】 1:男性,0:女性,&o:年长,&l:年幼,#:隔断,[a|b]:并列 rel.set_mode("northern",{ "m,f":["姥爷"], "m,m":["姥姥"], "m,xb,s&o":["表哥"], "m,xb,s&l":["表弟"], })
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file python3_relationship-0.1.2.tar.gz.
File metadata
- Download URL: python3_relationship-0.1.2.tar.gz
- Upload date:
- Size: 34.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.26
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ea7db36175dfcb4a82e21eb722cd0e2cc65571185740a1d99780983a7be0f847
|
|
| MD5 |
fb33ace0ba3e69aad5788a227766d880
|
|
| BLAKE2b-256 |
5a3cfb49d8629ec3faa876b278ccc0d7d9567a7d87b1524bc24a04b0c93b206e
|
File details
Details for the file python3_relationship-0.1.2-py3-none-any.whl.
File metadata
- Download URL: python3_relationship-0.1.2-py3-none-any.whl
- Upload date:
- Size: 39.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.26
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
016febdbebdc47ab6f82b9ee9579ccb2b5800380f0fab2645216f8a0d81a1e4e
|
|
| MD5 |
b37c0eccc43319614c26eceda2c7d35e
|
|
| BLAKE2b-256 |
1a6d37dcde8d438e85b7c7a6cd8fa30bb269682ce8b36d8962df0bd992ae4de3
|