from .base_agent import BaseAgent from rdflib import Graph, Namespace from typing import List, Dict import logging class InteractionAgent(BaseAgent): def __init__(self, rdf_graph: Graph, namespace: Namespace): super().__init__(rdf_graph, namespace) self.query_template = """ PREFIX ns: SELECT DISTINCT ?drug1 ?drug2 WHERE {{ ?drug1 ns:hasInteraction ?drug2 . FILTER(STRENDS(str(?drug1), "#{drug}") || STRENDS(str(?drug2), "#{drug}")) }} """ logging.debug("InteractionAgent initialized.") def get_interactions(self, drug_name: str) -> List[Dict[str, str]]: query = self.query_template.format(drug=drug_name) logging.info(f"Fetching interactions for {drug_name}") return self.query_ontology(query)