Fun chat for two robots

Source: Internet
Author: User

Two robots are Alma and Blur, this is the use of the free API provided by the Turing machine to achieve the function of two robot dialogue, the system automatically extracted from the Turing platform to provide intelligent chat library, you can also import their own knowledge base to make robots more personalized, more in line with your appetite, Turing device person Access document address http://www.tuling123.com/openapi/cloud/access_api.jsp

Package net.lxy520.tuling; Import Com.mashape.unirest.http.httpresponse;import Com.mashape.unirest.http.jsonnode;import  Com.mashape.unirest.http.Unirest;    public class Main {private static final String KEY = "91e71ab13d4f1be71de4a7ef1c1ec2ef";    private static final String BASEURL = "http://www.tuling123.com/openapi/api?key=" +key+ "&userid=";    Private static final String Alma = "Alma";      private static final String Blur = "Blur";        public static void Main (string[] args) {//First-time conversation String firstly = "Hello!";        System.out.println (alma+ "to" +blur+ "said:" +first);    New Main (). Communication (Alma, first); /** * Alma talks to Blur * @param user * @param text chat room content */public void communication (String us        Er, String text) {//construct access to Turing's address stringbuffer url = new StringBuffer ("");        Url.append (BASEURL);        Url.append (user);        Url.append ("&info="). Append (text); Output Log//System.out.println (URL.TOSTRing ());        Retrieving the conversation content String msg = getrobotmsg (url.tostring ());            if (alma.equals) {//If SYSTEM.OUT.PRINTLN is said to Alma (blur+ "to" +alma+ "said:" +msg ");        Communication (Blur, MSG);            } else if (blur.equals (user)) {//if Blur said System.out.println (alma+ "to" +blur+ "said:" +msg ");        Communication (Alma, MSG); }}/** * Retrieve the robot's answer * @param url Turing machine person full access address; with UserID and info * @return Robot answer */public String get robotmsg (String URL) {try {httpresponse<jsonnode> jsonnodehttpresponse = unirest.get (URL). Asjson            ();            String text = Jsonnodehttpresponse.getbody (). GetObject (). Get ("text"). ToString ();        return text;        } catch (Exception e) {return "I don't know!"; }    }}

Fun chat for two robots

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.