def testCapitalization(self): tests = [] tests.append( TestCase.formVerb(SKey.REG, 'DISmiss', 'Dismisses', 'Dismissed','Dismissing') ) tests[-1].forms[SKey.INFINATIVE] = 'Dismiss' # override InflTestHelper's so test is correct tests.append( TestCase.formAdj(SKey.REG, 'Brainy', 'Brainier', 'Brainiest') ) tests.append( TestCase.formNoun(SKey.REG, 'FLY', 'FLIES',) ) for word in tests: infl_dict = lemminflect.getAllInflectionsOOV(word.base, word.upos) msg = '\n%s\nCorrect : %s\nFunction: %s' % (word.base, word.forms, infl_dict) self.assertTrue(word.inflectionsInDict(infl_dict), msg)
def sample_verb(tag_list, source_tag, source): tag_list = [tag for tag in tag_list if tag != source_tag] tag = rd.choice(tag_list) cand_list = getInflection(source, tag) if cand_list == []: cand_list = getAllInflectionsOOV(source, upos='VERB').values() if len(cand_list) > 0: cand = rd.choice(cand_list) else: cand = None return cand
def testUPOSLog(self): with self.assertLogs(): infl = lemminflect.getInflection('WORD', 'X') self.assertEqual(infl, ()) with self.assertLogs(): infls = lemminflect.getAllInflections('WORD', 'X') self.assertEqual(infls, {}) with self.assertLogs(): infls = lemminflect.getAllInflectionsOOV('WORD', 'X') self.assertEqual(infls, {}) token = self.nlp('testing')[0] self.assertEqual(token._.inflect('X'), 'testing')
def get_lemmas(word: str, pos: PartOfSpeech): word = word.lower() if (" " in word or "." in word): return JSONResponse (status_code = 200, content = {"message": "Input must contain only a single word without spaces or punctuation."}) # Get the basic lemma version of the word first lemmas = getLemma(word, pos) if len(lemmas) > 0: lemma = getLemma(word, pos)[0] else: lemma = word inflections = merge_inflections(getAllInflections(lemma, upos=pos), getAllInflectionsOOV(lemma, upos=pos)) return {"lemma": lemma, "inflections": inflections}
def __call__(self, sent, index): # get word if sent[index].org is not None: word = sent[index].org else: word = sent[index].lemma # get cand cand = None source = word.lower() if source != '': source_tag = sent[index].tag tag_list = [tag for tag in self.tag_list if tag != source_tag] tag = rd.choice(tag_list) cand_list = getInflection(source, tag) if cand_list == []: cand_list = getAllInflectionsOOV(source, upos='VERB').values() if len(cand_list) > 0: cand = rd.choice(cand_list) # replace to cand if cand is not None: if word.istitle(): cand = cand.title() sent[index].org = cand if ((index >= 1 and sent[index - 1].pos != 'AUX') and (index >= 2 and sent[index - 2].pos != 'AUX') and self.sampler() < self.aux_ratio ): # 直前にAUXがなくVBG, VBNなら"have (been)"の変化を直前に挿入する if tag == 'VBG': sent[index].addition.append( EnToken(index=sent[index].index - 0.25, org=self.vbg_sampler())) elif tag == 'VBN': sent[index].addition.append( EnToken(index=sent[index].index - 0.25, org=self.vbn_sampler())) sent[index] = self.add_history(sent[index]) return sent
def testUPosException(self): self.assertEqual(lemminflect.getAllInflectionsOOV('test', 'X'), {})
def api_getAllInflectionsOOV(): content = request.json result = getAllInflectionsOOV(content['lemma'], content['upos']) return jsonify(result)