AIML Parser Example - chatbot

I need some help to understand AIML templates using an example below, your help is appreciated to get this template working.
These are some of the sample inputs I am trying to handle and output I want to generate from AIML parsing.
Input : sale abc
Output : SALES ABC
Input : sales abc
Output : SALES ABC
Input : sale of product abc
Output : SALES ABC
Input : sale product abc
Output : SALES ABC
Input : What is the sale of product abc
Output : SALES ABC
Input : What is the average sale of product abc
Output : AVG SALES ABC
Input : What is the avg sale of product abc
Output : AVG SALES ABC
Input : What is the last 30 day average sale of product abc
Output : AVG SALES ABC 30
Input : What is the last 30 day avg sale of product abc
Output : AVG SALES ABC 30
I have been trying to start with something like this to begin with but this does not seem to progress well due to lack of clarity on this tool to me.
<category><pattern>
# <set>numbers</set> <set>days</set> <set>average</set> sales <set>prepositions</set> *</pattern>
<template>SALES <star index="1"/>,<star index="2"/>,<star index="3"/>,<star index="4"/>,<star index="5"/>,<star index="6"/> </template>
</category>
Where numbers set define > 1,2,3,4,5..... 100
Days set define > day, days
Average set define > average, avg , averages
Prepositions set define > of
Thanks!

You should do this with wildcards rather than sets. The only sets you need are for your products and possibly a set for the number of days.
This category is the response to your first 4 queries:
<category>
<pattern>SALE <set>products</set></pattern>
<template>
SALES <star/>
</template>
</category>
We can now use wildcards to <srai> to call the master category:
<category>
<pattern>SALES ^ <set>products</set> ^</pattern>
<template>
<srai>SALE <star index="2"/></srai>
</template>
</category>
<category>
<pattern>SALE ^ <set>products</set> ^</pattern>
<template>
<srai>SALE <star index="2"/></srai>
</template>
</category>
<category>
<pattern>WHAT IS THE SALE ^ <set>products</set> ^</pattern>
<template>
<srai>SALE <star index="2"/></srai>
</template>
</category>
This category handles your next 2 queries:
<category>
<pattern>WHAT IS ^ AVERAGE SALE ^ <set>products</set> ^</pattern>
<template>
AVG SALES <star index="3"/>
</template>
</category>
We can use this to say that AVG means AVERAGE. You could also put this in your normal.substitutions file.
<category>
<pattern>_ AVG *</pattern>
<template>
<srai><star/> average <star index="2"/></srai>
</template>
</category>
Finally, this category handles your last 2 queries.
<category>
<pattern>WHAT IS ^ LAST * DAY ^ AVERAGE SALE ^ <set>products</set> ^</pattern>
<template>
AVG SALES <star index="5"/> <star index="2"/>
</template>
</category>

Related

SAPUI5, Two Calendars with own ids, without any sharement, setter will change the Month for both Calendars for no reason

look the Code below
this.byId("FirstCalendar").getDateValue().getMonth()
3
this.byId("SecondCalendar").getDateValue().getMonth()
3
this.byId("SecondCalendar").getDateValue().setMonth(this.byId("FirstCalendar").getDateValue().getMonth()+3)
1627084800000
this.byId("SecondCalendar").getDateValue().getMonth()
6
this.byId("FirstCalendar").getDateValue().getMonth()
6
.setMonth, changes the month of both Calendars for no reason.
Why do you think that is the Case?
Works as expected for me. You must have bound the properties to the same path, hence it is updating both. Provide the XML code please
XML: <DatePicker id="FirstDP" change="onCalendarChange"/>
<DatePicker id="SecondDP" change="onCalendarChange" />
<Button press="onDateTester" text="Date Tester" />
JS: onDateTester: function(evt){
var cal1 = this.getView().byId("FirstDP");
var cal2 = this.getView().byId("FirstDP");
console.log("Cal 1 Month : " + cal1.getDateValue().getMonth());
console.log("Cal 2 Month : " + cal2.getDateValue().getMonth());
console.log("Month change");
cal2.getDateValue().setMonth(cal1.getDateValue().getMonth()+3)
console.log("Cal 1 Month : " + cal1.getDateValue().getMonth());
console.log("Cal 2 Month : " + cal2.getDateValue().getMonth());
}
result:
Cal 1 Month : 2
Cal 2 Month : 2
Month change
Cal 1 Month : 2
Cal 2 Month : 5

format month of grouped news items in Typo3

I have news items, grouped by year and month. Here the code:
<f:groupedFor each="{paginatedNews}" as="groupedNews1" groupBy="yearOfDatetime" groupKey="year">
<f:groupedFor each="{groupedNews1}" as="groupedNews" groupBy="monthOfDatetime" groupKey="month">
<div style="border:1px solid blue;padding:10px;margin:10px;">
<h1>{month} {year} </h1>
<f:for each="{groupedNews}" as="newsItem">
<f:render partial="List/Item" arguments="{newsItem: newsItem,settings:settings,iterator:iterator}" />
</f:for>
</div>
</f:groupedFor>
</f:groupedFor>
Unfortunately, month and year are displayed in numbers in frontend, e.g.
03 2019
..(some news items)
02 2019
...
01 2019
However, what I need is this:
March 2019
...
February 2019
...
January 2019
How can I achieve this?
On the original EXT:news this method has been used:
Look at the template EXT:news/Resources/Private/Templates/News/DateMenu.html
<f:translate key="month.{month}" />
on the EXT:news/Resources/Private/Language/locallang.xlf you will find:
<trans-unit id="month.01" xml:space="preserve">
<source>January</source>
</trans-unit>
And so forth.

Watir,click on a date from a date picker 62 days from current date

I need to click on a date that is 62 days later than the current date.
The next button for the months is clickable so I have been able to move the calendar to 2 months later but unable to select the date.
Eg if the current date is 4 July then I need to select 6th Sept.
My code at the moment looks somewhat like this.
b.element(:name, "policyperiod_endDate").click <-- datetime picker's click
b.element(:xpath, "(//button[#type='button'])[50]").click <-- next month
b.element(:xpath, "(//button[#type='button'])[50]").click
b.element(:link,"06").click <--doesnt select 08
b.element(:xpath, "(//button[#type='button'])[68]").click <-selects fixed cell n
how to select 06?
The outer HTML is like this:
input type="text" class="pull-left pdr35 ng-isolate-scope ng-pristine ng- invalid ng-invalid-required" datepicker-popup="yyyy-MM-dd" is-open="datePickerOpts.datepickers.policyperiod_startdate[1]" ng-model="policyIVOs.policyEndDate" name="**policyperiod_endDate**" datepicker-options="dateOptions" show-button-bar="false" close-on-date-selection="true" show-weeks="false" ng-click="open($event, 'policyperiod_startdate', 1)" min-date="policyEndMin" max-date="policyEndMax" required="" readonly=""

How Do I Calculate Date Difference in Javascript

i want to count the date difference (days only) like if i am selecting "Date From" as 08-05-2016 and then "Date To" as 08-11-2016 ... it will calculate the days difference as "7" before submitting in leave count box the values on run time Using Javascript
Below is the text values codes.
Date From: <input type="date" name="from">
Date To: <input type="date" name="to">
Leave Count: <input type="text" name="leavecount">
<input type="submit" name="submit">

Merging average of time series corresponding to time span in a different data set

I have two datasets, one with contracts and one with market prices. The gist of what I am trying to accomplish is to find the average value of a time series that corresponds to a period of time in a cross-sectional data set. Please see below.
Example Dataset 1:
Beginning Ending Price
1/1/2014 5/15/2014 $19.50
3/2/2012 10/9/2015 $20.31
...
1/1/2012 1/8/2012 $19.00
In the example above there are several contracts, the first spanning from January 2014 to May 2014, the second from March 2012 to October 2015. Each one has a single price. The second dataset has weekly market prices.
Example Dataset 2:
Date Price
1/1/2012 $18
1/8/2012 $17.50
....
1/15/2015 $21.00
I would like to find the average "market price" (i.e. the average of the price in dataset 2) between the beginning and ending period for each contract on dataset 1. So, for the third contract from 1/1/2012 to 1/8/2012, from the second dataset the output would be (18+17.50)/2 = 17.75. Then merge this value back to the original dataset.
I work with Stata, but can also work with R or Excel.
Also, if you have a better suggestion for a title I would really appreciate it!
You can cross the contracts cross section data with the time series, which forms every pairwise combination, drop the prices from outside the date range, and calculate the mean like this:
/* Fake Data */
tempfile ts ccs
clear
input str9 d p_daily
"1/1/2012" 18
"1/8/2012" 17.50
"1/15/2015" 21.00
end
gen date = date(d,"MDY")
format date %td
drop d
rename date d
save `ts'
clear
input id str8 bd str9 ed p_contract
1 "1/1/2014" "5/15/2014" 19.50
2 "3/2/2012" "10/9/2015" 20.31
3 "1/1/2012" "1/8/2012" 19.00
end
foreach var of varlist bd ed {
gen date = date(`var',"MDY")
format date %td
drop `var'
rename date `var'
}
save `ccs'
/* Calculate Mean Prices and Merge Contracts Back In */
cross using `ts'
sort id d
keep if d >= bd & d <=ed
collapse (mean) mean_p = p_daily, by(id bd ed p_contract)
merge 1:1 id using `ccs', nogen
sort id
This gets you something like this:
id p_contract bd ed mean_p
1 19.5 01jan2014 15may2014 .
2 20.31 02mar2012 09oct2015 21
3 19 01jan2012 08jan2012 17.75