nikeshn commited on
Commit
fdc4c4b
·
verified ·
1 Parent(s): 9ffc6ef

Create staff_service.py

Browse files
Files changed (1) hide show
  1. src/services/staff_service.py +88 -0
src/services/staff_service.py ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import re
2
+ from typing import Dict, Optional, List
3
+
4
+ STAFF_DIRECTORY = [
5
+ {
6
+ "full_name": "Dr. Abdulla Al Hefeiti",
7
+ "role": "Library Director / Assistant Provost, Libraries",
8
+ "details": "He can help with strategic and institutional matters, library leadership, and partnerships. Email: abdulla.alhefeiti@ku.ac.ae | Phone: +971 2 312 3331",
9
+ "tokens": ["abdulla", "hefeiti", "abdulla al hefeiti", "al hefeiti"],
10
+ },
11
+ {
12
+ "full_name": "Nikesh Narayanan",
13
+ "role": "Research & Access Services Librarian",
14
+ "details": "He can help with research support, Khazna institutional repository, ORCID, SciVal, Scopus, research impact, AI tools for research, bibliometrics, scholarly communication, and LibGuides. Email: nikesh.narayanan@ku.ac.ae | Phone: +971 2 312 3980",
15
+ "tokens": ["nikesh", "narayanan", "nikesh narayanan"],
16
+ },
17
+ {
18
+ "full_name": "Rani Anand",
19
+ "role": "E-Resources Librarian",
20
+ "details": "She can help with database access problems, e-resources troubleshooting, remote access, vendor issues, patents, e-books, and bibliometrics. Email: rani.anand@ku.ac.ae | Phone: +971 2 312 3935",
21
+ "tokens": ["rani", "anand", "rani anand"],
22
+ },
23
+ {
24
+ "full_name": "Jason Fetty",
25
+ "role": "Medical Librarian",
26
+ "details": "He can help with medical and health sciences research, systematic reviews, PubMed, Embase, CINAHL, UpToDate, and clinical databases. Email: jason.fetty@ku.ac.ae | Phone: +971 2 312 4722",
27
+ "tokens": ["jason", "fetty", "jason fetty"],
28
+ },
29
+ {
30
+ "full_name": "Walter Brian Hall",
31
+ "role": "Digital & Technology Services Librarian / Systems Librarian",
32
+ "details": "He can help with library website, systems, technology, digital infrastructure, ORCID, STEAM, coding, Open Access publishing, APC funding, general library services, and public services. Email: walter.hall@ku.ac.ae | Phone: +971 2 312 3163",
33
+ "tokens": ["walter", "brian", "hall", "walter brian hall", "walter hall", "brian hall"],
34
+ },
35
+ ]
36
+
37
+ # Role index
38
+ _role_index = {}
39
+
40
+ def build_staff_index():
41
+ """Build search index for staff roles"""
42
+ global _role_index
43
+ _role_index = {}
44
+ for staff in STAFF_DIRECTORY:
45
+ key = re.sub(r"[^a-z0-9]+", " ", staff["full_name"].lower()).strip()
46
+ _role_index[key] = staff
47
+
48
+ # Add role variations
49
+ role = staff["role"].lower()
50
+ if "medical" in role:
51
+ _role_index["medical librarian"] = staff
52
+ if "research" in role:
53
+ _role_index["research librarian"] = staff
54
+ if "digital" in role or "systems" in role:
55
+ _role_index["systems librarian"] = staff
56
+ _role_index["technology"] = staff
57
+
58
+ def _normalize_name_query(text: str):
59
+ return [t for t in re.sub(r"[^a-z0-9 ]+", " ", (text or "").lower()).split() if t]
60
+
61
+ def match_staff_name(question: str) -> Optional[Dict]:
62
+ tokens = _normalize_name_query(question)
63
+ if not tokens:
64
+ return None
65
+ for staff in STAFF_DIRECTORY:
66
+ staff_tokens = set()
67
+ for tok in staff.get("tokens", []):
68
+ staff_tokens.update(_normalize_name_query(tok))
69
+ if all(tok in staff_tokens for tok in tokens):
70
+ return staff
71
+ return None
72
+
73
+ def match_staff_role(question: str) -> Optional[Dict]:
74
+ q = re.sub(r"[^a-z0-9]+", " ", question.lower()).strip()
75
+ if q in _role_index:
76
+ return _role_index[q]
77
+
78
+ # Partial match
79
+ for alias, staff in _role_index.items():
80
+ if len(alias) > 4 and alias in q:
81
+ return staff
82
+ return None
83
+
84
+ def staff_name_answer(staff: Dict) -> str:
85
+ return f"Did you mean <strong>{staff['full_name']}</strong>?<br><br><strong>{staff['full_name']}</strong> is the <strong>{staff['role']}</strong>. {staff['details']}"
86
+
87
+ def staff_role_answer(staff: Dict, question: str) -> str:
88
+ return f"For <strong>{question}</strong>, the best match is <strong>{staff['full_name']}</strong> — <strong>{staff['role']}</strong>.<br><br>{staff['details']}"