Artificial Intelligent Personal Assistant Program in C++.

    Lately I have been working on a simple C++ AI project about personal assistant and I am excited to discuss it with you today. So, basically for now it only supports Linux OS. (  :)  ). I wouldn’t be sharing any of my code although I would be explaining the algorithm.

    This AI program is pretty simple; I actually can now talk to my OS in my language instead of learning its language and perform my day to day tasks. It behaves like any personal assitant and assist me in my tasks. So, whenever I say to it that “I want to work now” It will ask me what kind of work I want to do; like whether it is a programming in any language or some word processing stuff or something else and based on my input it will automatically setup the required environment and tools on my desktop. If I say to it that “I am feeling bored” then it will automatically create a playlist of my favourite movies and open up for me to watch. Or if I say that I want to listen to songs of a particular artist then it will create a playlist of that artist and play for me. It can also schedule my day according the work input I have given to it based on some priority levels.

   Now lets move to the algorithm… So the simple trick behind this algorithm is, Consider that I want to tell you that I am hungry. Now this thing can be told to you in several different sentence construction: “I am Hungry”, “I am feeling Hungry”, “My stomach is Hungry”, “I am very Hungry” and blah blah… Now there is one similarity between these sentences and that is the word “Hungry”. So, every time I want to tell you that I need something to eat there is a huge probability that I will be using the word Hungry in my sentence to tell you that. 

    Based on this common theory my AI program works, it simply reads my input word by word and searchs for some specific words and if they relate to some task then that task is performed. Now obviously this might look simple but there are quite complex algorithms going on in my program like; my program first kind of proof reads my input (I make a lots of spelling mistake) and then searches for specific terms, but there might be chance I have used any synonym of that word. Like in the above example for Hungry I might use “starving”! So, we also need to consider that possibility. Or if I am saying it like this “I am not Hungry” and if my program just searches for the word hungry; her its found it will perform the task even though I don’t want it to be performed, hence we also need to consider the negation statements. So, we need to consider all possibilities of user input. That is, I want to say internally there are quite complex instructions running to avoid these possibilities.

    Now lets consider a real example. I ask my program to connect to Internet. So, here the rest is same, te searching stuff, but to connect to internet I am using bash script; similarly to perform other OS related tasks I am using Bash scripting. I am also simultaneously collecting user inputs in a file so that I can analyze how a user interacts with this program and perform tasks. It helps me to improve my algorithm accordingly. Now, you can use this basic idea to make your own custom Personal Assistant ( to whom you don’t have to pay ). You can make it search the web,do your auto scheduled tasks, book things for you, send auto replies and retrieve data or do some funny stuff.

Here is the screenshot of my program (Its really very old and first version…):

AI in C++

AI in C++

In this example I tell it that I want to Work and then I tell it what kind of work I want to do (PHP); It opens up all the required stuff for my PHP programming like my favorite editor (Sublime-text) and then my local-host, phpmyAdmin, my /var/www directory…            

How does the brain function?

         I am not a neuroscientist or anything but just a guy who is curious to know how the brain functions. I know there is lots of research going in to this and lots of brilliant people are putting forward their theories of how the brain functions. So, here I am writing about, How our brain functions, based on conclusions drawn from carrying out some really simple experiments. (I could be wrong…But I do not think I am!). Here we will be discussing about the general working of the cerebral cortex, especially the frontal lobes, which are associated with executive functions such as self-control, planning, reasoning, and abstract thought.


        So, here is the basic thing I found out in my first experiment; I have a friend named Jessica (name changed) whom I last saw when I was in my sixth grade. Back then she was some feet tall had big brown eyes, short black hairs, and fair colour. Now for some reasons she moved to a western country and returned back after seven years, for holidays. When I went to pick her up on the airport I found it hard to recognize her…she was now feet tall and she had blonde hairs and had a beautiful face with proportional eyes! Now lets us look from the perspective of our mind. When I first met, her, my mind kind of observed all the important features of her and stored that information. Now after that whenever I met her, my mind would recall all that information it has stored about her, which would help it to recognize her and compare it with the present information obtained from the present Jessica. It would update its information about Jessica if she would make any minor beauty makeovers, but that information would not serve a ground to identify her because my mind already knows that those beauty makeovers are temporary and are subjected to change, although they would help me to spot the difference.

         Now back to present, when I am driving to the airport, my mind meanwhile, gathers all the information it has about her and compiles it in a way that would help me to identify her at the airport. Based on that information it predicts her appearance as a white girl with black hairs and brown eyes. Here comes the tricky part, when she meets me in the parking lot, my mind notices that there has been a remarkable change in here appearance; her hairs are blonde, she is quite tall, her voice, body language has been changed. Since, this does not matches up the few predictions of her appearance made by my mind previously it gets confused for few seconds. Although, it comes back on track and again updates here information. Now as these changes were major but not major enough to make my mind believe that she is someone else; it updates its obsolete data about her and proceeds.

Therefore, from this we can say, that our mind constantly collects information from the all the bodies around us. In course of time, it modifies or removes some part of that information when changes are observed in them and it has the ability to recall and compare that information to check the validity of that particular body or the entire system.

         This above conclusion can also be checked; when we recognize that our friend has cold from the change in his voice over the phone. Our mind constantly gathers information, complies information, arranges it, or modifies it. It also derives some general theories or principles from this complied information and takes further action or decisions on its basis. These general theories or principles can be anything like when your friend speaks to you in a harsh voice he is probable angry or if he is being excessively polite probably he needs a favour from you. Alternatively, these principles can also be about other day-to-day stuff like sugar which looks something like small transparent cubes is sweet in taste. Now, if someone offers you something that looks almost like sugar but tastes bitter, your are surprised and confused and meanwhile your mind forces you to check the fact behind this thing.

           Now in the second scenario, lets us name orange juices as water and water as orange juice. When a small kid who has recently learnt that orange juices is something that has no taste and is colourless whereas water is something that is colourful and tastes awesome…is corrected by an adult that he has got confused with both the things. Now the kid will argue with that adult and try to prove that he is correct.

From this, we conclude that our mind labels information and tries to find a relation between things it has learnt and the facts it has observed and derives one single general principle from it, for better reasoning.

        This is the only reason that we have several theories from several scientists about extinction of dinosaurs; as our mind tries to derive a reasoning to it by finding a relation between things it has learnt and fact it knows (which are very less in this instance). But, when we consider this example, “Earth is circular in shape” everybody seems to agree to it because we have got lots of facts or photos to prove this statement; which provides a perfect reasoning to everybody’s mind. Now if in case some reputed scientists comes up and shows that, earth is in fact changing shape, with all sorts of proofs and photos we all will be confused and there will be a lots of theories to explain it, and this quest will continue unless and until someone comes up with a theory which will be having a perfect relation between facts and things we have learnt. A theory which will satisfy the sense, reasoning of everybody’s mind and thus there will be no further discussion.

         Therefore, I learnt these two things about the functioning of our brain from some easy day-to-day examples. If you have something to add or you completely disagree with what I have said above please let me know in the comment box below…!


Java Swing GUI–Currency Converter

       This is a Java Swing GUI program for currency conversion. So basically here we convert one currency to other or vise versa. For detailed explanation of how swing works checkout my previous post;

   Here as usual we create a JApplet class and implement an Action Listener. Here we require two text fields, two Combo box, two buttons and offcourse four labels. The rest are heard of but the JComboBox is new.Convc Conce

It is quite similar to a dropdown list only we have to specify the elements included in it, as String array.Here is how you will initialize them;

JComboBox c1,c2;

    String[] currency={"US Dollar","Indian Rupee","British Pound","Euro","Canadian Dollar","Emirati Driham","Chinese Yuan"};
  c1=new JComboBox(currency);
  c2=new JComboBox(currency);


     Now as you seen in the String array we have all the elements to be shown in the combo box that is the seven currencies. Then we initialize the combo box to String array ‘currency’ and set its index to 0, that is by default it will show up the element at index zero, in this case ‘US Dollar’.

    Here also, to design the GUI we use the GridBagLayout. We position the components as per our requirement and add them on the frame and lastly assign Action Listener to the components with which we are going to interact.

    Now when we complete our GUI we go for action performed; where we specify what happens when the user interacts with a particular component. We first get the amount from the first text field that has to be converted. Very important thing here is that any text field stores the data within it as a string so, to perform mathematical operation on the value we need to convert it from string to double.



    This step here is quite important where we need to decide from which currency to which currency we need to convert the amount. The string array here comes in handy. As we read the string array on the basis of index lets us consider; if the user selects index 2 at the combo box c1 and selects index 5 at the combo box c2; that means we need to convert British pounds to Emirati Dirham; so it performs that mathematical operation within the if condition. For example,

if(c1.getSelectedIndex()==2 & c2.getSelectedIndex()==5){
c= a*6.170453;}


Similarly to perform all the currency conversion we need to consider all the combinations of the currencies with each other except with itself, that is have to consider almost forty-two combinations. Then again to display this result in the second text field we need to convert the double value to string.



You can also add the Clear button to clear the text fields;


Note: The conversion rates were dated on 19th of April 2014 and obviously must have changed the very next day so you need to tinker with that formula if you want accuracy. Conversion rates were obtained from X-Rates.

  • Download the source code of this program here:


     If you have any improvements in this program to make it short and simple or have any doubts regarding this program please let me know by commenting below.


Get every new post delivered to your Inbox.

Join 515 other followers