def test_detect_misrecognition(self): coy = cotohappy.API() sentence = '温泉認識は誤りを起こす' detect_misrecognition = coy.detect_misrecognition(sentence) self.assertEqual('0.9999968696704667', str(detect_misrecognition)) self.assertEqual('温泉\t 0,2,0.9999968696704667,音声,厭戦,怨念,おんねん,モンセン', str(detect_misrecognition.candidates[0]))
def test_user_attribute(self): coy = cotohappy.API() document = '私は昨日田町駅で飲みに行ったら奥さんに怒られた。' kuzure = False user_attribute = coy.user_attribute(document, kuzure) self.assertEqual('60歳以上,既婚,*,*,*,*,*,*,*,*,*,ANIMAL,CAMERA,COOKING,FISHING,FORTUNE,*,*', str(user_attribute))
def test_sentiment(self): coy = cotohappy.API() sentence = '人生の春を謳歌しています' sentiment = coy.sentiment(sentence) self.assertEqual('Positive,0.19562121911742972', str(sentiment)) self.assertEqual({'安心', '喜ぶ', '*'}, set(str(sentiment.emotional_phrase[0]).split('\t')[-1][1:].split(',')))
def test_sentence_type(self): coy = cotohappy.API() sentence = 'あなたの名前は何ですか?' kuzure = False sentence_type = coy.sentence_type(sentence, kuzure) self.assertEqual('interrogative\t information-seeking,*,*,*,*', str(sentence_type))
def remove_filler(): text = request.args.get('text') coy = cotohappy.API() # text = "えーっと、それでは今からプレゼンを、始めさせていただこうかと思います。" do_segment = True remove_filler_li = coy.remove_filler(text, do_segment) for remove_filler in remove_filler_li: remove_filler = str(remove_filler) return re.sub('^\S+', '', remove_filler).lstrip()
def test_similarity(self): coy = cotohappy.API() s1 = '近くのレストランはどこですか?' s2 = 'このあたりの定食屋はどこにありますか?' kuzure = False similarity = coy.similarity(s1, s2, kuzure) self.assertEqual('0.88565135', str(similarity))
def test_ne(self): coy = cotohappy.API() sentence = '昨日は東京駅を利用した。' kuzure = False ne_li = coy.ne(sentence, kuzure) self.assertEqual('昨日\t 0,2,昨日,DAT,,*,basic', str(ne_li[0])) self.assertEqual('東京駅\t 3,6,東京駅,LOC,,*,basic', str(ne_li[1]))
def test_remove_filler(self): coy = cotohappy.API() text = 'えーーっと、あの、今日の打ち合わせでしたっけ。すみません、ちょっと、急用が入ってしまって。' do_segment = True remove_filler_li = coy.remove_filler(text, do_segment) self.assertEqual('えーっと、あの、今日の打ち合わせでしたっけ。\t 、今日の打ち合わせでしたっけ。', str(remove_filler_li[0])) self.assertEqual('すみません、ちょっと、急用が入ってしまって。\t すみません、急用が入ってしまって。', str(remove_filler_li[1]))
def test_coreference(self): coy = cotohappy.API() document = '太郎は友人です。彼は焼き肉を食べた。' kuzure = False do_segment = True coreference = coy.coreference(document, kuzure, do_segment) self.assertEqual('0', str(coreference.coreference[0])) self.assertEqual('彼\t 1,1,0,0', str(coreference.coreference[0].referents[1]))
def test_keyword(self): coy = cotohappy.API() document = 'レストランで昼食を食べた。' kuzure = False do_segment = True max_keyword_num = 2 keyword_li = coy.keyword(document, kuzure, do_segment, max_keyword_num) self.assertEqual('昼食\t 12.1121', str(keyword_li[0])) self.assertEqual('レストラン\t 9.42937', str(keyword_li[1]))
def test_parse(self): coy = cotohappy.API() sentence = '犬は歩く。' kuzure = False parse_li = coy.parse(sentence, kuzure) self.assertEqual('犬は\t 0,1,D,0,1,*,*,*,*,*', str(parse_li[0])) self.assertEqual('歩く。\t 1,-1,O,0,1,*,*,*,*,*', str(parse_li[1])) self.assertEqual('は\t 1,ハ,は,連用助詞,*,*,*,*,*', str(parse_li[0].tokens[1])) self.assertEqual('歩\t 2,アル,歩く,動詞語幹,K,*,*,*,*', str(parse_li[1].tokens[0]))
#!/usr/bin/env python3.8 # -*- coding: utf-8 -*- """ Created on Sun Oct 20 12:00:00 2019 COTOHA API for Python3.8 @author: Nicolas Toba Nozomi @id: 278mt """ import cotohappy if __name__ == '__main__': coy = cotohappy.API() document = 'レストランで昼食を食べた。' kuzure = False do_segment = True max_keyword_num = 2 keyword_li = coy.keyword(document, kuzure, do_segment, max_keyword_num) for keyword in keyword_li: print(keyword)
def get_kotonoha_story(): url = 'https://www.kotonohanoniwa.jp/page/product.html' res = requests.get(url) soup = BeautifulSoup(res.content, 'html.parser') p = soup.find_all('p', class_='mb24')[-1] return p.text if __name__ == '__main__': payload_fname = 'payload.json' """ if you prepare authority file for your account on Cotoha API, you can write such as: """ coy = cotohappy.API( payload_fname=payload_fname) # payload_fname's default: 'payload.json' """ so you can omit payload_fname: coy = cotohappy.API() """ """ or you can do another type: ACCESS_TOKEN_PUBLISH_URL = 'https://api.ce-cotoha.com/v1/oauth/accesstokens' API_BASE_URL = 'https://api.ce-cotoha.com/api/dev/' CLIENT_ID = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ123456' CLIENT_SECRET = '7890abcdefghijkl' coy = cotohappy.API( ACCESS_TOKEN_PUBLISH_URL, API_BASE_URL, CLIENT_ID, CLIENT_SECRET ) # you can confirm your Access Token Publish URL, API Base URL, Client ID, and Client secret on the website (https://api.ce-cotoha.com/home)