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.1.tar.gz (34.0 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.1-py3-none-any.whl (39.5 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for python3_relationship-0.1.1.tar.gz
Algorithm Hash digest
SHA256 d9f0c24703b819c4d09a71d90f234d19c6f866a14868d9397942cf7c43009309
MD5 c3e082292f2174cefbcb54fe707e8a58
BLAKE2b-256 a8e3938959cdac91d9379d2938e54c57764376fd40f3c98e7e1e765706717b89

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for python3_relationship-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 77a0e7b35c199e2a3f512dfe0ffc8be7215a9080e26fa1cf050217dd52cf01f6
MD5 23c9c5dcdf8a8dcc4849abf603671c06
BLAKE2b-256 c654e5fe1e9323f256cc8535c3e25df513f3e2c6cd938e67f27c7278f97ef2b9

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