Use inheritance for my first program (cpp)

Who is the intruder ?

Manage the multilingual

So far, we have only used individuals in one word that did not allow us to see if we were manipulating identifiers or words in natural language. But if we want to be able to work with different languages, we will have to make the link between a word and its computer identifier.

So you can test the program with the following words: "green cup", "blue cup" and "green book".

You have the following result which shows that no intruder has been found.

[SAY]on green cup blue cup green book
[SAY]Let's play!

However, by redoing the test with the "green_cup", "blue_cup" and "green_book" identifiers, you have this:

[SAY]on green_cup blue_cup green_book
[SAY]the intruder is green_book because it is the only one that is not: cup
[SAY]the intruder is blue_cup because it is the only one that is not: green
[SAY]Let's play!

You understand that we have so far worked with identifiers and not with words in natural language. Multilingual translation can not be done simply by changing the language of work.

To make the transition from natural language to identifiers and vice versa, we will use the two new functions: find() and getName()

find

The find function is used to retrieve all concepts of a given type whose name in natural language is the word passed in parameter. In this way, if several words are said (and therefore are written) in the same way we will be able to recover them all. In this tutorial, this case is not present in order not to add complexity. That's why we will each time recover the first cell of the vector.

We will therefore modify our callback function to realize the natural language transition to an identifier.

void wordCallback(const std_msgs::String& msg)
{
if(msg.data == "start")
start_ = true;
else
{
std::vector<std::string> ids = onto_->individuals.find(msg.data);
if(ids.size() == 0)
say("this word is unknown");
else if(std::find(names_.begin(), names_.end(), ids.front()) == names_.end())
names_.push_back(ids.front());
}
}

The find function is applied to individuals because we want individuals to input.

std::vector<std::string> ids = onto_->individuals.find(msg.data);

We can test our program again with the words: "green cup", "blue cup" and "green book". We thus obtain the same exit as with the old use of the identifiers:

[SAY]on green_cup blue_cup green_book
[SAY]the intruder is green_book because it is the only one that is not: cup
[SAY]the intruder is blue_cup because it is the only one that is not: green
[SAY]Let's play!

getName

Our display still uses identifiers. We will change this thanks to the function getName which will return a natural language word relative to the identifier passed in parameter.

The only thing we have to change is the display line as follows:

say("the intruder is " + onto.individuals.getName(intruder.name_)
+ " because it is the only one that is not: " +
onto.classes.getName(intruder.why_));

The result of our program becomes:

[SAY]on green_cup blue_cup green_book
[SAY]the intruder is green book because it is the only one that is not: cup
[SAY]the intruder is blue cup because it is the only one that is not: green
[SAY]Let's play!

Multilingual

We will now modify our launch file to put the working language in french.

<launch>
<node name="intruder" pkg="ontologenius_tutorial" type="intruder" output="screen"/>
<include file="$(find ontologenius)/launch/ontologenius.launch">
<arg name="intern_file" default="none"/>
<arg name="language" default="fr"/>
<arg name="files" default="$(find ontologenius)/files/tutorials/tutorial_1.owl"/>
</include>
</launch>

Well, that's it, our program will now work in French. You can test it with the words "tasse verte", "tasse bleu" et "livre vert".

The result of our program is:

[SAY]on green_cup blue_cup green_book
[SAY]the intruder is livre vert because it is the only one that is not: tasse
[SAY]the intruder is tasse bleu because it is the only one that is not: vert
[SAY]Let's play!

The advantage of this method is that internally the program uses identifiers that are much faster to find and thus only the interface uses the natural language.

Go further

To go further, you can add the ability to change the working language with the setLang() function.

onto.actions.setLang("en");

You can also change the display texts according to the language used by retrieving the language currently used with the getLang() function.

std::string lang = onto.actions.getLang();

To obtain the identifier of a word in natural language, we used the function find, but ontologenius provides other functions to obtain an identifier from natural language. You can try the functions proposed by class OntologyClient.