Skip to main content

成语与成语接龙查询工具(Python 版)

pypi python_vesion

用于成语接龙。

关于

特性

  1. 用于玩转成语接龙的种种方法。

安装

$ pip install china-idiom

升级

$ pip install -U china-idiom

依赖库

pandas>=0.23.4

使用示例

首先导入库

import china_idiom as idiom

1. 判断一个词是否是成语。

idiom.is_idiom('一心一意')
>>> True

2. 搜索成语

功能说明:

search_idiom(word, position=0, count=1, is_detail=False)
    :param word: str,关键词
    :param position: int, 所在位置,默认为:0
    :param count: int ,返回最大数量 默认为: 1
    :param is_detail: bool,是否返回详细内容(包括:拼音,拼音缩写,解释,来源,造句)
    :return: list

实用式例 1:简单查询

idiom.search_idiom(word='猪')
>>> ['指猪骂狗']

实用式例 2:查询成语第 2 个字是『心』的成语,最大查询数量为 2, 返回详细内容。

idiom.search_idiom(word='心', position=2, count=2, is_detail=True)
>>> 
[{'word': '热心快肠',
  'pinyin': 'rè xīn kuài cháng',
  'abbreviation': 'rxkc',
  'explanation': '形容热情直爽。',
  'derivation': '柯岩《奇异的书简·东方的明珠三》也许因为是她热心快肠,群众有事爱找她拿主意,帮个忙。”',
  'example': '无'},
 {'word': '人心大快',
  'pinyin': 'rén xīn dà kuài',
  'abbreviation': 'rxdk',
  'explanation': '快痛快。指坏人坏事受到惩罚或打击,使大家非常痛快。',
  'derivation': '明·沈德符《万历野获编·立枷》东山受恩反噬,其罪盖浮于诸龙光。当时人心大快,佐以此得缙绅闻声,然亦不云立枷。”',
  'example': '无'}]

3. 成语接龙

功能说明:

def next_idioms_solitaire(word, count=1, heteronym=True, smaller=False):
    """
    :param word: str, 成语
    :param count: int, 返回数量
    :param heteronym: bool,是否可以使用同音字
    :param smaller: bool, 是否选择尽可能的少的后续
    :return: list
    """

式例代码 1 :

idiom.next_idioms_solitaire('一生一世')
>>> ['逝将去汝']

式例代码 2 :

idiom.next_idioms_solitaire('一生一世', count=3, heteronym=False)
>>> ['世态炎凉', '世代书香', '世上无难事']

代码说明:获取可接『一生一世』的成语。返回最大数量为 3。不能用于同音字。

4. 判断两个成语是否能接龙。

示例代码:

idiom.is_idiom_solitaire('一生一世', '逝将去汝')
>>> True

idiom.is_idiom_solitaire('一生一世', '生生世世')
>>> False

5. 自动接龙模式。

输入一个汉字或者成语,程序自动输出一组成语接龙的结果。

功能说明:

def auto_idioms_solitaire(word, max_count=10, heteronym=True):
    """
    自动接龙模式 - 输入一个汉字或者成语,程序自动输出一组成语接龙的结果。
    :param word: str 起始汉字或者成语。
    :param max_count: int, 最大长度。默认最大长度:20。
    :param heteronym: bool, 是否可以用同音字。默认 True。
    :return: list
    """

示例代码:

idiom.auto_idioms_solitaire('一生一世')
>>>
["一生一世", "适心娱目", "目兔顾犬", "犬马之力", "立时三刻", "刻意经营", "蝇粪点玉", "鬻驽窃价", "驾轻就熟", "熟路轻辙"]

资源文件

Lincese

MIT License

Copyright (c) 2019  Thunder Bouble

Release files for china-idiom 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for china-idiom 0.0.3
File Size Uploaded
china_idiom-0.0.3.tar.gz 4.3 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for china-idiom 0.0.3
File Interpreter ABI Platform
china_idiom-0.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 8.5 MB

Release files / china_idiom-0.0.3.tar.gz

Download URL china_idiom-0.0.3.tar.gz
Size 4.3 MB
Tags Source
SHA-256 checksum
How to use checksums
9a8fd81317019039632f4277c95c18781ea738fd42fb78f0f0fef430092483e9
BLAKE2b-256 checksum
How to use checksums
d606c51d4321606586e7d38205546d5c6cbda2fdcf0f8ffc5499c422a67e89fb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3

Release files / china_idiom-0.0.3-py3-none-any.whl

Download URL china_idiom-0.0.3-py3-none-any.whl
Size 4.3 MB
Tags Python 3
SHA-256 checksum
How to use checksums
95b0685c88fb42eed93c46e0c5473c6a9c5c8340f201f348488169a9813123d8
BLAKE2b-256 checksum
How to use checksums
439eeb799e7d7523ca9409b1ba01e784c2cf8bc826fb1b4f1bc80129661ba44c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3

Release history Release notifications | RSS feed

This release

0.0.3 This release

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page