Code Monkey home page Code Monkey logo

calling-cotoha-api-from-matlab's Introduction

What is COTOHA API?

COTOHA API developed by NTT group provides natural language processing specialised in Japanese. See https://api.ce-cotoha.com/contents/index.html

COTOHA API is capable of various tasks (see https://api.ce-cotoha.com/contents/api-all.html for details) and some advanced capabilities are

  • Parsing
  • Reference Resolution
  • Keyword Extraction
  • Speech Recognition
  • Speech Synthesis
  • Summarization

I believe these capabilities to be fully functional, texts still need some preprocessing where MATLAB and Text Analytics Toolbox come in handy.

Calling COTOHA API from MATLAB

Step 0. Getting security tokens

Users need to use their own clientid and clientsecret.

clientid = 'input_your_Client_ID';
clientsecret = 'input_your_Client_secret';

url = 'https://api.ce-cotoha.com/v1/oauth/accesstokens';
options = weboptions('RequestMethod','post', 'MediaType','application/json');
Body = struct('grantType', 'client_credentials', ... 
          'clientId', clientid, ...
          'clientSecret', clientsecret);
tokens = webwrite(url, Body, options);

Step 1-1. Summarize documents

COTOHA API Reference provides the following example code

curl -X POST -H 'Content-Type:application/json;charset=UTF-8' -H 'Authorization:Bearer [Access Token]' -d '{"document":"前線が太平洋上に停滞しています。一方、高気圧が千島近海にあって、北日本から東日本をゆるやかに覆っています。関東地方は、晴れ時々曇り、ところにより雨となっています。東京は、湿った空気や前線の影響により、晴れ後曇りで、夜は雨となるでしょう。","sent_len":"1"}' [API Base URL]/nlp/beta/summary

In MATLAB this task can be done by the following code

documents = "前線が太平洋上に停滞しています。一方、高気圧が千島近海にあって、" ...
    + "北日本から東日本をゆるやかに覆っています。関東地方は、晴れ時々曇り、ところにより雨" ...
    + "となっています。東京は、湿った空気や前線の影響により、晴れ後曇りで、夜は雨となるでしょう。";

baseurl = 'https://api.ce-cotoha.com/api/dev/';
accesstoken = tokens.access_token;

Header = {'Content-Type', 'application/json;charset=UTF-8';
    'Authorization', ['Bearer ' accesstoken]};
Body = struct('document', documents, ... 
          'sent_len', '1');
options = weboptions('RequestMethod','post', ...
    'MediaType','application/json','HeaderFields', Header);

response = webwrite([baseurl 'nlp/beta/summary'], Body, options)
response = 
    result: '東京は、湿った空気や前線の影響により、晴れ後曇りで、夜は雨となるでしょう。'
    status: 0

The response contains a summary sentense of the provided documents. Other functionalities of COTOHA API can be called similarly.

calling-cotoha-api-from-matlab's People

Contributors

minoue-xx avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.