Skip to content

Commit

Permalink
skills: nlu test final replacements, better logging
Browse files Browse the repository at this point in the history
  • Loading branch information
LeroyR committed Jun 6, 2024
1 parent ae194ee commit cba7a43
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class ConfirmNLURegex : AbstractSkill(), SensorListener<NLU?> {
private const val PS_YES = "confirmYes"
}

private val finalReplacements = mapOf("""\bme\b""" to "you", """\byou\b""" to "me")
private val finalReplacements = mapOf("\bme\b" to "you","\\bme\\b" to "you", """\bme\b""" to "you", """\byou\b""" to "me", """ me\?""" to "you?")
private var doFinalReplacements = true
private var confirmText = "You want Me to: #M?"
private var defaultMapping = "#T"
Expand Down Expand Up @@ -142,7 +142,7 @@ class ConfirmNLURegex : AbstractSkill(), SensorListener<NLU?> {

for (m in mappings.split(";")) {
if (m.isBlank()) continue // last string after ;
logger.debug("add mapping: $m")
logger.trace("add mapping: $m")
val s = m.trim().split("=")
if (s.size != 2) throw SkillConfigurationException("error in intentMapping for '$m' size:${s.size} != 2")
intentMapping[s.first()] = s.last()
Expand Down Expand Up @@ -170,10 +170,13 @@ class ConfirmNLURegex : AbstractSkill(), SensorListener<NLU?> {
}
}
logger.info("computed: '$result'")
if (doFinalReplacements) for (replacement in finalReplacements) {
result = result.replace(replacement.key.toRegex(), replacement.value)
if (doFinalReplacements) {
for (replacement in finalReplacements) {

result = result.replace(replacement.key.toRegex(), replacement.value)
}
logger.info("text after final replacements: '$result'")
}
logger.info("after final replacements: '$result'")
return result
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public class CompareSlot extends AbstractSkill {

private ExitToken tokenMisMatch;
private ExitToken tokenMatch;
private ExitToken tokenError;

private static final String KEY_COMPARE_STRING = "#_COMPARE_STRING";

Expand All @@ -46,7 +45,7 @@ public class CompareSlot extends AbstractSkill {
public void configure(ISkillConfigurator configurator) {
tokenMatch = configurator.requestExitToken(ExitStatus.SUCCESS().withProcessingStatus("match"));
tokenMisMatch = configurator.requestExitToken(ExitStatus.SUCCESS().withProcessingStatus("misMatch"));
tokenError = configurator.requestExitToken(ExitStatus.ERROR());


readSlot = configurator.getReadSlot("ReadSlot", String.class);
compareString = configurator.requestValue(KEY_COMPARE_STRING);
Expand All @@ -59,6 +58,7 @@ public boolean init() {

if (slotContent == null) {
logger.warn("your ReadSlot was empty");
return false;
}

} catch (CommunicationException ex) {
Expand All @@ -70,9 +70,6 @@ public boolean init() {

@Override
public ExitToken execute() {
if (slotContent == null) {
return tokenError;
}
if (slotContent.equals(compareString)) {
return tokenMatch;
}
Expand Down

0 comments on commit cba7a43

Please sign in to comment.