I tried using the COTOHA API (there is code on GitHub)

0. Related articles

nth decoction

1. Background

~~ Because I learned about Present Planning. ~~

I personally wanted to do text analysis for a long time, so I decided to take this opportunity. However, when I looked it up, there was no official API for various languages. (This article belongs to the author. It's like NTT, but maybe this is the official theory)

So, I will try to make it after studying.

Link to COTOHA API Portal

2. Description of the created API

2.1 Operation confirmed environment

You need requests.

windows

Linux

Mac

♰ I don't have ♰

2.2 Quick start

  1. First, register for free at COTOHA API for Developers
  2. Execute the following command
git clone https://github.com/tsuji-tomonori/cotohapy.git
cd cotohapy
pip install -r requirements.txt
# config.Create json
python demo.py
#if,For python3 environment
python3 demo.py
# action!

config.json looks like this.



```json
{
    "access_token_publish_url": "",
    "developer_api_base_url": "",
    "clientid": "",
    "clientsecret": ""
}

When you go to the account home, the following page will appear, so please set it based on it. The correspondence table is attached below.

key.png

2.3 How to use

GitHub

git clone https://github.com/tsuji-tomonori/cotohapy.git

import

from cotohapy3 import CotohaAPI

The library is all in "cotohapy3". There are other classes besides CotohaAPI, but that will be later ...

Get Access Token

Be sure to go first.

api = CotohaAPI(
    developer_api_base_url=developer_api_base_url, 
    access_token_publish_url=access_token_publish_url
)
api.login(clientid=clientid, clientsecret=clientsecret)
def __init__(self, developer_api_base_url, access_token_publish_url)
argument Data type Contents
developer_api_base_url str API Base URL
access_token_publish_url str Access Token Publish URL
def login(self, clientid, clientsecret)
argument Data type Contents
clientid str Client ID
clientsecret str Client secret

Parsing (https://api.ce-cotoha.com/contents/reference/apireference.html): parse

#Execution example
api.parse("I ate yakiniku with my mother in Ginza yesterday")
def parse(self, sentence, **kwargs)
argument Data type Contents
sentence str Analysis target sentence
**kwargs Any other parameters(Official reference API reference)

Named entity extraction: `` `ne```

#Execution example
api.ne("I used Tokyo station yesterday.")
def ne(self, sentence, **kwargs)
argument Data type Contents
sentence str Analysis target sentence
**kwargs Any other parameters(Official reference API reference)

Resolution analysis: `` `coreference```

#Execution example
api.coreference("Taro is a friend. He ate grilled meat.")
def coreference(self, document, **kwargs)
argument Data type Contents
document str / list Specify in either of the following formats
str:Sentence to be analyzed
list:Sentence to be analyzed集合
**kwargs Any other parameters(Official reference API reference)

Keyword extraction: `` `keyword```

#Execution example
api.keyword("I had lunch at the restaurant.")
def keyword(self, document, **kwargs)
argument Data type Contents
document str / list Specify in either of the following formats
str:Sentence to be analyzed
list:Sentence to be analyzed集合
**kwargs Any other parameters(Official reference API reference)

Similarity calculation: `` `similarity```

#Execution example
api.similarity("Where is the restaurant nearby?", "Where are the set meal shops around here?")
def similarity(self, s1, s2, **kwargs)
argument Data type Contents
s1 str Text to be calculated for similarity
s2 str Text to be calculated for similarity
**kwargs Any other parameters(Official reference API reference)

Sentence type determination: `` `sentence_type```

#Execution example
api.sentence_type("What is your name?")
def sentence_type(self, sentence, **kwargs)
argument Data type Contents
sentence str Analysis target sentence
**kwargs Any other parameters(Official reference API reference)

User attribute estimation (β): user_attribute

#Execution example
api.user_attribute("When I went to drink at Tamachi station yesterday, my wife got angry.")
def user_attribute(self, document, **kwargs)
argument Data type Contents
document str / list Specify in either of the following formats
str:Sentence to be analyzed
list:Sentence to be analyzed集合
**kwargs Any other parameters(Official reference API reference)

Stagnation removal (β): remove_filler

#Execution example
api.remove_filler(
    "Well, was that the meeting today? I'm sorry, I have a little urgent need."
)
def remove_filler(self, text, **kwargs)
argument Data type Contents
text str Text to be analyzed
**kwargs Any other parameters(Official reference API reference)

Speech recognition error detection (β): `` `detect_misrecognition```

#Execution example
api.detect_misrecognition("Hot spring recognition makes mistakes")
def detect_misrecognition(self, sentence, **kwargs)
argument Data type Contents
sentence str Analysis target sentence
**kwargs nothing special(Just in case than the beta version)

Emotion analysis: `` `sentiment```

#Execution example
api.sentiment("Enjoying the spring of life")
def sentiment(self, sentence)
argument Data type Contents
sentence str Analysis target sentence

Summary (β): `` `summary```

#Execution example
with open("summary.txt", "r", encoding="utf-8") as f:
    document = f.read()
api.summary(document, 1)

summary.txt


The front is stagnant over the Pacific Ocean. On the other hand, there is an anticyclone in the sea near Chishima, which gently covers northern and eastern Japan. The Kanto region is sunny and sometimes cloudy, with some rain. Tokyo will be cloudy after sunny and rainy at night due to the effects of moist air and fronts.
def summary(self, document, sent_len, **kwargs)
argument Data type Contents
document str Input text
sent_len int Number of summary sentences
**kwargs nothing special(Just in case than the beta version)

3. Future plans

I want to put out something I made

Or I want to explain a function that is not explained

reference

pixivpy

Recommended Posts

I tried using the COTOHA API (there is code on GitHub)
I tried using the checkio API
I tried to touch the COTOHA API
I tried using the BigQuery Storage API
I tried using Remote API on GAE / J
I tried using the Google Cloud Vision API
I tried using the API of the salmon data project
I tried to score the syntax that was too humorous and humorous using the COTOHA API.
[First COTOHA API] I tried to summarize the old story
[Python] I tried collecting data using the API of wikipedia
[For beginners] I tried using the Tensorflow Object Detection API
I tried the Naro novel API 2
I tried the Naruro novel API
I tried to digitize the stamp stamped on paper using OpenCV
I tried using Twitter api and Line api
I tried using YOUTUBE Data API V3
I stumbled on the Hatena Keyword API
I tried using UnityCloudBuild API from Python
Play with puns using the COTOHA API
I tried to get the authentication code of Qiita API with Python.
I tried to summarize various sentences using the automatic summarization API "summpy"
I tried to extract and illustrate the stage of the story using COTOHA
Using COTOHA, I tried to follow the emotional course of Run, Melos!
I tried using scrapy for the first time
I checked the library for using the Gracenote API
I tried hitting the Qiita API from go
vprof --I tried using the profiler for Python
I tried using PyCaret at the fastest speed
I tried to touch the API of ebay
[Pythonocc] I tried using CAD on jupyter notebook
Try CIing the pushed python code on GitHub.
Output repository list using Github API on Mac
I tried using the Datetime module by Python
Until the Sphinx documentation is published on GitHub
I tried LINE Message API (line-bot-sdk-python) on GAE
I tried using the image filter of OpenCV
I tried using the functional programming library toolz
I tried playing with the calculator on tkinter
I tried using parameterized
I tried using argparse
I tried using mimesis
I tried using anytree
I tried Python on Mac for the first time.
I tried to notify the update of "Become a novelist" using "IFTTT" and "Become a novelist API"
I tried running the app on the IoT platform "Rimotte"
[Python] I immediately tried using Pylance's VS Code extension.
I tried using aiomysql
I tried using Summpy
I tried using coturn
I tried using Pipenv
I tried using matplotlib
I tried using "Anvil".
I tried using Hubot
I tried using ESPCN
[Linux] I tried using the genetic statistics software PLINK
I tried using openpyxl
I tried a visual regression test on GitHub Pages
I tried clustering ECG data using the K-Shape method
I tried using Ipython
I tried to approximate the sin function using chainer
I tried using PyCaret