File size: 2,258 Bytes
0fd5c5a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# ==========================================================
# PATHOGENAGENT - MODULE 1: INTENT ROUTER
# ==========================================================

import re
from typing import Dict, List, Tuple

class IntentRouter:
    """تشخیص نوع سوال و تعیین ابزارهای مورد نیاز"""
    
    def __init__(self):
        self.variant_patterns = [
            r'c\.[0-9]+[a-z]?[0-9]*',
            r'p\.[a-z][0-9]+[a-z]',
            r'rs[0-9]+',
            r'[a-z]+[0-9]+[a-z]',
            r'[A-Z][0-9]+[A-Z]'
        ]
        
        self.gene_list = [
            "brca1", "brca2", "cftr", "tp53", "egfr", "kras",
            "alk", "ros1", "her2", "apoe", "mlh1", "msh2",
            "pten", "atm", "chek2", "palb2", "vhl"
        ]
        
        self.pathogen_keywords = [
            "virus", "genome", "sequence", "organism", "strain",
            "sars", "cov", "ebola", "influenza", "mers", "hiv",
            "dengue", "zika", "tuberculosis", "malaria"
        ]
    
    def detect_intent(self, query: str) -> Dict:
        """تشخیص نوع سوال"""
        q = query.lower().strip()
        confidence = 0.0
        intent = "general"
        tools = ["PubMed"]
        
        # بررسی واریانت
        for pattern in self.variant_patterns:
            if re.search(pattern, q, re.IGNORECASE):
                confidence = 0.9
                intent = "variant"
                tools = ["PubMed", "ClinVar"]
                break
        
        # بررسی ژن
        if confidence < 0.7:
            for gene in self.gene_list:
                if gene in q:
                    confidence = 0.7
                    intent = "gene"
                    tools = ["PubMed", "Gene"]
                    break
        
        # بررسی پاتوژن
        if confidence < 0.5:
            for keyword in self.pathogen_keywords:
                if keyword in q:
                    confidence = 0.8
                    intent = "pathogen"
                    tools = ["PubMed", "GenBank"]
                    break
        
        return {
            "query": query,
            "intent": intent,
            "confidence": confidence,
            "required_tools": tools
        }