How to set variables with default values in AIML? - aiml

I want to set some variables to default values, so if the user never supplies, say, their username, my responses won't have odd empty spaces in them.
Sample of what I tried but didn't work:
<set name="name">user</set>
<category>
<pattern>HELLO</pattern>
<template>
Hello, <get name="name"/>.
</template>
</category>

The description of <get /> leads to the .pdefaults file.
Instead of
<set name="name">user</set>
in the UDC, the following single line in .pdefaults gets the result you want
[["name", "user"]]

Related

Callapi and openweathermap

I have problem with I think format when I get temperature value. When I call for this parameter I always got it with "d0" f.e. "-0,39d0". How can I fix it? My code:
<category>
<pattern>PADANIE</pattern>
<template>
<think>
<set name="weather_t">
<callapi>
<url>http://api.openweathermap.org/data/2.5/weather</url>
<method>GET</method>
<query name="appid"><secret name="openweathermap_secret_appid"/></query>
<query name="q">zyrardow</query>
<query name="units">metric</query>
<query name="lang">pl</query>
<filter type="jsonpath">$.main.temp</filter>
</callapi>
</set>
</think>
<get name="weather_t"/>.
</template>
</category>
If I use jsonpath instead filter the result is the same.
<category>
<pattern>PADANIE</pattern>
<template>
<think>
<set var="weather_t">
<callapi>
<url>http://api.openweathermap.org/data/2.5/weather</url>
<method>GET</method>
<query name="appid"><secret name="openweathermap_secret_appid"/></query>
<query name="q">zyrardow</query>
<query name="units">metric</query>
<query name="lang">pl</query>
</callapi>
</set>
</think>
<jsonpath><path>$.main.temp</path><get var="weather_t"/></jsonpath>
</template>
</category>
bot answer example
This is how the openweathermap API presents the results. The easiest way to get rid of the d0 part is to denormalize the output.
Add this to your denormal substitution file:
["0d0", "0"],
["1d0", "1"],
["2d0", "2"],
["3d0", "3"],
["4d0", "4"],
["5d0", "5"],
["6d0", "6"],
["7d0", "7"],
["8d0", "8"],
["9d0", "9"],
In your first category, replace:
<get name="weather_t"/>
with
<denormalize><get name="weather_t"/></denormalize>
It should now work

Load xaml file and filter tags and values using c/c++

Is there a way to load a .xaml file data, filter the tags, and check values?
For instance, using the bellow code, how can I get all 'variable' tags and check if is 'String'and check if the value contains come specific keyword (using c/c++)?
Thank you
<Flowchart.Variables>
<Variable x:TypeArguments="x:String" Name="strDebugDt" />
<Variable x:TypeArguments="x:String" Name="strMailFilter" />
<Variable x:TypeArguments="sd:DataTable" Name="dtReportAttachments" />
</Flowchart.Variables>

How can I trigger a response on a particular day in a month with condition tag?

I am having problems making my aiml chatbot respond on a particular day of the month.
I make chatbots on botlibre.
I tried this code in my aiml chatbot but it did not work.
<pattern>date</pattern>
<template>
<think><set name="day of the month"><date format="%B %d"/></set></think>
<condition name="day of the month">
<li value="December 29">it's the twenty ninth.</li>
<li value="November 06">it's the sixth. How are you?</li>
</condition>
The expected result is the twenty ninth.
In actuality the aiml chatbot does not respond.
This is valid AIML and should work. It works fine on Pandorabots.com
Amend your category (as below) so it displays your predicate and you can see what "day of the month" is set to. My advice is to miss out the spaces in the predicate name and set it to "dayofthemonth" or even just "day", as it's possible Botlibre doesn't like predicates with spaces.
<category>
<pattern>date</pattern>
<template>
<set name="day of the month"><date format="%B %d"/></set>
<condition name="day of the month">
<li value="December 29">it's the twenty ninth.</li>
<li value="November 07">it's the seventh. How are you?</li>
<li>day of the month = <get name="day of the month"/></li>
</condition>
</template>
</category>
An AIML tip I would advise you do with <condition> is to always include a catchall <li> as I've done above. That way, your bot will at least respond with something if nothing matches rather than leaving the user hanging.

How to iterate a List and print it's content one by one in each groupFooter?

I just want to know, is there any way to iterate a List and print it's content one by one (incremental) in each groupFooter?
I create a group in my report, and in each groupFooter section, I want to display content from a java.util.List I sent from Java class via parameter.
Currently I just using jr:list and jr:listContents in my groupFooter, and the result is all contents from the list is printed in every groupFooter. I got an headache to solve this, so any help will relief me.
I don't think you should try to iterate the List to get content in a certain number of groupFooter, instead I would get content directly List based on index.
What we need is simple a pointer (position in list), in your case this number seems to be an incremented number every time we have a new group.
A variabile counting as group change is:
<variable name="countMyGroup" class="java.lang.Integer" incrementType="Group" incrementGroup="Group1" calculation="Count">
<variableExpression><![CDATA[""]]></variableExpression>
<initialValueExpression><![CDATA[0]]></initialValueExpression>
</variable>
With this simple variabile we will now have the current number of group that is displayed and we can add a textField with the value from or List using this number. see java.util.List.get(int index)
<parameter name="listOfStuff" class="java.util.List" isForPrompting="false"/>
.....
<textField>
<reportElement x="120" y="0" width="267" height="17" uuid="b45699d3-5d34-4d88-b7bc-2666cf787ace">
<printWhenExpression><![CDATA[$P{listOfStuff}.size()>=$V{countMyGroup}]]></printWhenExpression>
</reportElement>
<textFieldExpression><![CDATA[$P{listOfStuff}.get($V{countMyGroup}-1)]]></textFieldExpression>
</textField>
Note: the printWhenExpression will avoid IndexOutOfBoundsException, hence that the group number is higher then the size of our List
Full jrxml example, it use a dummy group changing on each record, to try it use a JREmptyDatasource with a couple of records.
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="ListOnEachPage" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="33394f25-66fc-431b-ac82-88660e9115e5">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="Empty 4 records"/>
<parameter name="listOfStuff" class="java.util.List" isForPrompting="false">
<defaultValueExpression><![CDATA[Arrays.asList(new String[]{"group 1","group 2","group 3"})]]></defaultValueExpression>
</parameter>
<queryString>
<![CDATA[]]>
</queryString>
<variable name="countMyGroup" class="java.lang.Integer" incrementType="Group" incrementGroup="Group1" calculation="Count">
<variableExpression><![CDATA[""]]></variableExpression>
<initialValueExpression><![CDATA[0]]></initialValueExpression>
</variable>
<group name="Group1">
<groupExpression><![CDATA[$V{REPORT_COUNT}]]></groupExpression>
<groupFooter>
<band height="34">
<textField>
<reportElement x="120" y="0" width="267" height="17" uuid="b45699d3-5d34-4d88-b7bc-2666cf787ace">
<printWhenExpression><![CDATA[$P{listOfStuff}.size()>=$V{countMyGroup}]]></printWhenExpression>
</reportElement>
<textFieldExpression><![CDATA[$P{listOfStuff}.get($V{countMyGroup}-1)]]></textFieldExpression>
</textField>
<textField>
<reportElement x="445" y="0" width="100" height="17" uuid="e5c46332-b137-4c55-99e4-265c87b8f97d"/>
<textFieldExpression><![CDATA[$V{countMyGroup}]]></textFieldExpression>
</textField>
</band>
</groupFooter>
</group>
<detail>
<band height="63" splitType="Stretch">
<staticText>
<reportElement x="140" y="20" width="264" height="30" uuid="1ec9f950-dd2d-4c18-a81a-b0da937eb1b5"/>
<textElement>
<font size="14"/>
</textElement>
<text><![CDATA[Just some text to simulate detail band]]></text>
</staticText>
</band>
</detail>
</jasperReport>
Output, see how values from list are extracted as long as we are within size of List
You need to make a variable which increment at your group level.
Step 2 its to use that variable in a simple textfield or what component you want (not a collection component) and put his expression like this : list.indexOf(countVariable)

Setting origin or referer value which from request to the response-header using urlrewritefilter

How to set origin value or referer value in a response-header using tuckey url rewrite filter xml file.
Accessing %{origin} directly in the set tag is not working but not working in condition tag.
Below is the example I tried.
<rule enabled="true" last="false" match-type="regex">
<name>Enabling CORS Headers</name>
<from>^/path/someMorePath.*$</from>
<condition name="origin" operator="equal">http://www.testsite.com</condition> <!-- would like to write some regex to match a set of sites and if matched, then set the same origin as response -->
<set type="response-header" name="Access-Control-Allow-Origin">%{origin}</set>
<set type="response-header" name="Access-Control-Allow-Credentials">true</set>
</rule>
After having an complete understanding on the urlrewritefilter of tuckey api, the solution is to have a regular expression.
<rule enabled="true" match-type="regex">
<name>Enabling CORS Headers</name>
<from>^/path/someMorePath.*$</from>
<condition name="origin" operator="equal">([a-z.\/\/0-9]+)</condition>
<set type="response-header" name="Access-Control-Allow-Origin">%1</set>
<set type="response-header" name="Access-Control-Allow-Credentials">true</set>
</rule>
So, here using the regular expression in the condition tag and then using the back references in the regular expression as the variables in the response header