Feature/ontology class clean (#249)

* [add] Complete ontology engineering feature implementation

* [add] Add ontology feature integration and validation utilities

* [add] Add OWL validator and validation utilities

* [fix] Add missing render_ontology_extraction_prompt function

* [fix]Add dependencies, fix functionality
This commit is contained in:
乐力齐
2026-01-30 15:16:39 +08:00
committed by GitHub
parent e7370489e8
commit 696b0475a8
20 changed files with 5825 additions and 0 deletions

View File

@@ -28,6 +28,10 @@ from .tool_model import (
ToolExecution, ToolType, ToolStatus, AuthType, ExecutionStatus
)
from .memory_perceptual_model import MemoryPerceptualModel
from .ontology_scene import OntologyScene
from .ontology_class import OntologyClass
from .ontology_scene import OntologyScene
from .ontology_class import OntologyClass
__all__ = [
"Tenants",

View File

@@ -0,0 +1,40 @@
# -*- coding: utf-8 -*-
"""本体类型模型
本模块定义本体类型的数据模型。
Classes:
OntologyClass: 本体类型表模型
"""
import datetime
import uuid
from sqlalchemy import Column, String, DateTime, Text, ForeignKey
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.orm import relationship
from app.db import Base
class OntologyClass(Base):
"""本体类型表 - 用于存储某个场景提取出来的本体类型信息"""
__tablename__ = "ontology_class"
# 主键
class_id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4, index=True, comment="类型ID")
# 类型信息
class_name = Column(String(200), nullable=False, comment="类型名称")
class_description = Column(Text, nullable=True, comment="类型描述")
# 外键:关联到本体场景
scene_id = Column(UUID(as_uuid=True), ForeignKey("ontology_scene.scene_id", ondelete="CASCADE"), nullable=False, index=True, comment="所属场景ID")
# 时间戳
created_at = Column(DateTime, default=datetime.datetime.now, nullable=False, comment="创建时间")
updated_at = Column(DateTime, default=datetime.datetime.now, onupdate=datetime.datetime.now, nullable=False, comment="更新时间")
# 关系:类型属于某个场景
scene = relationship("OntologyScene", back_populates="classes")
def __repr__(self):
return f"<OntologyClass(id={self.class_id}, name={self.class_name}, scene_id={self.scene_id})>"

View File

@@ -0,0 +1,43 @@
# -*- coding: utf-8 -*-
"""本体场景模型
本模块定义本体场景的数据模型。
Classes:
OntologyScene: 本体场景表模型
"""
import datetime
import uuid
from sqlalchemy import Column, String, DateTime, Integer, Text, ForeignKey, UniqueConstraint
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.orm import relationship
from app.db import Base
class OntologyScene(Base):
"""本体场景表 - 用于存储本体场景下不同的类型信息"""
__tablename__ = "ontology_scene"
__table_args__ = (
UniqueConstraint('workspace_id', 'scene_name', name='uq_workspace_scene_name'),
)
# 主键
scene_id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4, index=True, comment="场景ID")
# 场景信息
scene_name = Column(String(200), nullable=False, comment="场景名称")
scene_description = Column(Text, nullable=True, comment="场景描述")
# 外键:关联到工作空间
workspace_id = Column(UUID(as_uuid=True), ForeignKey("workspaces.id", ondelete="CASCADE"), nullable=False, index=True, comment="所属工作空间ID")
# 时间戳
created_at = Column(DateTime, default=datetime.datetime.now, nullable=False, comment="创建时间")
updated_at = Column(DateTime, default=datetime.datetime.now, onupdate=datetime.datetime.now, nullable=False, comment="更新时间")
# 关系:一个场景可以有多个类型
classes = relationship("OntologyClass", back_populates="scene", cascade="all, delete-orphan")
def __repr__(self):
return f"<OntologyScene(id={self.scene_id}, name={self.scene_name})>"