Entity Identificationn

Entity Identificationn

识别两组数据是否来自同一实体。

实体识别 Quick Start 指南

概述

该工具用于识别两组数据是否来自同一主体,支持MCP(模型上下文协议)。工具通过文本规范化和语言模型比较数据的精确和语义相等性。

安装

pip install genai

核心功能

  • 文本规范化处理
  • 精确和语义值比较
  • JSON结构智能遍历
  • 语义相似性评估

使用方法

基本示例

import json
import genai
import re

# 准备要比较的数据
json1 = {
    "name": "John Doe",
    "address": "123 Main St, Anytown, USA",
    "hobbies": ["reading", "hiking", "coding"]
}

json2 = {
    "name": "john doe",
    "address": "123 Main Street, Anytown, USA",
    "hobbies": ["coding", "hiking", "reading"]
}

# 比较JSON对象
comparison_results = compare_json(json1, json2)

# 生成最终匹配结果
model = genai.GenerativeModel("gemini-2.0-flash-thinking-exp")
result = model.generate_content("综合这些信息,你认为可以判断两个数据来自同一主体吗?" + 
                               json.dumps(comparison_results, ensure_ascii=False, indent=4))
print(result.text)

主要函数

  1. normalize_text(text) - 文本标准化处理
  2. compare_values(val1, val2) - 比较两个值的相似性
  3. compare_json(json1, json2) - 结构化比较两个JSON对象

联系方式

有任何问题,请通过以下方式联系: