Skip to content

Commit 8cfcb7b

Browse files
authored
optional gensim; 3.11 support (#46)
* make gensim optional * make gensim optional * exception handling * change import logic * inspect.getargspac is removed from python 3.11
1 parent c1f71d2 commit 8cfcb7b

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

onir/interfaces/wordvec.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import tempfile
33
import zipfile
44
import numpy as np
5-
from gensim.models.keyedvectors import KeyedVectors
65
from onir import util
76
from onir.interfaces import plaintext
87

@@ -110,6 +109,11 @@ def wrapped(logger):
110109
with logger.duration(f'downloading {url}'):
111110
util.download(url, vocab_path)
112111
with logger.duration(f'loading binary {vocab_path}'):
112+
try:
113+
from gensim.models.keyedvectors import KeyedVectors
114+
except ModuleNotFoundError as mnfe:
115+
print("gensim needs to be installed for gensim_w2v_handler to work")
116+
raise mnfe
113117
vectors = KeyedVectors.load_word2vec_format(vocab_path, binary=True)
114118
vocab_path += '.txt'
115119
with logger.duration(f'saving text {vocab_path}'):

onir_pt/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,8 @@ def __str__(self):
522522

523523

524524
def _inject(cls, context={}):
525+
if not hasattr(inspect, 'getargspec'):
526+
inspect.getargspec = inspect.getfullargspec
525527
spec = inspect.getargspec(cls.__init__)
526528
args = []
527529
for arg in spec.args:

requirements.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ nltk>=3.4.5
2525
git+https://github.com/TREMA-UNH/trec-car-tools.git#subdirectory=python3
2626
sqlitedict>=1.6.0
2727
pytrec-eval-terrier>=0.5.1
28-
gensim>=3.7.3
2928
Cython>=0.29.2
3029
pyjnius>=1.2.1
3130
ir_datasets>=0.2.0
@@ -34,3 +33,6 @@ ir_measures>=0.2.1
3433
# misc
3534
pytools>=2018.5.2
3635
cached-property>=1.5.1
36+
37+
# optional:
38+
# gensim>=3.7.3

0 commit comments

Comments
 (0)