Skip to content

Commit

Permalink
Merge pull request #549 from NatLibFi/update-dependencies-v0.56
Browse files Browse the repository at this point in the history
Update dependencies v0.56
  • Loading branch information
juhoinkinen committed Jan 17, 2022
2 parents 586adba + f6cf926 commit b894218
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 29 deletions.
10 changes: 8 additions & 2 deletions annif/backend/omikuji.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import shutil
import annif.util
from annif.suggestion import SubjectSuggestion, ListSuggestionResult
from annif.exception import NotInitializedException, NotSupportedException
from annif.exception import NotInitializedException, NotSupportedException, \
OperationFailedException
from . import backend
from . import mixins

Expand Down Expand Up @@ -40,7 +41,12 @@ def _initialize_model(self):
path = os.path.join(self.datadir, self.MODEL_FILE)
self.debug('loading model from {}'.format(path))
if os.path.exists(path):
self._model = omikuji.Model.load(path)
try:
self._model = omikuji.Model.load(path)
except RuntimeError:
raise OperationFailedException(
"Omikuji models trained on Annif versions older than "
"0.56 cannot be loaded. Please retrain your project.")
else:
raise NotInitializedException(
'model {} not found'.format(path),
Expand Down
4 changes: 2 additions & 2 deletions annif/backend/pav.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ def _suggest_train_corpus(source_project, corpus):
scores = coo_matrix((data, (row, col)),
shape=(ndocs, len(source_project.subjects)),
dtype=np.float32)
true = coo_matrix((np.ones(len(trow), dtype=np.bool), (trow, tcol)),
true = coo_matrix((np.ones(len(trow), dtype=bool), (trow, tcol)),
shape=(ndocs, len(source_project.subjects)),
dtype=np.bool)
dtype=bool)
return csc_matrix(scores), csc_matrix(true)

def _create_pav_model(self, source_project_id, min_docs, corpus):
Expand Down
9 changes: 2 additions & 7 deletions annif/backend/tfidf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,13 @@
import os.path
import tempfile
import annif.util
import gensim.similarities
from gensim.matutils import Sparse2Corpus
from annif.suggestion import VectorSuggestionResult
from annif.exception import NotInitializedException, NotSupportedException
from . import backend
from . import mixins

# Filter UserWarnings due to not-installed python-Levenshtein package
import warnings
with warnings.catch_warnings():
warnings.simplefilter('ignore')
import gensim.similarities
from gensim.matutils import Sparse2Corpus


class SubjectBuffer:
"""A file-backed buffer to store and retrieve subject text."""
Expand Down
2 changes: 1 addition & 1 deletion annif/eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def filter_pred_top_k(preds, limit):

masks = []
for pred in preds:
mask = np.zeros_like(pred, dtype=np.bool)
mask = np.zeros_like(pred, dtype=bool)
top_k = np.argsort(pred)[::-1][:limit]
mask[top_k] = True
masks.append(mask)
Expand Down
2 changes: 1 addition & 1 deletion annif/lexical/mllm.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def candidates_to_features(candidates, mdata):

matrix = np.zeros((len(candidates), len(Feature)), dtype=np.float32)
c_ids = [c.subject_id for c in candidates]
c_vec = np.zeros(mdata.related.shape[0], dtype=np.bool)
c_vec = np.zeros(mdata.related.shape[0], dtype=bool)
c_vec[c_ids] = True
broader = mdata.broader.multiply(c_vec).sum(axis=1)
narrower = mdata.narrower.multiply(c_vec).sum(axis=1)
Expand Down
5 changes: 2 additions & 3 deletions annif/lexical/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import collections
from rdflib import URIRef
from rdflib.namespace import SKOS
import numpy as np
from scipy.sparse import lil_matrix, csc_matrix


Expand All @@ -16,7 +15,7 @@ def get_subject_labels(graph, uri, properties, language):

def make_relation_matrix(graph, vocab, property):
n_subj = len(vocab.subjects)
matrix = lil_matrix((n_subj, n_subj), dtype=np.bool)
matrix = lil_matrix((n_subj, n_subj), dtype=bool)

for subj, obj in graph.subject_objects(property):
subj_id = vocab.subjects.by_uri(str(subj), warnings=False)
Expand All @@ -36,7 +35,7 @@ def make_collection_matrix(graph, vocab):
c_members[str(coll)].append(member_id)

c_matrix = lil_matrix((len(c_members), len(vocab.subjects)),
dtype=np.bool)
dtype=bool)

# populate the matrix for collection -> subject_id
for c_id, members in enumerate(c_members.values()):
Expand Down
4 changes: 2 additions & 2 deletions annif/suggestion.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,15 @@ def filter(self, subject_index, limit=None, threshold=0.0):
mask = (self._vector > threshold)
deprecated_ids = subject_index.deprecated_ids()
if limit is not None:
limit_mask = np.zeros_like(self._vector, dtype=np.bool)
limit_mask = np.zeros_like(self._vector, dtype=bool)
deprecated_set = set(deprecated_ids)
top_k_subjects = itertools.islice(
(subj for subj in self.subject_order
if subj not in deprecated_set), limit)
limit_mask[list(top_k_subjects)] = True
mask = mask & limit_mask
else:
deprecated_mask = np.ones_like(self._vector, dtype=np.bool)
deprecated_mask = np.ones_like(self._vector, dtype=bool)
deprecated_mask[deprecated_ids] = False
mask = mask & deprecated_mask
vsr = VectorSuggestionResult(self._vector * mask)
Expand Down
22 changes: 11 additions & 11 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,30 @@ def read(fname):
zip_safe=False,
python_requires='>=3.7',
install_requires=[
'connexion[swagger-ui]',
'connexion2[swagger-ui]',
'swagger_ui_bundle',
'flask>=1.0.4,<2',
'flask>=1.0.4,<3',
'flask-cors',
'click==7.1.*',
'click==8.0.*',
'click-log',
'joblib==1.0.1',
'joblib==1.1.0',
'nltk',
'gensim==4.0.*',
'scikit-learn==0.24.2',
'scipy==1.5.4',
'gensim==4.1.*',
'scikit-learn==1.0.2',
'scipy==1.7.*',
'rdflib>=4.2,<7.0',
'gunicorn',
'numpy==1.19.*',
'optuna==2.8.0',
'numpy==1.21.*',
'optuna==2.10.*',
'stwfsapy==0.3.*',
'python-dateutil',
],
tests_require=['py', 'pytest', 'requests'],
extras_require={
'fasttext': ['fasttext==0.9.2'],
'voikko': ['voikko'],
'nn': ['tensorflow-cpu==2.5.0', 'lmdb==1.2.1'],
'omikuji': ['omikuji==0.3.*'],
'nn': ['tensorflow-cpu==2.7.0', 'lmdb==1.3.0'],
'omikuji': ['omikuji==0.4.*'],
'yake': ['yake==0.4.5'],
'pycld3': ['pycld3'],
'dev': [
Expand Down

0 comments on commit b894218

Please sign in to comment.