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_call_not_implemented(self):
class Dummy(SentenceEmbedding):
def embed(self, s): ...
sentence = 'I am a dog.'
with self.assertRaises(NotImplementedError):
Dummy(Tokenizer(), WordEmbedding()).__call__(sentence)
def test_embed_not_implemented(self):
class Dummy(SentenceEmbedding):
def __call__(self, s): ...
sentence = 'I am a dog.'
with self.assertRaises(NotImplementedError):
Dummy(Tokenizer(), WordEmbedding()).embed(sentence)
from typing import List
class Tokenizer(object):
def tokenize(self, sentence: str) -> List[str]:
raise NotImplementedError
class SimpleTokenizer(Tokenizer):
def __init__(self):
self.replace_tokens = str.maketrans({
'.': ' .',
'?': ' ?',
'!': ' !',
'(': ' ( ',
')': ' ) ',
})
def tokenize(self, sentence: str) -> List[str]:
return sentence.translate(self.replace_tokens).split()