6c1a69af0d
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
73 lines
1.9 KiB
Python
73 lines
1.9 KiB
Python
"""
|
|
基础功能测试
|
|
"""
|
|
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
sys.path.insert(0, str(Path(__file__).parent.parent))
|
|
|
|
def test_imports():
|
|
"""测试模块导入"""
|
|
try:
|
|
from src.preprocessing.text_processor import TextProcessor
|
|
from src.preprocessing.document_parser import DocumentParser
|
|
from src.ontology.schema import OntologySchema
|
|
from src.prompts.ner_prompts import NERPromptBuilder
|
|
from src.extraction.ner import NERExtractor
|
|
from src.kg_builder.graph import KnowledgeGraph
|
|
print("✅ 所有模块导入成功")
|
|
return True
|
|
except ImportError as e:
|
|
print(f"❌ 模块导入失败: {e}")
|
|
return False
|
|
|
|
|
|
def test_ontology():
|
|
"""测试本体模型"""
|
|
try:
|
|
from src.ontology.schema import OntologySchema
|
|
|
|
schema = OntologySchema()
|
|
summary = schema.get_schema_summary()
|
|
|
|
assert summary["entity_types"] == 9
|
|
assert summary["relation_types"] == 8
|
|
print("✅ 本体模型测试通过")
|
|
return True
|
|
except Exception as e:
|
|
print(f"❌ 本体模型测试失败: {e}")
|
|
return False
|
|
|
|
|
|
def test_prompt_template():
|
|
"""测试Prompt模板"""
|
|
try:
|
|
from src.prompts.template import PromptTemplate
|
|
|
|
template = PromptTemplate(
|
|
task_description={"system": "test", "user": "test"},
|
|
candidate_targets={"entity": "definition"},
|
|
task_examples=[{"input": "test", "output": "test"}],
|
|
task_emphasis="test",
|
|
)
|
|
|
|
assert template.task_description is not None
|
|
print("✅ Prompt模板测试通过")
|
|
return True
|
|
except Exception as e:
|
|
print(f"❌ Prompt模板测试失败: {e}")
|
|
return False
|
|
|
|
|
|
if __name__ == "__main__":
|
|
print("开始运行基础测试...")
|
|
test_imports()
|
|
test_ontology()
|
|
test_prompt_template()
|
|
print("测试完成!")
|
|
|
|
|
|
|
|
|