API Practice: Write an auto-answer Web page with the Turing man API

Source: Internet
Author: User
Tags knowledge base

Turing platform is a free API open platform, based on natural language processing, knowledge base and cloud computing technology, for the vast number of developers, partners to provide a range of intelligent semantic processing capabilities (including semantic understanding, intelligent Quiz, knowledge base docking, etc.) service platform. API use Address:http://www.tuling123.com/openapi/record.do?channel=50044

Today, I made a simple real-time answer program with the Turing's Open API:)

robot.php:

<?phperror_reporting (0); $INFO =$_get[' INFO '];if (! $INFO) $INFO = "hello!"; $apiKey = "AAAAAAAAAAAAAAAAAAAAAAA"; Your appkey$apiurl= "http://www.tuling123.com/openapi/api?key= $apiKey &info= $INFO";//appkey address $cmd=file_get_ Contents ($apiURL);//echo $cmd. " <br> ";//output JSON format information (not in this instance) $tmp =json_decode ($cmd, 1), if ($tmp [code][0]!=" 4 ")//JSON decoding if there is no error (the return code starts with 4), The text message  {    Print_r ($tmp [text]) is displayed;  } else  {    echo "Error!error code is: $tmp [code]!];  }?>

Demo.html

<form> say:<input type= "text" id= "Robot" onkeyup= "Showhint (this.value)"/> Triggers an event to send an AJAX request when the keyboard strikes &LT;/FORM&G T;<p>ans: <span id= "Txthint" ></span></p> as Echo zone <script>var xmlhttpfunction Showhin    T (str) {if (str.length==0) {document.getElementById ("Txthint"). innerhtml= "";    Return } xmlhttp=getxmlhttpobject () if (xmlhttp==null) {alert ("Your browser does not support ajax!    ");    Return  } var url= "robot.php";  url=url+ "info=" +STR;  url=url+ "&sid=" +math.random ();  xmlhttp.onreadystatechange=statechanged;  Xmlhttp.open ("GET", url,true); Xmlhttp.send (null);} function statechanged () {if (xmlhttp.readystate==4) {document.getElementById ("Txthint"). innerhtml= Xmlhttp.responsetext;}}  function Getxmlhttpobject () {var xmlhttp=null;    try {//Firefox, Opera 8.0+, Safari xmlhttp=new XMLHttpRequest ();      } catch (E) {///Internet Explorer try {xmlhttp=new ActiveXObject ("msxml2.xmlhttp"); } catch (e) {     Xmlhttp=new ActiveXObject ("Microsoft.XMLHTTP"); }}return xmlHttp;} </script>


API Practice: Write an auto-answer Web page with the Turing man API

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.