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.
However, by redoing the test with the "green_cup", "blue_cup" and "green_book" identifiers, you have this:
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.
The find function is applied to individuals because we want individuals to input.
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:
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:
The result of our program becomes:
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>
<launch>
<node pkg="ontologenius_tutorial" exec="intruder" output="screen"/>
<include file="$(find-pkg-share ontologenius)/launch/ontologenius.launch">
<arg name="intern_file" value="none"/>
<arg name="language" value="fr"/>
<arg name="files" value="$(find-pkg-share ontologenius)/files/tutorials/tutorial_1.owl"/>
</include>
</launch>
launch:
- node:
pkg: "ontologenius_tutorial"
exec: "intruder"
output: "screen"
- include:
file: "$(find-pkg-share ontologenius)/launch/ontologenius.yaml"
arg:
-
name: "intern_file"
value: "none"
-
name: "language"
value: "fr"
-
name: "files"
value: "$(find-pkg-share ontologenius)/files/tutorials/tutorial_1.owl"
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:
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.
You can also change the display texts according to the language used by retrieving the language currently used with the getLang() function.
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.