How to use AIML to find category out of topic? - aiml

I have been using AIML to make chatbot. I want search category out of topic after set data in topic. But, i don't have idea for that
set day
set class
search category out of topic use day and class
How could I do that?
Thanks in advance.
<category>
<pattern>SCHEDULE</pattern>
<template>
<think><set name="topic">SCHEDULE</set></think>
day ?</template>
</category>
<topic name="SCHEDULE">
<category>
<pattern><set>setdays</set></pattern>
<template>
<think><set name="day"><star/></set></think>
<condition name="day">
<li value="Monday"><set name="day"><star/></set> for class?</li>
<li value="Tuesday"><set name="day"><star/></set> for class?</li>
<li value="Wednesday"><set name="day"><star/></set> for class?</li>
<li value="Thursday"><set name="day"><star/></set> for class?</li>
<li value="Friday"><set name="day"><star/></set> for class?</li>
<li value="Saturday"><set name="day"><star/></set> for class?</li>
<li value="Sunday"><set name="day"><star/></set> for class?</li>
<li>not found</li>
</condition>
</template>
</category>
<category>
<pattern><set>setclass</set></pattern>
<template>
<think>
<set name="search"><get name="day"/> <set name="class"></set></set>
After set class i want to search category out of topic
</think>
</template>
</category>
</topic>

To search out of topic, reset your topic name to something that doesn't exist. Also you need <star/> instead of <set name="class"></set> in your template.
<category>
<pattern><set>setclass</set></pattern>
<template>
<think>
<set name="search"><get name="day"/> <star/></set>
<set name="topic">none</set>
</think>
</template>
</category>

Related

AIML recognizing middle letter of any word

In aiml i am trying to make my bot recognize of middle letter of any word. for exemple if i ask "What is the middle letter of cat" then it should response "A" this is what code looks like
<category><pattern>MIDDLELETTER *</pattern>
<template>The middle letter of <star/> is: <srai>MIDDLEITEM <explode><star/></explode></srai></template>
</category>
<category><pattern>MIDDLEITEM * * *</pattern>
<template><srai>MIDDLEITEM <star index="2"/></srai></template>
</category>
<category><pattern>MIDDLEITEM *</pattern>
<template><star/></template>
</category>
The above code works fine in this scenario
HUMAN: MIDDLELETTER CAT
ROBOT: The middle letter of CAT is: A
HUMAN: MIDDLELETTER SKY
ROBOT: The middle letter of SKY is: K
But does not work properly in this case
HUMAN: MIDDLELETTER ROMAN
ROBOT: The middle letter of ROMAN is: O
HUMAN: MIDDLELETTER DCNOVAN
ROBOT: The middle letter of DCNOVAN is: C
I was expecting these kind of results
HUMAN: MIDDLELETTER ROMAN
ROBOT: The middle letter of ROMAN is: M
HUMAN: MIDDLELETTER DCNOVAN
ROBOT: The middle letter of DCNOVAN is: O
Also, what if if there are 8 letters in an word? i am expecting to make it work like
HUMAN: MIDDLELETTER ABSOLUTE
ROBOT: The middle letter of ABSOLUTE could be either O or L
What am i missing in my code?
To find the middle letter, you need to break up the word into individual letters and work out how long the word is. You can then use the length of the word to find the middle letter.
This method will work. For compatibility, I've assumed you have no math capabilities in your bot ie division. It works up to letters that are 11 letters long. For longer words, you should divide the word length by 2 to find the middle letter of a word.
<category>
<pattern>MIDDLELETTER *</pattern>
<template>
<think>
<set name="letternum">0</set>
<srai>BreakUpWord <explode><star/></explode></srai>
<condition name="letternum">
<li value="1"><set name="middle"><get name="char1"/></set></li>
<li value="2"><set name="middle"><get name="char1"/> or <get name="char2"/></set></li>
<li value="3"><set name="middle"><get name="char2"/></set></li>
<li value="4"><set name="middle"><get name="char2"/> or <get name="char3"/></set></li>
<li value="5"><set name="middle"><get name="char3"/></set></li>
<li value="6"><set name="middle"><get name="char3"/> or <get name="char4"/></set></li>
<li value="7"><set name="middle"><get name="char4"/></set></li>
<li value="8"><set name="middle"><get name="char4"/> or <get name="char5"/></set></li>
<li value="9"><set name="middle"><get name="char5"/></set></li>
<li value="10"><set name="middle"><get name="char5"/> or <get name="char6"/></set></li>
<li value="11"><set name="middle"><get name="char6"/></set></li>
</condition>
</think>
The middle letter of <star/> is <get name="middle"/>.
</template>
</category>
<category>
<pattern>BREAKUPWORD * *</pattern>
<template>
<srai>IncreaseLetternum <star/></srai>
<srai>BREAKUPWORD <star index="2"/></srai>
</template>
</category>
<category>
<pattern>BREAKUPWORD *</pattern>
<template>
<srai>IncreaseLetternum <star/></srai>
</template>
</category>
<category>
<pattern>INCREASELETTERNUM *</pattern>
<template>
<think>
<condition name="letternum">
<li value="0"><set name="letternum">1</set><set name="char1"><star/></set></li>
<li value="1"><set name="letternum">2</set><set name="char2"><star/></set></li>
<li value="2"><set name="letternum">3</set><set name="char3"><star/></set></li>
<li value="3"><set name="letternum">4</set><set name="char4"><star/></set></li>
<li value="4"><set name="letternum">5</set><set name="char5"><star/></set></li>
<li value="5"><set name="letternum">6</set><set name="char6"><star/></set></li>
<li value="6"><set name="letternum">7</set><set name="char7"><star/></set></li>
<li value="7"><set name="letternum">8</set><set name="char8"><star/></set></li>
<li value="8"><set name="letternum">9</set><set name="char9"><star/></set></li>
<li value="9"><set name="letternum">10</set><set name="char10"><star/></set></li>
<li value="10"><set name="letternum">11</set><set name="char11"><star/></set></li>
</condition>
</think>
</template>
</category>

RadListView: Unknown custom element: <ReorderHandle>

I am getting an error while using ReorderHandle in reorderMode="Drag" in RadListView component of nativescript-ui-listview/vue like
[Vue warn]: Unknown custom element: <ReorderHandle> - did you register the component correctly? For recursive components, make sure to provide the "name" option.
How can I use ReorderHandle in Nativescript-vue according to this doc link?
Any help on this functionality will be appreciated.
Here are my codes
main.js
import Vue from 'nativescript-vue'
import RadListView from 'nativescript-ui-listview/vue';
Vue.use(RadListView);
My Vue Component
<RadListView ref="listView" for="(manager, index) in managers" :itemReorder="true" reorderMode="Drag">
<v-template>
<Label>{{ manager.name }}</Label>
<ReorderHandle col="1" verticalAlignment="center">
<Image android:src="res://reorder_icon" ios:src="res://reorder-icon" stretch="none" verticalAlignment="stretch" margin="16" />
</ReorderHandle>
</v-template>
</RadListView>
There is an Vue example of that.
Like you can see in the code you don't need to add <ReorderHandle>
Example:
<template>
<RadListView ref="listView"
for="item in items"
pullToRefresh="true"
itemReorder="true"
swipeActions="true"
#itemTap="onItemTap"
#pullToRefreshInitiated="onPullToRefreshInitiated"
#itemReordered="onItemReordered"
#itemSwipeProgressStarted="onSwipeStarted">
<v-template>
<GridLayout columns="50, *" rows="*" class="item">
<Image :src="item.image" col="0" class="thumbnail" />
<StackLayout col="1">
<label :text="item.name" class="h2" col="1"/>
<label :text="item.description" class="p" col="1"/>
</StackLayout>
</GridLayout>
</v-template>
<v-template name="itemswipe">
<GridLayout columns="auto, *, auto" backgroundColor="White">
<StackLayout id="mark-view" col="0" class="swipe-item left"
orientation="horizontal" #tap="onLeftSwipeClick">
<Label text="mark" verticalAlignment="center" horizontalAlignment="center"/>
</StackLayout>
<StackLayout id="delete-view" col="2" class="swipe-item right"
orientation="horizontal" #tap="onRightSwipeClick">
<Label text="delete" verticalAlignment="center" horizontalAlignment="center" />
</StackLayout>
</GridLayout>
</v-template>
</RadListView>
</template>
More details can be found here.

Insert grid template row (within grid) under condition

In a facebook-esque fasion, I'm working in a post with comments. The comments have a int which indicates the id of the parent post. So Comment 1 and 2 both have assigned as parent Post 1.
What im working on is on displaying them as a grid within a grid. Here is that part in .zul:
<grid id="postGrid" height="550px" model="#load(vm.pcdata.posts)" emptyMessage="No Posts.">
<template name="model">
<row>
<window border="normal">
<!-- .................. -->
<!-- PARENT POST -->
<!-- .................. -->
<caption id="userPost" label="#load(each.user)"/>
<textbox id="infoPost" readonly="true" value="#load(each.info)" multiline="true" rows="4" width="100%" mold="rounded"/>
<separator bar="true"/>
<hlayout>
<div>
<button label="Like" onClick="#command('addPLike', postid=each.postid)"/>
</div>
<div hflex="true">
<textbox id="likeTB" disabled="true" width="40px" style="text-align:center" value="#load(each.plikes)"/>
</div>
</hlayout>
<separator bar="false"/>
<window border="normal">
<!-- .................. -->
<!-- THE SECOND GRID-->
<!-- .................. -->
<grid id="commentGrid" height="150px" model="#load(vm.pcdata.comments)" emptyMessage="No Comments.">
<template name="model">
<row>
<window border="normal">
<caption id="userComment" label="#load(each.user)"/>
<textbox id="infoComment" readonly="true" value="#load(each.info)" multiline="true" rows="4" width="100%" mold="rounded"/>
<separator bar="true"/>
<hlayout>
<div>
<button label="Like" onClick="#command('addCLike', commentid=each.commentid)"/>
</div>
<div hflex="true">
<textbox id="likeTB" disabled="true" width="40px" style="text-align:center" value="#load(each.clikes)"/>
</div>
</hlayout></window></row></template></grid></window></window></row></template></grid>
In the second grid, I imagine there could be some sort of if function in which if both the postid in the father Post and the postsrc in the child Comment are the same, the comment will be displayed. Is there any way to make this work?
You can use shadow element <if>, e.g.
<if test="#load(vm.yourFlag)">
<grid id="commentGrid">
....
</if>
please see http://books.zkoss.org/zk-mvvm-book/8.0/shadow_elements/flow_control.html
Do you mean commentGrid is created but inner window is hidden, so there is space inside commentGrid, right?
Since you specify emptyMessage on commentGrid, it should show no comments. Or there are still comments but all hidden? If so, you can consider hide both commentGrid with inner window.

XSLT: How to place multiple level nodes in <ol> in place of xls:number format

I'm new to xsl and messing about with a sample template to try and figure things out.
I managed to get this far as per below snippets. Not sure if the way I'm applying the template for the different System.AreaPath is correct, but seems to work?
The one thing I'm struggling with right now is to use ol (or ol for Epic, ul for all siblings) and css, instead of the template sample putting every in a div and h{$level}.
I'm hoping this will also resolve the current issue of the number format - apply-template does not reset the count when applied twice as I have done here.
Any suggestions or samples will be appreciated as I'm not finding - or rather understanding correctly how to implement - the various search results and samples I have found. (for-each and when came up frequently)
I hope the above makes sense and that the code pasted is sufficient?
Thanks in advance!
- Jacques
xml: (edit: xml, not xlm)
<result executedDate="8/8/2017" executedBy="abc" email="abc#email.com">
<columns>
<System.Id name="ID" width="75" type="Integer"/>
<System.WorkItemType name="Work Item Type" width="75" type="String"/>
<System.Title name="Title" width="150" type="String"/>
<System.AreaPath name="Area Path" width="75" type="TreePath"/>
</columns>
<options>
...
</options>
<workitem id="1051" type="Epic" state="In Progress">
<System.Id>1051</System.Id>
<System.WorkItemType>Epic</System.WorkItemType>
<System.Title>Epic1</System.Title>
<System.AreaPath>Path1</System.AreaPath>
<workitem id="5411" type="Feature" state="Done">
<System.Id>5411</System.Id>
<System.WorkItemType>Feature</System.WorkItemType>
<System.Title>Feature1</System.Title>
<System.AreaPath>Path1</System.AreaPath>
<workitem id="5414" type="Product Backlog Item" state="Done">
<System.Id>5414</System.Id>
<System.WorkItemType>Product Backlog Item</System.WorkItemType>
<System.Title>Backlog Item 1</System.Title>
<System.AreaPath>Path1</System.AreaPath>
</workitem>
<workitem id="5418" type="Product Backlog Item" state="Done">
<System.Id>5418</System.Id>
<System.WorkItemType>Product Backlog Item</System.WorkItemType>
<System.Title>Backlog Item 2</System.Title>
<System.AreaPath>Path1</System.AreaPath>
</workitem>
</workitem>
</workitem>
<workitem id="1529" type="Epic" state="In Progress">
<System.Id>1529</System.Id>
<System.WorkItemType>Epic</System.WorkItemType>
<System.Title>Epic 2</System.Title>
<System.AreaPath>Path2</System.AreaPath>
<workitem id="3956" type="Feature" state="Done">
<System.Id>3956</System.Id>
<System.WorkItemType>Feature</System.WorkItemType>
<System.Title>Feature 2</System.Title>
<System.AreaPath>Path 2</System.AreaPath>
<workitem id="5955" type="Product Backlog Item" state="Done">
<System.Id>5955</System.Id>
<System.WorkItemType>Product Backlog Item</System.WorkItemType>
<System.Title>Backlog item 3</System.Title>
<System.AreaPath>Path2</System.AreaPath>
</workitem>
<workitem id="6667" type="Product Backlog Item" state="Done">
<System.Id>6667</System.Id>
<System.WorkItemType>Product Backlog Item</System.WorkItemType>
<System.Title>Backlog item 4</System.Title>
<System.AreaPath>Path2</System.AreaPath>
</workitem>
</workitem>
xsl:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes"/>
<xsl:template match="/">
<html>
<head>
<meta charset="UTF-8"/>
</head>
<body>
<h2>Section 1</h2>
<xsl:apply-templates select="/result /workitem[#type != 'Bug' and System.AreaPath='Path2']"/>
<p/>
<h2>Section 2</h2>
<xsl:apply-templates select="/result /workitem[#type != 'Bug' and System.AreaPath='Path1']"/>
</body>
</html>
</xsl:template>
<xsl:template match="//workitem">
<xsl:variable name="level" select="count(ancestor-or-self::*) "/>
<xsl:element name="h{$level}">
<xsl:number level="multiple" format="1. "/>
<xsl:value-of select="System.Title"/>
</xsl:element>
<div style="margin-left:15px;">
<xsl:apply-templates select="workitem"/>
</div>
</xsl:template>
html ouput:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html">
<meta charset="UTF-8">
</head>
<body>
<h2>Section 1</h2>
<h2>2. Epic 2</h2>
<div style="margin-left:15px;">
<h3>2.1. Feature 2</h3>
<div style="margin-left:15px;">
<h4>2.1.1. Backlog item 3</h4>
<div style="margin-left:15px;"></div>
<h4>2.1.2. Backlog item 4</h4>
<div style="margin-left:15px;"></div>
</div>
</div>
<p></p>
<h2>Section 2</h2>
<h2>1. Epic1</h2>
<div style="margin-left:15px;">
<h3>1.1. Feature1</h3>
<div style="margin-left:15px;">
<h4>1.1.1. Backlog item 1</h4>
<div style="margin-left:15px;"></div>
<h4>1.1.2. Backlog item 2</h4>
<div style="margin-left:15px;"></div>
</div>
</div>
Desired html output:
This is basesd on a current view in use that I'm trying to replicate. Might opt to not use the table later on, but the <ul> layout is what I'm after.
Also, the 'epic' node will likely not be used and can be excluded in the query generating the xml
<table>
<tr>
<td class=class1>Section 1</td> <!-- list all features from Path2 -->
</tr>
<tr>
<td>
<ul class=class2>
<li>Feature 3
<ul>
<li>Backlog item 5</li>
<li>Backlog item 6</li>
</ul>
</li>
<li>Feature 4
<ul>
<li>Backlog item 7</li>
<li>Backlog item 8</li>
</ul>
</li>
</ul>
</td>
</tr>
<tr>
<td class=class1>Section 2</td> <!-- list all features from Path1 -->
</tr>
<tr>
<td>
<ul class=class2>
<li>Feature1
<ul>
<li>Backlog item 1</li>
<li>Backlog item 2</li>
</ul>
</li>
<li>Feature 2
<ul>
<li>Backlog item 3</li>
<li>Backlog item 4</li>
</ul>
</li>
</ul>
</td>
</tr>
</table>
Your expected output is not clear. If you want a nested list, you could do simply:
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/result">
<html>
<body>
<ul>
<xsl:apply-templates select="workitem[#type != 'Bug' and starts-with(System.AreaPath, 'Path')]"/>
</ul>
</body>
</html>
</xsl:template>
<xsl:template match="workitem">
<li>
<xsl:number level="multiple" format="1. "/>
<xsl:value-of select="System.Title"/>
</li>
<xsl:if test="workitem">
<ul>
<xsl:apply-templates select="workitem"/>
</ul>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
and get:
Result
<html>
<body>
<ul>
<li>1. Epic1</li>
<ul>
<li>1.1. Feature1</li>
<ul>
<li>1.1.1. Backlog Item 1</li>
<li>1.1.2. Backlog Item 2</li>
</ul>
</ul>
<li>2. Epic 2</li>
<ul>
<li>2.1. Feature 2</li>
<ul>
<li>2.1.1. Backlog item 3</li>
<li>2.1.2. Backlog item 4</li>
</ul>
</ul>
</ul>
</body>
</html>

Odoo hide "Create" and "Edit" buttons depend on state and role

I would like to hide "Create" and "Edit" buttons on state and group role in form view .For example hide Create and Edit buttons when the state is not draft and user belongs to request user group.
As I understand hide buttons I can on editing views. And on group role rules I can disable create or edit.
I tried to write a rule for request user group but then user can't use the button but see it.
From view I found only way to hide default Create and Edit buttons:
<form string="Request" create="false" edit="false">
But in that way I hide them for all users for all states. Is there another way how can I hide Create and Edit buttons depend on state and group role?
I tried to expand the base.xml template on conditions state is "approved" or "done" and the group role is purchase_request_user and view id is view_purchase_request_form "Create" and "Edit" button:
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space='preserve'>
<t t-extend="FormView.buttons">
<t t-if="widget.fields_view.state !== 'done' or widget.fields_view.state !== 'approved'">
<div class="o_form_buttons_view">
<button t-if="widget.is_action_enabled('edit')"
type="button"
class="oe_form_button_edit btn btn-default btn-sm" accesskey="E">
Edit
</button>
<button t-if="widget.is_action_enabled('create')"
type="button" class="oe_form_button_create btn btn-default btn-sm"
accesskey="C">
Create
</button>
</div>
</t>
</t>
</templates>
added 'base' to dependences.
UPDATED base.xml Now I can change "Create" button name depend on my view name but nothing that depends on my module states.
<templates>
<t t-extend="FormView.buttons">
<t t-jquery="button.oe_form_button_create" t-operation="replace">
<t t-if="widget.fields_view.name == 'purchase.request.form'">
<button t-if="widget.is_action_enabled('create')"
type="button" class="oe_form_button_create btn btn-default btn-sm"
accesskey="C">
New button name
</button>
</t>
</t>
</t>
</templates>
My form view xml peace:
<openerp>
<data>
<record model="ir.ui.view" id="view_purchase_request_form">
<field name="name">purchase.request.form</field>
<field name="model">purchase.request</field>
<field name="arch" type="xml">
<form string="Purchase Request" create="false" edit="false">
<header>
<button name="%(action_sale_order_reset)d" attrs="{'invisible': [('state','not in', ('to_approve_first'))]}" string="Reset" type="action" groups="purchase_request.group_purchase_request_manager"/>
<button name="button_to_approve_first" states="draft" string="Request approval" type="object" class="oe_highlight"/>
<button name="button_approved" states="to_approve_first" string="Approve" type="object" class="oe_highlight" groups="purchase_request.group_purchase_request_manager"/>
<button name="button_approvedd" states="approved" string="Return Request" type="object" class="oe_highlight" groups="purchase_request.group_purchase_request_manager"/>
<button name="button_create_order" states="approvedd" string="Create Order" type="object" class="oe_highlight" groups="purchase_request.group_purchase_request_user"/>
<button name="button_to_approve_second" states="create_order" string="Approve" type="object" class="oe_highlight" groups="purchase_request.group_purchase_request_manager"/>
<button name="button_approved2" states="to_approve_second" string="Done" type="object" class="oe_highlight" groups="purchase_request.group_purchase_request_manager"/>
<button name="button_rejected" states="draft,approvedd" string="Reject" type="object" groups="purchase_request.group_purchase_request_user"/>
<field name="state" widget="statusbar" statusbar_visible="draft,to_approve_first,approved,rejected" statusbar_colors="{"approved":"green"}"/>
</header>
<sheet>
<group>
<group>
<field name="date_start" readonly="1"/>
<field name="participate_process"/>
</group>
<group>
<field name="requested_by" readonly="1"/>
<field name="assigned_to" attrs="{'readonly': [('state','not in', ('draft'))]}" />
</group>
<notebook>
<page string="Order" attrs="{'invisible': [('state','in', ('draft', 'to_approve_first', 'approved', 'approvedd'))]}">
<field name="supply_ids" attrs="{'readonly': [('state','not in', ('to_approve_second'))]}"/>
</page>
</notebook>
</sheet>
</form>
</field>
</record>
You have to write a template inheriting the 'FormView.buttons' one, check the context fields, like groups and state, and put a condition based on the wanted fields.
Something like this:
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space='preserve'>
<t t-extend="FormView.buttons">
<t t-if="widget.fields_view.state == <wanted_state>">
<your operations>
</t>
</t>
</templates>
Using this you can inspect all the FormView widget fields, you can find it in /odoo/addons/web/static/src/js/views/form_view.js.
I also found datarecord inside it, which should contain your state info and value.
Then, if you want to do the same with the buttons in edit mode, replace '.o_form_buttons_view' with '.o_form_buttons_edit'.
Tell me if you have problems. And again sorry for the delay, I was a little busy.
<t t-extend="FormView.buttons">
<t t-jquery=".o_form_buttons_view" t-operation="before">
<t t-log="widget"/>
</t>
</t>
Thank you! #Michele Zaccheddu using your answer I can get many types of the widget using
<t t-extend="FormView.buttons">
<t t-jquery=".o_form_buttons_view" t-operation="before">
<t t-log="widget"/>
</t>
</t>
Just put the code as a test and after update apps - go to form view, check using browser Developer Tools, In the console you will get the list from "Class", I'm using odoo 11 and can target
<t t-if="widget.initialState.data.state === 'draft'">
For other versions, please check the t-log yourself it can be different, but I haven't check for user group it may or may not be there...