Article
· May 1 3m read

Ladies and Gentlemen, the amazing Iris-nator

   

The amazing Iris-nator has arrived in town.

He knows what you think, with just a few questions he is able to guess the character you have thought of.

Do you dare?

Some of you may know the game Akinator, where a genie is able to guess the character you have thought of, while you answer “yes” or “no” to a simple question.

No AI analyzing your social networks, no microphones listening in... So how does it do it?

The secret is a simple algorithm and a lot of people playing and feeding the database.

How does it work?

Let's define a term: Node.

A node can be a question or the name of the character.

If it is a question, it will have two answers: Yes or No.

 

Now let's give it a value.

To the question we will give the Id 1, to the affirmative answer, we will give the Id 2 and to the negative answer, the Id 3.

Now let's imagine that both the affirmative and negative answers return another question, with corresponding characters for “yes” and “no”.

 

We can see a pattern between the questions and the answers.

Affirmative answers are twice the question identifier, and negative answers are twice the question identifier plus one.

Then, if we have the node n, the next node to display will be node n*2 if the answer is "yes" or node (n*2)+1 if the anser is "no".

Let's give an example:

 

Suppose I think of Snoopy, and the question is "Is your character fictional?", the answer "yes" will tell us that the character we have thought of is "Superman", but it is not correct.

How do we turn our answer into a question that leads us to Snoopy?

We need a characteristic that differentiates us from Superman, in this case we will ask “Is your character a dog?”, then, the affirmative answer would be ‘Snoopy’ and the negative answer would be “Superman”.

This new question will replace the Id of the node “Superman”, the character “Snoopy” will have the double of the node of the new question and the character "Superman" will have the double of the node of the new question plus one.

 

This way, if we create a lot of questions and answers, our Iris-nator will be able to guess any character you have thought of.

How does Iris-nator works?

Create a table with information of nodes:

Class Irisnator.Data.Nodes Extends %Persistent
{

/// NodeId
Property NodeId As %Numeric;
/// Text of the node
Property Text As %String(MAXLEN = "");
/// Type of node (0 = text, 1 = question)
Property Question As %Boolean [ InitialExpression = 0 ];
/// Verb of the question
Property Verb As %String(MAXLEN = "");
}

Note: Why is there a field called "verb"? because, the question is shown as {verb} your character {text} ? therefore, it needs to know what is the verb (is, had, does, etc...)

The front-end is created with Angular19, to communicate with IRIS, I have created several API methods:

GET localhost:52773/irisnator/api/node/:nodeId

Returns the information about the node, also the NodId for answer Yes and No

{
    "nodeId": 1,
    "text": "a woman",
    "verb": "is",
    "question": true,
    "nodeYes": 2,
    "nodeNo": 3
}

GET localhost:52773/irisnator/api/score/:top

Returns the top score. This top score is the number of times a character has been hit.

{
    "score": [
        {
            "characterName": "Superman",
            "score": 8
        },
        {
            "characterName": "Maddona",
            "score": 3
        },
        {
            "characterName": "Snoopy",
            "score": 1
        }
    ]
}

POST localhost:52773/irisnator/api/node

When Iris-nator has not been able to guess your character, we fill in a form with the data of the new character, and what would be the question to ask to differentiate him/her from the character he/she had arrived at.

Then, move the current character to "no" answer, and put the id to the new question.

{
    "nodeId": 507,
    "newCharacter": "Snoopy",
    "oldCharacter": "Superman",
    "text": "a dog",
    "verb": "is"
}

In addition, it will add Snoopy as a character it has failed.

POST localhost:52773/irisnator/api/score

This method set the score for a character, if it has been success or not.

{
    "characterName": "Snoopy",
    "success": true
}

 

You can watch the following video of how the application works, enjoy it!!!

https://www.youtube.com/embed/v5GsiXJDgC8
[This is an embedded link, but you cannot view embedded content directly on the site because you have declined the cookies necessary to access it. To view embedded content, you would need to accept all cookies in your Cookies Settings]

Discussion (2)1
Log in or sign up to continue