Spaces:
Running
Running
Update src/visualization.py
Browse files- src/visualization.py +9 -6
src/visualization.py
CHANGED
@@ -182,15 +182,17 @@ def analyze_query_ontology_concepts(query: str, ontology_manager) -> Tuple[List[
|
|
182 |
Analyze the query to identify ontology concepts with confidence scores.
|
183 |
This is a simplified implementation that would be replaced with NLP in production.
|
184 |
"""
|
185 |
-
query_lower = query.lower()
|
186 |
|
187 |
# Entity detection
|
188 |
entity_mentions = []
|
189 |
classes = ontology_manager.get_classes()
|
190 |
|
191 |
for class_name in classes:
|
192 |
-
#
|
193 |
-
|
|
|
|
|
194 |
# Get class info
|
195 |
class_info = ontology_manager.ontology_data["classes"].get(class_name, {})
|
196 |
|
@@ -204,15 +206,16 @@ def analyze_query_ontology_concepts(query: str, ontology_manager) -> Tuple[List[
|
|
204 |
"description": class_info.get("description", "")
|
205 |
})
|
206 |
|
207 |
-
#
|
208 |
relationship_mentions = []
|
209 |
relationships = ontology_manager.ontology_data.get("relationships", [])
|
210 |
|
211 |
for rel in relationships:
|
212 |
rel_name = rel["name"]
|
213 |
|
214 |
-
#
|
215 |
-
|
|
|
216 |
# Assign confidence
|
217 |
confidence = min(0.9, 0.5 + (len(rel_name) / 20))
|
218 |
|
|
|
182 |
Analyze the query to identify ontology concepts with confidence scores.
|
183 |
This is a simplified implementation that would be replaced with NLP in production.
|
184 |
"""
|
185 |
+
query_lower = query.lower()
|
186 |
|
187 |
# Entity detection
|
188 |
entity_mentions = []
|
189 |
classes = ontology_manager.get_classes()
|
190 |
|
191 |
for class_name in classes:
|
192 |
+
# Use word boundary regex to improve matching
|
193 |
+
import re
|
194 |
+
pattern = r'\b' + re.escape(class_name.lower()) + r'\b'
|
195 |
+
if re.search(pattern, query_lower):
|
196 |
# Get class info
|
197 |
class_info = ontology_manager.ontology_data["classes"].get(class_name, {})
|
198 |
|
|
|
206 |
"description": class_info.get("description", "")
|
207 |
})
|
208 |
|
209 |
+
# Similar improvement for relationship detection
|
210 |
relationship_mentions = []
|
211 |
relationships = ontology_manager.ontology_data.get("relationships", [])
|
212 |
|
213 |
for rel in relationships:
|
214 |
rel_name = rel["name"]
|
215 |
|
216 |
+
# Use word boundary regex
|
217 |
+
pattern = r'\b' + re.escape(rel_name.lower()) + r'\b'
|
218 |
+
if re.search(pattern, query_lower):
|
219 |
# Assign confidence
|
220 |
confidence = min(0.9, 0.5 + (len(rel_name) / 20))
|
221 |
|