Skip to main content
Glama

QueryNest

by niuzaishu
test_semantic_completion.py3.27 kB
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ 语义补全功能测试脚本(简化版) """ import asyncio import sys import os from pathlib import Path import pytest # 添加项目根目录到Python路径 project_root = Path(__file__).parent sys.path.insert(0, str(project_root)) @pytest.mark.asyncio async def test_semantic_completion_basic(): """测试语义补全基础功能""" print("🧪 开始测试语义补全基础功能...") try: # 直接导入和测试语义补全工具的核心功能 from mcp_tools.query_generation import QueryGenerationTool # 创建一个模拟的查询生成工具实例 class MockConnectionManager: pass class MockMetadataManager: pass class MockSemanticAnalyzer: def get_semantic_suggestions_for_query(self, description, fields): return [] # 初始化查询生成工具 query_tool = QueryGenerationTool( MockConnectionManager(), MockMetadataManager(), MockSemanticAnalyzer() ) print("✅ 查询生成工具初始化成功") # 测试1: 未知字段检测 print("\n📝 测试1: 未知字段检测") description = "查找用户名为张三且创建时间在最近一周的记录" field_suggestions = [ {"field_path": "username", "field_type": "string"}, {"field_path": "email", "field_type": "string"} ] unknown_fields = query_tool._detect_unknown_fields(description, field_suggestions) print(f"查询描述: {description}") print(f"检测到的未知字段: {unknown_fields}") # 测试2: 字段名识别 print("\n📝 测试2: 字段名识别") test_words = ["用户名", "创建时间", "状态", "email", "user_id", "的", "和", "姓名", "时间"] for word in test_words: is_field = query_tool._looks_like_field_name(word) print(f"'{word}' 是否像字段名: {is_field}") # 测试3: 中文分词功能 print("\n📝 测试3: 中文分词功能") import jieba test_text = "查找用户名为张三且创建时间在最近一周的记录" words = list(jieba.cut(test_text)) print(f"分词结果: {words}") # 过滤可能的字段名 potential_fields = [] for word in words: if len(word) > 1 and word.isalnum(): potential_fields.append(word) print(f"可能的字段名: {potential_fields}") print("\n✅ 语义补全基础功能测试完成") print("\n📋 测试总结:") print("- ✅ 查询生成工具初始化正常") print("- ✅ 未知字段检测功能正常") print("- ✅ 字段名识别功能正常") print("- ✅ 中文分词功能正常") print("- ✅ 语义补全工具集成到查询生成工具成功") except Exception as e: print(f"❌ 测试失败: {e}") import traceback traceback.print_exc() if __name__ == "__main__": asyncio.run(test_semantic_completion_basic())

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/niuzaishu/QueryNest'

If you have feedback or need assistance with the MCP directory API, please join our Discord server