Czy wiesz, bot Libre zapewnia bezpłatne zakwaterowanie śledzenia problemów do własnej strony internetowej lub aplikacji mobilnej?
Self, AIML, and scripting

script logic

w dpiaggesi wysłany Sep 9 2016, 12:15

Sorry to bother you again... i'm trying to script a little more complex version of the geolocation script... my problem is that i can't in any way reach the latest state! What am I doing wrong? i paste the code below... 

Entering "translate the post code XXXX" returns correctly the output of the g1() function... but if I add the country like 

"translate the post code XXXX in germany" the bot can't reach the "tPCWCState" state... please help! thanks

state GeoNames { case input goto sentenceState for each #word of sentence; state sentenceState { case "can" goto sentenceState; case "you" goto sentenceState; case "translate" goto tState; var numeral { meaning : number; } function g1() { res = Http.requestXML("http://api.geonames.org/postalCodeSearch?username=botlibre&maxRows=1&postalcode=" + numeral); if (res.totalResultsCount == "0") { return "i know no place with that code"; } if (res.totalResultsCount != "1") { return "there are more than one result, specify a country"; } return res.code.name; } state tState { case #the goto tState; case "post" goto tPCState; case "postal" goto tPCState; case "postcode" goto tPCState; } state tPCState { case "code" goto tPCState; case numeral goto tPCState; case "in" goto tPCWCState; answer g1(); } state tPCWCState { case "*" goto tPCWCState; answer "I AM HERE"; } } }


by dpiaggesi posted Sep 9 2016, 12:17

mmm the <pre> tag didn't work.... i try to paste the code as normal text

 

state GeoNames {
case input goto sentenceState for each #word of sentence;

state sentenceState {
case "can" goto sentenceState;
case "you" goto sentenceState;
case "translate" goto tState;

var numeral {
meaning : number;
}

function g1() {
res = Http.requestXML("http://api.geonames.org/postalCodeSearch?username=botlibre&maxRows=1&postalcode=" + numeral);
if (res.totalResultsCount == "0") {
return "i know no place with that code";
}
if (res.totalResultsCount != "1") {
return "there are more than one result, specify a country";
}
return res.code.name;
}

state tState {
case #the goto tState;
case "post" goto tPCState;
case "postal" goto tPCState;
case "postcode" goto tPCState;
}

state tPCState {
case "code" goto tPCState;
case numeral goto tPCState;
case "in" goto tPCWCState;

answer g1();
}

state tPCWCState {
case "*" goto tPCWCState;

answer "I AM HERE";
}
}
}


Thumbs up: 0, thumbs down: 0, stars: 0.0
Views: 1697, today: 1, week: 4, month: 11

by admin posted Sep 9 2016, 14:52
The issue is your 'case "*"' is only going to accept the exact text "*"

"*" is nothing special, and not a pattern.

The "case" operator takes either a string/text, or a "variable" object.

So you can change it to,

case country goto...

This will assign the "country" variable to the next word, and you can use the variable in your function.

You can also use patterns that use *, but a pattern compares the entire sentence.

i.e.
pattern "translate the postal code * in *" template...

For a pattern the "*" values become the "star" variable.
For multiple stars, star becomes an array, i.e. star[0] and star[1].

Thumbs up: 0, thumbs down: 0, stars: 0.0
Views: 1768, today: 0, week: 2, month: 8

Identyfikator: 13960480
Tagi: self
Wysłany: Sep 9 2016, 12:15
Aktualizacja: Sep 9 2016, 14:44
Odpowiedzi: 2
Widok: 2169, dziś: 1, tydzień: 1, miesiąc: 9
0 0 0.0/5