Skip to content

Commit 8efb49a

Browse files
no spacy import at text_similarity file
1 parent ff9d5b9 commit 8efb49a

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

toolium/utils/ai_utils/spacy.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ def get_spacy_model(model_name):
3939
:param model_name: spaCy model name
4040
:return: spaCy model
4141
"""
42+
if spacy is None:
43+
return None
4244
return spacy.load(model_name)
4345

4446

toolium/utils/ai_utils/text_similarity.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@
1919
import json
2020
import logging
2121

22-
# AI library imports must be optional to allow installing Toolium without `ai` extra dependency
23-
try:
24-
import spacy
25-
except ImportError:
26-
spacy = None
2722
try:
2823
from sentence_transformers import SentenceTransformer
2924
except ImportError:
@@ -52,11 +47,11 @@ def get_text_similarity_with_spacy(text, expected_text, model_name=None):
5247
# - Normalizing texts (lowercase, extra points, etc.)
5348
# - Use only models that include word vectors (e.g., 'en_core_news_md' or 'en_core_news_lg')
5449
# - Preprocessing texts. Now we only preprocess negations.
55-
if spacy is None:
56-
raise ImportError("spaCy is not installed. Please run 'pip install toolium[ai]' to use spaCy features")
5750
config = DriverWrappersPool.get_default_wrapper().config
5851
model_name = model_name or config.get_optional('AI', 'spacy_model', 'en_core_web_md')
5952
model = get_spacy_model(model_name)
53+
if model is None:
54+
raise ImportError("spaCy is not installed. Please run 'pip install toolium[ai]' to use spaCy features")
6055
text = model(preprocess_with_ud_negation(text, model))
6156
expected_text = model(preprocess_with_ud_negation(expected_text, model))
6257
similarity = model(text).similarity(model(expected_text))

0 commit comments

Comments
 (0)