This commit is contained in:
LASTA_DEV01\lasta
2026-05-19 20:31:52 +09:00
parent 00407e7a08
commit e260e5f218
104 changed files with 12898 additions and 1709 deletions

View File

@@ -12,12 +12,20 @@ class SemanticGraphQuery:
def __init__(self, session: Session):
self.session = session
def neighborhood(self, project_id: int, entity_id: int | None = None, limit: int = 120) -> dict[str, Any]:
def neighborhood(
self,
project_id: int,
entity_id: int | None = None,
limit: int = 120,
statuses: list[str] | None = None,
) -> dict[str, Any]:
query = (
select(models.Claim, models.Entity)
.join(models.Entity, models.Claim.subject_entity_id == models.Entity.id)
.where(models.Claim.project_id == project_id, models.Claim.status == "validated_claim")
.where(models.Claim.project_id == project_id)
)
if statuses is not None:
query = query.where(models.Claim.status.in_(statuses))
if entity_id is not None:
query = query.where(
(models.Claim.subject_entity_id == entity_id) | (models.Claim.object_entity_id == entity_id)
@@ -40,7 +48,9 @@ class SemanticGraphQuery:
"target": claim.object_entity_id,
"target_value": claim.object_value if not claim.object_entity_id else None,
"predicate": claim.predicate,
"status": claim.status,
"confidence": claim.confidence,
"last_seen_at": claim.last_seen_at.isoformat() if claim.last_seen_at else None,
"metadata": claim.metadata_json or {},
"object": object_payload,
}