Environment setup and project structure
Java artificial intelligence tutorial
Creating an AI sports chatbot with java
In part one of this series Artificial intelligence achieved through Java we took a look at what artificial intelligence is in software terms and at some examples of artificial intelligence systems in the market today. We also introduced the java AI chatbot tutorial and technologies that we will be working with, this article will focus on the setup of your development environment, technology stack and will explain the goals we want to achieve at the end of this tutorial.
Technology Stack
This is a list of all the technologies and languages that we will use throughout this tutorial:
- Java
- Eclipse IDE (Java EE Developers version)
- Maven
- PostgreSQL
- Wildfly 9.0.2
The goal we aim to achieve by the end of this tutorial is to create a sports chatbot using java AI concepts, the sports chatbot will be able to talk to you about sports matches coming up, completed matches, players in the team being discussed and make predictions on upcoming matches. At the end of this tutorial we want to have provided you with basic java AI knowledge and maybe introduce you to some new technology’s you may or may not have worked with in the past.
Download and Setup
Getting your environment ready to code
In order to save time and get you developing, I have listed links to download and setup tutorials for the technology stack mentioned above that are quick and easy to follow. If you have any trouble getting any of these technology’s and tools setup there is an extensive amount of documentation and video’s available online, as well as forums that can assist.
Download |
Setup |
Java 8 | Java setup tutorial |
Eclipse Java EE Developers | Eclipse setup tutorial |
Maven | Maven in 5 minutes setup tutorial |
PostgreSQL | Windows, Mac OS, Linux |
Wildfly 9.0.2 | Wildfly setup tutorial in Eclipse |
node js | run exe |
Angular JS | Angular JS plugin for Eclipse |
Bower | npm install -g bower |
Step 1: Maven project structure
Build automation made easy
Maven truly does make build automation easy, here is a link for more information: Maven Introduction
We are going to create the following project structure:
sportbot (top level maven project that will manage all our plugins)
sportbot-parent (parent project)
sportbot-API
sportbot-core
sportbot-datamodel
sportbot-rs (rest services)
Before creating the maven project structure above create a new workspace called sportbot, you can do this by creating a new folder on your machine where you would prefer to keep your Eclipse workspaces, then open Eclipse and browse to the newly created workspace sportbot.
1. Create the top level sportbot maven project
– Select file / new / Maven Project
– Check Create simple project (skip archetype selection) and click next
– Fill in the following fields
Group id: com.sportbot
Artifact id: sportbot
Version: 1.0.0-SNAPSHOT
Packaging: pom
click finish
– Open the new top level sportbot project, right click on the src folder and click delete
2. Create sportbot-parent project
– Right click on the sportbot project, select new / other / maven module and click next.
– Check Create simple project (skip archetype selection)
– Fill in the following
Module Name : sportbot-parent
Parent Project: sportbot
– Click next and fill in the following
Packaging: pom
– Click finish
– Open the new sportbot-parent project, right click on the src folder and click delete
3. Create sportbot-API layer
– Right click on the sportbot project, select new / other / maven module and click next.
– Check Create simple project (skip archetype selection)
– Fill in the following
Module Name: sportbot-API
Parent Project: sportbot
– Click next and fill in the following
Packaging: jar
– Click finish
– Open the new sportbot-api project, open the pom file
– The overview of the pom file is now open, click the open folder icon in the parent section to select a parent
– Select sportbot-parent and click okay.
4. Create sportbot-core layer
– Right click on the sportbot project, select new / other / maven module and click next.
– Check Create simple project (skip archetype selection)
– Fill in the following
Module Name : sportbot-core
Parent Project: sportbot
– Click next and fill in the following
Packaging: jar
– Click finish
– Open the new sportbot-core project, open the pom file
– The overview of the pom file is now open, click the open folder icon in the parent section to select a parent
– Select sportbot-parent and click okay.
5. Create sportbot-datamodel layer
– Right click on the sportbot project, select new / other / maven module and click next.
– Check Create simple project (skip archetype selection)
– Fill in the following
Module Name: sportbot-datamodel
Parent Project: sportbot
– Click next and fill in the following
Packaging: jar
– Click finish
– Open the new sportbot-datamodel project, open the pom file
– The overview of the pom file is now open, click the open folder icon in the parent section to select a parent
– Select sportbot-parent and click okay.
6. Create sportbot-rs layer (note the packaging of this layer is war)
– Right click on the sportbot project, select new / other / maven module and click next.
– Check Create simple project (skip archetype selection)
– Fill in the following
Module Name: sportbot-rs
Parent Project: sportbot
– Click next and fill in the following
Packaging: war
– Click finish
– Open the new sportbot-rs project, open the pom file
– The overview of the pom file is now open, click the open folder icon in the parent section to select a parent
– Select sportbot-parent and click okay.
Now you should have a project structure that looks like this:
As the main focus and aim of this tutorial is on artificial intelligence, I am not going to go into detail regarding maven in general and the configuration of the pom.xml files for this project. We will focus on the role of each layer and how it translates in artificialintelligence and the human anatomy as we progress.
After you have successfully created the project structure you can edit your pom.xml files to match the project pom.xml files located on github:
github.com
Step 2: Creating the database
Postgresql and pgAdmin
Now that we have created a maven project structure, we need to create the database that we will be creating our data model from and using in our rest services. Open pgAdmin and let’s get started.
1. Create the database and schema
– In pgAdmin click and expand your PostgreSQL server, this is usually setup on port 5432 by default if you did not explicitly choose another port or if 5432 is reserved for another application.
– Right click on Databases and select New Database
– Name the database sportbot
– Click and expand the newly created sportbot database , right-click on Schemas and select New Object/ New Schema…
– Name the schema sportbot
– Right click on Schemas and click refresh, there should now be two schemas named public and sportbot.
2. Create the database tables
– To create a table expand the sportbot schema, right click on tables and select new table and enter the name of the table.
– Create the following tables:
teams
players
sport_type
past_matches
present_matches
future_matches
player_stats
match_stats
popular_opinion
greetings
questions
answers
context
english_words
emotions
betting
trending
information_sources
predictions
spelling
team_rivalry
player_rivalry
locations
You should now have 23 tables and your structure should resemble the image on the below.
Implementation depicted through human anatomy
Neuron cells and memory
As mentioned artificial intelligence achieved through java part 1 AI is achieved by studying how the human brain thinks and how humans learn, decide, and work to solve a problem, then using outcomes of this study as a basis of developing intelligent software and systems.Neurons are nerve cells that transmit nerve signals to and from the brain at up to 200 mph, in terms of our project we have now laid the foundation of our sport bot’s brain with the maven project acting as the nervous system and the rest services we are going to create acting as neurons carrying messages to and from the brain of our AI sport bot.
Memory is not a single unitary process, there are different types of memory. Our short term and long term memories are encoded and stored in different ways and in different parts of the brain. The database we have created acts as the sport bot’s memory, providing the sport bot with the ability to formulate a response based on stored data/knowledge.
In the next part of this tutorial, we will start populating our database and create rest services to access our data and start to look at obtaining data from external sources.