number comparison in IBM Watson Assistant - ibm-cloud

I am trying to build a BMI calculator inside Watson but it seems like Watson is not supporting number comparison when you use the "Multiple conditioned responses".
<? ($weight / ($height * $height) ) < 18.5 ?>
This code will throw an error:
SpelParseException when evaluating dialog node ID [response_8_1624288200413]. Condition [<? ($weight / ($height * $height) ) < 18.5 ?>] could not be parsed. Check the syntax of the expression. SpEL syntax error: Expression [<? ($weight / ($height * $height) ) < 18.5 ?>] converted to [<? (context['weight'] / (context['height'] * context['height']) ) < 18.5 ?>] at position 0: EL1070E: Problem parsing left operand

Your example works for me. I can also confirm that IBM Watson Assistant can compare numbers and has other support for math expressions and number processing.
This is my response text:
This is: <? ($weight / ($height*$height)) < 18.5 ?>
I set values for weight and height in Manage Context in the "Try it". Depending on the values, it returns either
This is: true
or
This is: false
Have you set any values during your tests?

Related

Incrementing numbers in REXX

I have a requirement where I take a SUBSTR (e.g st_detail = "%BOM0007992739871P", st_digit = SUBSTR(st_detail, 8, 10) ). I have to do some validations on the st_digit and if it is valid change "%BOM0002562186P" to "%BOM0002562186C". My code works fine upto this. But I was asked to increment st_digit (I used st_digit = st_digit + 1 ) and print 100 valid st_digits and append it with C. so I put the code in a loop and display st_detail. But when i ran it i got "%BOM0007.99273987E+9C" after first increment. Please help on how to display "%BOM0007992739872C"? (NOTE: this is a reference only and I can't display the validation logic here and my code works fine. The extra code i added was the code I used here)
out_ctr = 1
DO while out_ctr < 101
/* validations */
IF valid THEN
say st_digit " is valid"
ELSE
say st_digit " is invalid"
st_digit = st_digit + 1
out_ctr = out_ctr + 1
END
It seems the NUMERIC setting was " 9 0 SCIENTIFIC ". I changed it to NUMERIC DIGITS 12, So, now it works.
parse numeric my_numeric_settings
say my_numeric_settings /* 9 0 SCIENTIFIC */
NUMERIC DIGITS 16
parse numeric my_numeric_settings
say my_numeric_settings /* 16 0 SCIENTIFIC */
It's because I used SUBSTR(st_detail, 8, 10),So, st_digit is of length 10, which is greater than the DEFAULT setting of "9 0 SCIENTIFIC", So by changing it to either "NUMERIC DIGITS 10" or "NUMERIC DIGITS 12" the code worked.

or-tools NewIntVar seems not supporting int64 in python

Dears,
I'm trying to create NewIntVar with lower bound an higher bound equal to the one of the int64:
(-9.223.372.036.854.775.808 to +9.223.372.036.854.775.807)
But I get the Model invalid error when I try to solve the model. The max range I found as working (trying manually) is the following model.NewIntVar(-93.372.036.854.775.808, 9.123.372.036.854.775.807,'pippo')
Do you know why int64 is not supported?
Thanks
Stefano
From the source code I see:
https://github.com/google/or-tools/blob/stable/ortools/sat/cp_model_checker.cc#L90
const int64 ub = proto.domain(proto.domain_size() - 1);
if (lb < kint64min + 2 || ub > kint64max - 1) {
return absl::StrCat(
"var #", v, " domain do not fall in [kint64min + 2, kint64max - 1]. ",
ProtobufShortDebugString(proto));
}
// We do compute ub - lb in some place in the code and do not want to deal
// with overflow everywhere. This seems like a reasonable precondition anyway.
if (lb < 0 && lb + kint64max < ub) {
return absl::StrCat(
"var #", v,
" has a domain that is too large, i.e. |UB - LB| overflow an int64: ",
ProtobufShortDebugString(proto));
}
So the values actually are:
cp_model.INT_MIN + 2 (-9223372036854775806)
cp_model.INT_MAX - 1 (9223372036854775806)
And max-min can't exceed kint64max (9223372036854775807)
You could use INT32_MAX and INT32_MIN instead or a range that satisfies these conditions.

Drools: how to use abbreviated condition notation together with further conditions?

Using Drools 6.5.0.Final
I want to use abbreviated combined relation condition (e.g. Person( age > 30 && < 40 )) in combination with additional conditions.
I tried it, but the resulting rules are executed more than once.
I have a small example, where temperature deviation from a setpoint is checked and the allowed deviations depend on the setpoint. The allowed deviations are configured with Param facts, see below.
If I execute the example (fire-all-rules):
rule 1 fires two times (bug?)
rule 2 fires once as expected (without abbreviated notation).
Is my usage of the abbreviated notation wrong or is this a bug?
Example rules:
declare Param
from : float
to : float
low : float
high : float
end
declare TemperatureEvent
#role( event )
id : String
setpoint : float
t : float
end
rule "Init abbreviated conditions test"
when
then
insert(new Param(0, 10, 1, 1));
insert(new Param(10,20, 2, 3));
insert(new TemperatureEvent("id1", 13.7f,11.5f));
// rule 1 and rule 2 should fire exactly once
end
rule "rule 1"
when
$p: Param()
$x : TemperatureEvent($p.from <= setpoint && < $p.to, (t < setpoint+$p.low || t > setpoint+$p.high))
then
System.out.println("rule 1: "+$x.getId()+" "+$x.getSetpoint()+" "+$x.getT());
end
rule "rule 2"
when
$p: Param()
$x : TemperatureEvent($p.from <= setpoint, setpoint < $p.to, (t < setpoint+$p.low || t > setpoint+$p.high))
then
System.out.println("rule 2: "+$x.getId()+" "+$x.getSetpoint()+" "+$x.getT());
end
The abbreviated restriction
$p.from <= setpoint && < $p.to
is equivalent to
$p.from <= setpoint && $p.from < $p.to
What you want is
setpoint >= $p.from && < $p.to

Liberty Basic Payroll Calculator IF ELSE

I'm just getting started with learning basic programming with Sams and already am having issues with the simple payroll calculator I've been trying to write. Could someone explain how I could better rewrite this? And can you only follow IF THEN statements with a print command? I think I'll have to invest in a newer book but I was hoping I could get this to run at least in the meantime.
Input "Please input payrate: "; Ans$
Print
Input "Please input hours worked: "; Hrs$
If (Hrs$ >= "40") Then
payRate = (Hrs$ * Ans$)
Else If (Hrs$ <= "41") Then
payRate = Hrs$ * (1.5 * Ans$)
End If
taxRate = payRate * .15
grossPay = payRate * Hrs$
netPay = payRate - taxRate
Print
Print: "Your net pay is: "; netPay
Also, I see you have an else if statement. One of the perplexing design decisions in Liberty Basic is that it doesn't support the else if/elseif statement that you might find in most BASIC language dialects.
From the online manual:
The elseif keyword is not supported. Here is an >example using elseif (QBasic):
'QBasic only
if sis boom bah then
print "Yippie!"
elseif la dee da then
print "So what!"
end if
Instead in Liberty BASIC, it looks like this:
'Liberty BASIC - no elseif
if sis boom bah then
print "Yippie!"
else
if la dee da then
print "So what!"
end if
end if
And to extend the above official documentation a little further with my own code sample in LB (Liberty Basic), you might just appreciate how deeply nested the if, else, end if can become.
'Liberty BASIC
grade = 55
if grade > 90 then
print "Excellent!"
else
if grade > 80 and grade < 90 then
print "Good"
else
if grade > 70 and grade < 80 then
print "We need to try a little harder."
else
if grade > 60 and grade < 70 then
print "We need to try a lot harder!"
else
print "Let's have a talk."
end if
end if
end if
end if
end
The equivalent in another dialect of BASIC, in this case FreeBasic, might look something like this which of course appears much tidier with only one end if vs a trail of end if's:
'FreeBasic
Dim grade as integer = 55
if grade > 90 then
print "Excellent!"
elseif grade > 80 and grade < 90 then
print "Good"
elseif grade > 70 and grade < 80 then
print "We need to try a little harder."
elseif grade > 60 and grade < 70 then
print "We need to try a lot harder!"
else
print "Let's have a talk."
end if
sleep
end
But all is not lost with LB because the language actually implements a fairly powerful select case statement which can include conditional statements which is not possible in certain dialects of BASIC (i.e. PureBasic)
'LB - Liberty Basic
grade = 55
select case grade
case grade > 90
print "Excellent!"
case (grade > 80) and (grade < 90)
print "Good"
case (grade > 70) and (grade < 80)
print "We need to try a little harder."
case (grade > 60) and (grade < 70)
print "We need to try a lot harder!"
case else
print "Let's have a talk."
end select
I don't use Liberty, but I imagine it's complaining when you're trying to do math on strings. Additionally, I find your misuse of the "payrate" name to be confusing. The logic of the overtime calc is also wrong. Here's my first attempt at a rewrite:
Input "Please input payrate: "; Rate$
Rate = val(Rate$)
Print
Input "Please input hours worked: "; Hrs$
Hrs = val(Hrs$)
Gross = Hrs * Rate
If Hrs > 40 Then Gross = Gross + ((Hrs - 40) * Rate / 2))
Taxes = Gross * .15
Net = Gross - Taxes
Print
Print: "Your gross pay is: "; Gross
Print: "Your net pay (after $";Taxes;" in taxes) is: "; Net
This code will work in Liberty BASIC:
INPUT "Please enter hours worked: "; hours 'you don't need a dollar sign at the end of the variable because it's a value not a string
INPUT "Please enter your hourly rate: "; hourlyRate
gross = hours * hourlyRate 'works out the gross amount
IF (hours > 40) THEN 'if the person worked more than 40 hours, then the following command is applicable...
gross = 40 * hourlyRate + ((hours - 40) * (hourlyRate * 1.5)) 'this line calculates the money earned for 40 hours, and adds the remaining hours at 1.5 times the hourly rate
END IF 'end the IF condition
tax = gross * 0.15 'calculates the tax at 15%
net = gross - tax 'calculates the net pay (i.e., gross pay after tax)
PRINT "-------------------------------"
PRINT "Your gross pay is: "; gross
PRINT "Your net pay is: "; net
As the previous poster suggested, you should use values instead of strings for maths (values don't have a dollar sign at the end), and when you label your variables they should have a meaningful name in relation to what you're trying to achieve.
Liberty BASIC has a tutorial under Help that you can use to teach yourself how to code. Otherwise Beginning Programming for Dummies is another useful guide - that's what I'm using :)

Perl function for negative integers using the 2's complement

I am trying to convert AD maxpwdAge (a 64-bit integer) into a number of days.
According to Microsoft:
Uses the IADs interface's Get method to retrieve the value of the domain's maxPwdAge attribute (line 5).
Notice we use the Set keyword in VBScript to initialize the variable named objMaxPwdAge—the variable used to store the value returned by Get. Why is that?
When you fetch a 64-bit large integer, ADSI does not return one giant scalar value. Instead, ADSI automatically returns an IADsLargeInteger object. You use the IADsLargeInteger interface's HighPart and LowPart properties to calculate the large integer's value. As you may have guessed, HighPart gets the high order 32 bits, and LowPart gets the low order 32 bits. You use the following formula to convert HighPart and LowPart to the large integer's value.
The existing code in VBScript from the same page:
Const ONE_HUNDRED_NANOSECOND = .000000100 ' .000000100 is equal to 10^-7
Const SECONDS_IN_DAY = 86400
Set objDomain = GetObject("LDAP://DC=fabrikam,DC=com") ' LINE 4
Set objMaxPwdAge = objDomain.Get("maxPwdAge") ' LINE 5
If objMaxPwdAge.LowPart = 0 Then
WScript.Echo "The Maximum Password Age is set to 0 in the " & _
"domain. Therefore, the password does not expire."
WScript.Quit
Else
dblMaxPwdNano = Abs(objMaxPwdAge.HighPart * 2^32 + objMaxPwdAge.LowPart)
dblMaxPwdSecs = dblMaxPwdNano * ONE_HUNDRED_NANOSECOND ' LINE 13
dblMaxPwdDays = Int(dblMaxPwdSecs / SECONDS_IN_DAY) ' LINE 14
WScript.Echo "Maximum password age: " & dblMaxPwdDays & " days"
End If
How can I do this in Perl?
Endianness may come into this, but you may be able to say
#!/usr/bin/perl
use strict;
use warnings;
my $num = -37_108_517_437_440;
my $binary = sprintf "%064b", $num;
my ($high, $low) = $binary =~ /(.{32})(.{32})/;
$high = oct "0b$high";
$low = oct "0b$low";
my $together = unpack "q", pack "LL", $low, $high;
print "num $num, low $low, high $high, together $together\n";
Am I missing something? As far as I can tell from your question, your problem has nothing at all to do with 2’s complement. As far as I can tell, all you need/want to do is
use Math::BigInt;
use constant MAXPWDAGE_UNIT_PER_SEC => (
1000 # milliseconds
* 1000 # microseconds
* 10 # 100 nanoseconds
);
use constant SECS_PER_DAY => (
24 # hours
* 60 # minutes
* 60 # seconds
);
my $maxpwdage_full = ( Math::BigInt->new( $maxpwdage_highpart ) << 32 ) + $maxpwdage_lowpart;
my $days = $maxpwdage_full / MAXPWDAGE_UNIT_PER_SEC / SECS_PER_DAY;
Note that I deliberately use 2 separate constants, and I divide by them in sequence, because that keeps the divisors smaller than the range of a 32-bit integer. If you want to write this another way and you want it to work correctly on 32-bit perls, you’ll have to keep all the precision issues in mind.