Skip to main content

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

使用

  1. 通用方法: 唯一的计算方法 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('外婆和奶奶之间是什么关系?')
    # => ['儿女亲家']
    
  2. 内部属性:获取当前数据表 rel.data.

  3. 内部方法:获取当前数据量 rel.data_count().

  4. 内部方法:用户自定义模式 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python3_relationship-0.1.2.tar.gz (34.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python3_relationship-0.1.2-py3-none-any.whl (39.5 kB view details)

Uploaded Python 3

File details

Details for the file python3_relationship-0.1.2.tar.gz.

File metadata

File hashes

Hashes for python3_relationship-0.1.2.tar.gz
Algorithm Hash digest
SHA256 ea7db36175dfcb4a82e21eb722cd0e2cc65571185740a1d99780983a7be0f847
MD5 fb33ace0ba3e69aad5788a227766d880
BLAKE2b-256 5a3cfb49d8629ec3faa876b278ccc0d7d9567a7d87b1524bc24a04b0c93b206e

See more details on using hashes here.

File details

Details for the file python3_relationship-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for python3_relationship-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 016febdbebdc47ab6f82b9ee9579ccb2b5800380f0fab2645216f8a0d81a1e4e
MD5 b37c0eccc43319614c26eceda2c7d35e
BLAKE2b-256 1a6d37dcde8d438e85b7c7a6cd8fa30bb269682ce8b36d8962df0bd992ae4de3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page