Skip to content

Commit 72ca13f

Browse files
committed
context logging
1 parent 37d5c38 commit 72ca13f

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

backend/Context.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
from . import Affinity_strategy
2-
from typing import List
2+
import logging
3+
4+
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
5+
logger = logging.getLogger(__name__)
36

47
class Context():
58
def __init__(self, strategy: Affinity_strategy) -> None:
@@ -13,6 +16,22 @@ def strategy(self) -> Affinity_strategy:
1316
def strategy(self, strategy: Affinity_strategy) -> None:
1417
self.affinity_strategy = strategy
1518

16-
def use_affinity_algorithm(self, application_name, data: List, linkage, object_weight, verb_weight, distance_threshold, metric):
17-
return self.affinity_strategy.compute_affinity(application_name, data, linkage,object_weight, verb_weight, distance_threshold, metric)
19+
def use_affinity_algorithm(self, application_name, data, linkage, object_weight, verb_weight, distance_threshold, metric):
20+
logger.info(f"Using affinity algorithm with {self.strategy.__class__.__name__}")
21+
22+
if isinstance(self.strategy, Affinity_strategy.TfidfEmbeddingService):
23+
logger.info("Calling TF-IDF affinity computation.")
24+
25+
result = self.strategy.compute_affinity(application_name,
26+
data,
27+
linkage,
28+
object_weight,
29+
verb_weight,
30+
distance_threshold,
31+
metric)
32+
if result is None:
33+
logger.error("Affinity algorithm returned None. Possible recursion issue.")
34+
raise RuntimeError("Affinity algorithm failed.")
35+
36+
return result
1837

0 commit comments

Comments
 (0)