Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_create_multi_namespace():
test_registry = catalogue.create("x", "y")
@test_registry.register("z")
def z():
pass
items = test_registry.get_all()
assert len(items) == 1
assert items["z"] == z
assert catalogue.check_exists("x", "y", "z")
assert catalogue._get(("x", "y", "z")) == z
def test_create_single_namespace():
test_registry = catalogue.create("test")
assert catalogue.REGISTRY == {}
@test_registry.register("a")
def a():
pass
def b():
pass
test_registry.register("b", func=b)
items = test_registry.get_all()
assert len(items) == 2
assert items["a"] == a
assert items["b"] == b
assert catalogue.check_exists("test", "a")
assert catalogue.check_exists("test", "b")
def test_registry_get_set():
test_registry = catalogue.create("test")
with pytest.raises(catalogue.RegistryError):
test_registry.get("foo")
test_registry.register("foo", func=lambda x: x)
assert "foo" in test_registry
def test_entry_points():
# Create a new EntryPoint object by pretending we have a setup.cfg and
# use one of catalogue's util functions as the advertised function
ep_string = "[options.entry_points]test_foo\n bar = catalogue:check_exists"
ep = catalogue.importlib_metadata.EntryPoint._from_text(ep_string)
catalogue.AVAILABLE_ENTRY_POINTS["test_foo"] = ep
assert catalogue.REGISTRY == {}
test_registry = catalogue.create("test", "foo", entry_points=True)
entry_points = test_registry.get_entry_points()
assert "bar" in entry_points
assert entry_points["bar"] == catalogue.check_exists
assert test_registry.get_entry_point("bar") == catalogue.check_exists
assert catalogue.REGISTRY == {}
assert test_registry.get("bar") == catalogue.check_exists
assert test_registry.get_all() == {"bar": catalogue.check_exists}
assert "bar" in test_registry
cupy = None
from .symbols import ORTH
from .compat import cupy, CudaStream, path2str, basestring_, unicode_
from .compat import import_file
from .errors import Errors, Warnings, deprecation_warning
_data_path = Path(__file__).parent / "data"
_PRINT_ENV = False
class registry(object):
languages = catalogue.create("spacy", "languages", entry_points=True)
architectures = catalogue.create("spacy", "architectures", entry_points=True)
lookups = catalogue.create("spacy", "lookups", entry_points=True)
factories = catalogue.create("spacy", "factories", entry_points=True)
displacy_colors = catalogue.create("spacy", "displacy_colors", entry_points=True)
def set_env_log(value):
global _PRINT_ENV
_PRINT_ENV = value
def lang_class_is_loaded(lang):
"""Check whether a Language class is already loaded. Language classes are
loaded lazily, to avoid expensive setup code associated with the language
data.
lang (unicode): Two-letter language code, e.g. 'en'.
RETURNS (bool): Whether a Language class has been loaded.
import cupy.random
except ImportError:
cupy = None
from .symbols import ORTH
from .compat import cupy, CudaStream, path2str, basestring_, unicode_
from .compat import import_file
from .errors import Errors, Warnings, deprecation_warning
_data_path = Path(__file__).parent / "data"
_PRINT_ENV = False
class registry(object):
languages = catalogue.create("spacy", "languages", entry_points=True)
architectures = catalogue.create("spacy", "architectures", entry_points=True)
lookups = catalogue.create("spacy", "lookups", entry_points=True)
factories = catalogue.create("spacy", "factories", entry_points=True)
displacy_colors = catalogue.create("spacy", "displacy_colors", entry_points=True)
def set_env_log(value):
global _PRINT_ENV
_PRINT_ENV = value
def lang_class_is_loaded(lang):
"""Check whether a Language class is already loaded. Language classes are
loaded lazily, to avoid expensive setup code associated with the language
data.
import prodigy
from prodigy.components.db import connect
from prodigy.util import log, split_string, set_hashes, TASK_HASH_ATTR, INPUT_HASH_ATTR
import murmurhash
from sense2vec import Sense2Vec
import srsly
import spacy
import random
from wasabi import msg
from collections import defaultdict, Counter
import copy
import catalogue
# fmt: off
eval_strategies = catalogue.create("prodigy", "sense2vec.eval")
EVAL_EXCLUDE_SENSES = ("SYM", "MONEY", "ORDINAL", "CARDINAL", "DATE", "TIME",
"PERCENT", "QUANTITY", "NUM", "X", "PUNCT")
# fmt: on
@prodigy.recipe(
"sense2vec.teach",
dataset=("Dataset to save annotations to", "positional", None, str),
vectors_path=("Path to pretrained sense2vec vectors", "positional", None, str),
seeds=("One or more comma-separated seed phrases", "option", "se", split_string),
threshold=("Similarity threshold for sense2vec", "option", "t", float),
n_similar=("Number of similar items to get at once", "option", "n", int),
batch_size=("Batch size for submitting annotations", "option", "bs", int),
case_sensitive=("Show the same terms with different casing", "flag", "CS", bool),
resume=("Resume from existing phrases dataset", "flag", "R", bool),
)
import catalogue
class registry(object):
optimizers = catalogue.create("thinc", "optimizers", entry_points=True)
schedules = catalogue.create("thinc", "schedules", entry_points=True)
layers = catalogue.create("thinc", "layers", entry_points=True)
@classmethod
def get(cls, name, key):
if not hasattr(cls, name):
raise ValueError("Unknown registry: %s" % name)
reg = getattr(cls, name)
func = reg.get(key)
if func is None:
raise ValueError("Could not find %s in %s" % (name, key))
return func
@classmethod
def make_optimizer(name, args, kwargs):
func = cls.optimizers.get(name)
return func(*args, **kwargs)
import re
from spacy.tokens import Doc, Token, Span
from spacy.util import filter_spans
from thinc.neural.util import get_array_module
import catalogue
try:
import importlib.metadata as importlib_metadata # Python 3.8
except ImportError:
import importlib_metadata # noqa: F401
class registry(object):
make_key = catalogue.create("sense2vec", "make_key")
split_key = catalogue.create("sense2vec", "split_key")
make_spacy_key = catalogue.create("sense2vec", "make_spacy_key")
get_phrases = catalogue.create("sense2vec", "get_phrases")
merge_phrases = catalogue.create("sense2vec", "merge_phrases")
@registry.make_key.register("default")
def make_key(word: str, sense: str) -> str:
"""Create a key from a word and sense, e.g. "usage_example|NOUN".
word (unicode): The word.
sense (unicode): The sense.
RETURNS (unicode): The key.
"""
text = re.sub(r"\s", "_", word)
return text + "|" + sense
from typing import Union, List, Tuple, Set
import re
from spacy.tokens import Doc, Token, Span
from spacy.util import filter_spans
from thinc.neural.util import get_array_module
import catalogue
try:
import importlib.metadata as importlib_metadata # Python 3.8
except ImportError:
import importlib_metadata # noqa: F401
class registry(object):
make_key = catalogue.create("sense2vec", "make_key")
split_key = catalogue.create("sense2vec", "split_key")
make_spacy_key = catalogue.create("sense2vec", "make_spacy_key")
get_phrases = catalogue.create("sense2vec", "get_phrases")
merge_phrases = catalogue.create("sense2vec", "merge_phrases")
@registry.make_key.register("default")
def make_key(word: str, sense: str) -> str:
"""Create a key from a word and sense, e.g. "usage_example|NOUN".
word (unicode): The word.
sense (unicode): The sense.
RETURNS (unicode): The key.
"""
text = re.sub(r"\s", "_", word)
return text + "|" + sense