def test_eq(self): word1 = Word("Hello", 0, 1) word2 = Word("Hello", 0, 1) word3 = Word("Hello World", 0, 2) assert word1 == word2 assert word1 != word3
def test_eq(self): sentence1 = LabeledSentence([Word("Hello", 0, 1)]) sentence2 = LabeledSentence([Word("Hello", 0, 1)]) sentence3 = LabeledSentence([Word("Hello World", 0, 2)]) assert sentence1 == sentence2 assert sentence1 != sentence3
def test_init(self): sentence = [Word(text="qi1shi2", begin=1, end=3)] spell = [Word(text="qi1", begin=1, end=3)] phone = [Word(text="q", begin=1, end=3)] labeledsentence = LabeledSentence( sentence=sentence, spell=spell, phone=phone, attributes={"gender": "male"} ) assert labeledsentence.sentence == list(sentence) assert labeledsentence.spell == list(spell) assert labeledsentence.phone == list(phone)
def test_dumps(self): sentence = [Word(text="qi1shi2", begin=1, end=3)] spell = [Word(text="qi1", begin=1, end=2)] phone = [Word(text="q", begin=1, end=1.5)] labeledsentence = LabeledSentence( sentence=sentence, spell=spell, phone=phone, attributes={"gender": "male"} ) labeledsentence.dumps = { "sentence": [{"text": "qi1shi2", "begin": 1, "end": 3}], "spell": [{"text": "qi1", "begin": 1, "end": 2}], "phone": [{"text": "q", "begin": 1, "end": 1.5}], "attributes": {"gender": "male"}, }
def _get_label(label_file: str) -> List[LabeledSentence]: with open(label_file, encoding="utf-8") as fp: labels = ((Word(text=text) for text in texts.split()) for texts in fp) return [LabeledSentence(*labels)]
def test_dumps(self): word = Word(text="Hello", begin=1, end=3) assert word.dumps() == {"text": "Hello", "begin": 1, "end": 3}
def test_loads(self): word = Word.loads({"text": "Hello", "begin": 1, "end": 3}) assert word.text == "Hello" assert word.begin == 1 assert word.end == 3
def test_init(self): word = Word(text="Hello", begin=1, end=3) assert word.text == "Hello" assert word.begin == 1 assert word.end == 3