nth decoction
~~ 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.
You need requests.
windows
Linux
Mac
♰ I don't have ♰
2.2 Quick start
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.
GitHub
git clone https://github.com/tsuji-tomonori/cotohapy.git
from cotohapy3 import CotohaAPI
The library is all in "cotohapy3". There are other classes besides CotohaAPI
, but that will be later ...
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 |
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) |
#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) |
#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 formatsstr :Sentence to be analyzedlist :Sentence to be analyzed集合 |
**kwargs | Any other parameters(Official reference API reference) |
#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 formatsstr :Sentence to be analyzedlist :Sentence to be analyzed集合 |
**kwargs | Any other parameters(Official reference API reference) |
#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) |
#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
#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 formatsstr :Sentence to be analyzedlist :Sentence to be analyzed集合 |
**kwargs | Any other parameters(Official reference API reference) |
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) |
#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) |
#Execution example
api.sentiment("Enjoying the spring of life")
def sentiment(self, sentence)
argument | Data type | Contents |
---|---|---|
sentence | str | Analysis target sentence |
#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) |
I want to put out something I made
Or I want to explain a function that is not explained
Recommended Posts