In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how to make an exclusive intelligent chat robot with java". Interested friends might as well take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how to make your own intelligent chat robot by java".
1. Demonstration of intelligent chat robot
Artificial intelligence has been a hot topic recently, but the application field of automatic artificial intelligence has been expanding continuously, and artificial intelligence will continue to be popularized and applied in people's life in the future. The chat robot in this blog post, written in java, can respond intelligently to your messages. It's an interesting gadget. The demonstration of the final effect is shown below.
two。 Introduction of Intelligent question answering platform API
This chat robot project uses Qingyun lesson's intelligent API to get information feedback by calling API.
The specific call format is as follows:
The% s of the http://api.qingyunke.com/api.php?key=free&appid=0&msg=%s passes in what we need to send to the robot, and we can get feedback on the result of the API call.
Key fixed parameter free
Appid is set to 0 for intelligent recognition.
Msg is the search keyword
Result indicates the returned status, and 0 indicates normal
The content of the information returned by content api
You can see that the data is returned as JSON.
3. Integrate third-party JSON open source libraries
Gson is a class library provided by Google, which can be used to handle the mapping between java objects and JSON data, and convert an JSON string into a java object. It is convenient for us to deal with the JSON format data returned by API. The following shows how to import the Gson class library into our project.
First of all, you can go to the official website to download the corresponding jar package, or get it by private message directly. After getting the jar package, find an all-English path to save it. The editor we use here is IDEA, so we use IDEA to demonstrate. If friends use other editors, the import method is similar. Open the following interface in IDEA, find the jar package and import it.
4. Intelligent Robot Project Framework Construction and Module Partition
Project construction: there are not too many requirements for the construction part, you only need to use IDEA to create a new ordinary java project.
The project module is built:
The model class is used to store the objects returned by the request.
The util class is used to store the utility classes used by the project, such as the HTTP request parsing class
The app class is used as an entry point for a robot project
The interface that the service class uses to implement the business
The two related entity classes are as follows:
Public class Request {private String key = "free"; private String appid = "0"; private String msg = ""; public Request () {} public Request (String msg) {this.msg = msg;} public String getKey () {return key;} public void setKey (String key) {this.key = key;} public String getAppid () {return appid } public void setAppid (String appid) {this.appid = appid;} public String getMsg () {return msg;} public void setMsg (String msg) {this.msg = msg;}} public class Response {private int code; private String content; public int getCode () {return code;} public void setCode (int code) {this.code = code } public String getContent () {return content;} public void setContent (String content) {this.content = content;}} 5. Encapsulate a robot HTTP tool class
The HTTP utility class is mainly used to request api and get the returned content.
Public class HttpUtils {public static String request (String api) {HttpURLConnection connection = null; int responseCode = 0; try {URL url = new URL (api); / / get the corresponding connection object connection = (HttpURLConnection) url.openConnection (); responseCode = connection.getResponseCode ();} catch (Exception e) {e.printStackTrace () } if
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 216
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.