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.3.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.3-py3-none-any.whl (39.6 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for python3_relationship-0.1.3.tar.gz
Algorithm Hash digest
SHA256 31daeb6dfab0d10eac01b045dd86fa2acbd90fc725bbfaa6108ed33421582380
MD5 3daeba7587615925708de6e3724a0441
BLAKE2b-256 4609b0a41cdbf792d3e9257f232adb0ebe991ffcccb35ea07e05978f007fb1cf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python3_relationship-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 e500fd0ba3000e2c6cbc314873000cbc071a9f687379820a24e8d92bc2728b05
MD5 88503c4b0bb33614f99841a617965783
BLAKE2b-256 cacadcfb83e751ce462134d9583c563cf5eeb705ad515cab8f16a20c73afa0e0

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