Skip to main content

V5相关度算法

基于jieba的V5版中文文本相关度计算算法,提供精确的文本匹配和相关性评分。

功能特性

  • ✅ 基于jieba的中文分词和词性标注
  • ✅ 智能分词过滤,支持专业术语识别
  • ✅ 多维度相关度评分算法
  • ✅ 批量处理支持
  • ✅ 自动用户词典创建
  • ✅ 完全封装的类设计

安装

基础安装

pip install v5-relevance

完整安装(包含所有依赖)

pip install v5-relevance[full]

快速开始

from v5 import V5Relev

# 创建算法实例
v5 = V5Relev()

# 计算单个文本的相关度
content = "这是一个关于AI软件前端设计哲学的测试内容"
query = "AI软件前端设计"
score = v5.calculate_relevance_score(content, query)
print(f"相关度分数: {score}")

# 批量处理
notes = [
    (1, "AI软件前端设计哲学", "2025-10-30"),
    (2, "AI软件设计白皮书", "2025-10-29"), 
    (3, "从AI软件控件设计", "2025-10-28")
]

top_notes = v5.get_top_relevant_notes(notes, query, limit=2)
print("前2条相关笔记:")
for note in top_notes:
    print(f"  ID: {note[0]}, 分数: {note[3]}")

算法原理

V5相关度算法基于以下维度计算总匹配度:

  1. LIKE匹配 - 精确匹配、标题开头匹配、连续关键词匹配
  2. 标题关键词匹配 - 标题区域的关键词匹配计数
  3. 关键词紧密度 - 关键词在标题中的位置距离
  4. 内容匹配平均占比 - 基于词性权重的加权匹配占比

用户词典

算法会自动创建用户词典文件 user_dict.txt,包含:

  • 人名地名(元龙居士、北京、上海等)
  • 专业术语(LLM、API_KEY、BASE_URL等)
  • 技术名词(Python、JavaScript、Docker等)
  • 时间相关词(今天、明天、本周等)
  • 常见问题关键词

API文档

V5Relev 类

初始化

v5 = V5Relev(user_dict_path="user_dict.txt", debug=False)

方法

calculate_relevance_score(content, query, user_id=None)

  • 计算单个文本的相关度分数
  • 返回:浮点数相关度评分

get_top_relevant_notes(notes, query, limit=10)

  • 批量计算相关度并排序
  • 返回:按相关度降序排列的笔记列表

extract_core_keywords(tokens)

  • 提取核心关键词,过滤停用词

extract_content_words(tokens)

  • 提取内容关键词(名词、动词等实词)

依赖

  • Python >= 3.7
  • jieba >= 0.42.1

许可证

MIT License

贡献

欢迎提交Issue和Pull Request!

联系方式

Metadata

Release files for v5-relevance 1.1.4

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

Source distribution (sdist)

Source distribution for v5-relevance 1.1.4
File Size Uploaded Provenance
v5_relevance-1.1.4.tar.gz 12.1 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for v5-relevance 1.1.4
File Interpreter ABI Platform
v5_relevance-1.1.4-py3-none-any.whl Python 3 none any Details

Total release size: 23.8 kB

Release files / v5_relevance-1.1.4.tar.gz

Download URL v5_relevance-1.1.4.tar.gz
Size 12.1 kB
Tags Source
SHA-256 checksum
How to use checksums
3b50d60a36252f379327860ed69e46d78fc3844d23b3f169f513461b32c97bbb
BLAKE2b-256 checksum
How to use checksums
db115d8e007a730913f23273a72eeae6f5974f646ddd252c94b5149e5e54a042
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.12

Release files / v5_relevance-1.1.4-py3-none-any.whl

Download URL v5_relevance-1.1.4-py3-none-any.whl
Size 11.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
74b85c894ee6be1a95895200df2892861d21ff668e0567b43e1636074b73adda
BLAKE2b-256 checksum
How to use checksums
a940411d073fc53ec0ad8504435e826a11e7549fd426bda360d9de9ef4dc0cb5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.12

Security for v5-relevance 1.1.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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