France
Asked — Edited

The Robot Program 027 - Microsoft Cognitive Emotion In French

Hi, after watching this video on Youtube, i writed a little script for translate the emotion in french :

$retVal=" " $retVal= $EmotionDescription if ($EmotionDescription="Happiness") $retVal="eureu" endif if ($EmotionDescription="Sadness") $retVal="Triste" endif if ($EmotionDescription="Surprise") $retVal="Surpri" endif if ($EmotionDescription="Anger") $retVal= "En Colère" endif if ($EmotionDescription="Neutral") $retVal="sans zexpression" endif if ($EmotionDescription="Disgust") $retVal="Dégouté" endif if ($EmotionDescription="Fear") $retVal="Effrayé" endif SayEZB(("iL ME SEMBLE QUE VOUS zaiTe" + $retVal))

Valere.


ARC Pro

Upgrade to ARC Pro

Stay on the cutting edge of robotics with ARC Pro, guaranteeing that your robot is always ahead of the game.

PRO
USA
#1  

Valere73,

Do you need help ?

1) to help readability, use [ code ] [ /code ] tags.

2) ARC > Edit Script > use (Alt+F) to format code improves readability.


#using elseif less comparisations => less cpu
if ($EmotionDescription="Happiness")
  $retVal="eureu"
ELSEif ($EmotionDescription="Sadness")
  $retVal="Triste"
ELSEif ($EmotionDescription="Surprise")
  $retVal="Surpri"
ELSEif ($EmotionDescription="Anger")
  $retVal= "En Colère"
ELSEif ($EmotionDescription="Neutral")
  $retVal="sans zexpression"
ELSEif ($EmotionDescription="Disgust")
  $retVal="Dégouté"
ELSEif ($EmotionDescription="Fear")
  $retVal="Effrayé"
ELSE
  $retVal=$EmotionDescription
endif
#removed extra parentheses
SayEZB("IL ME SEMBLE QUE VOUS ZAITE " + $retVal)

#2  

This is where a switch or case statement would be useful. Not saying it is needed, but would just be useful in the script language.

PRO
USA
#3  

I agree.

if you have zillions strings to match you can be creative:


#can be moved to the initialize script
DefineArray($emotion_keys_en, 7)
$emotion_keys_en[0]="Happiness"
$emotion_keys_en[1]="Sadness"
$emotion_keys_en[2]="Surprise"
$emotion_keys_en[3]="Anger"
$emotion_keys_en[4]="Neutral"
$emotion_keys_en[5]="Disgust"
$emotion_keys_en[6]="Fear"

DefineArray($emotion_keys_fr, 7)
$emotion_keys_fr[0]="Eureu"
$emotion_keys_fr[1]="Triste"
$emotion_keys_fr[2]="Surpri"
$emotion_keys_fr[3]="En Colère"
$emotion_keys_fr[4]="Sans zexpression"
$emotion_keys_fr[5]="Dégouté"
$emotion_keys_fr[6]="Effrayé"

#main logic

$retVal=$EmotionDescription

repeat ($ix, 0, GetArraySize("$emotion_keys_en")-1, 1)
  if ($EmotionDescription=$emotion_keys_en[$ix])
    $retVal=$emotion_keys_fr[$ix]
    # key found => break the repeat
    $ix=GetArraySize("$emotion_keys_en")
  endif
endrepeat

SayEZB("IL ME SEMBLE QUE VOUS ZAITE " + $retVal)

#4  

Great ! thanks I understand the code but it's too high level for me stress