AIML not printing anything within this one condition loop; XCAR in nested category inside that condition loop treating input sentence as a single word - aiml

Using the standard library.
The code looks like <srai>XCAR AB, CD</srai>
But the stack trace shows [0] srai of XCAR AB,CD with the space removed.
Using Pandorabots.com.
I'm trying to loop though a string of , -delineated words of uniform length using XSUBSTRING, in order to map each one to a human-readable output.
So I'm using a nested category to get and print the XCAR of each XSUBSTRING based on the updated index predicate from the outer category.
Here's the code for the outer category:
<category>
<pattern>COMMAND</pattern>
<template>
<think>
<set name="index">0</set>
<set name="allitemsprinted">FALSE</set>
</think>
This part prints for me.
<br/><br/>
So does this.
<!-- iterate through "ties" -->
<condition name="allitemsprinted" value="FALSE">
But this doesn't print.
Nor does anything after.
This srai works correctly:
<srai>XCDR UX, SE, CS</srai>
<srai>PRINT ITEM</srai>
<loop/>
</condition>
<br/>
</template>
</category>
And here's the nested category:
<category>
<pattern>PRINT ITEM</pattern>
<template>
<think>
<set var="itemlocation">
<!-- 2-char name plus delim -->
<srai>XMUL <get name="index"/> XS 4</srai>
</set>
<set var="remainingitems">
<srai>XSUBSTRING <get name="items"/> XS <get var="itemlocation"/></srai>
</set>
<!-- increment index -->
<set name="index">
<map name="successor">
<get name="index"/>
</map>
</set>
<!-- check for end of list -->
<set name="allitemsprinted">
<srai>XGT <get name="index"/> XS <get name="itemcount"/></srai>
</set>
</think>
Remaining items: <get var="remainingitems"/>
First remaining item: <srai>XCAR <get var="remainingitems"/></srai>
<!-- human-readable output -->
<map name="itemsreadable">
<srai>XCAR <get var="remainingitems"/></srai>
</map>
<br/>
</template>
</category>
The stack trace provided by Pandorabots shows that the <srai> inside the <condition> does indeed get called. But it won't print anything at all.

First, make sure normal.substitution has an entry for removing commas [",", ""], as it's very rare that the bot needs to process commas.
Assuming your map is something like this:
[
["UX", "User Experience"],
["SE", "Sales Entry"],
["CS", "Customer Services"]
]
You can then do this to get human readable output (you don't need the standard library for this):
<category>
<pattern>COMMAND</pattern>
<template>
<think><set name="itemlist">UX, SE, CS</set></think>
<srai>PRINT ITEM <get name="itemlist"/></srai>
</template>
</category>
<category>
<pattern>PRINT ITEM * *</pattern>
<template>
<map name="itemsreadable"><star/></map><br/>
<srai>PRINT ITEM <star index="2"/></srai>
</template>
</category>
<category>
<pattern>PRINT ITEM *</pattern>
<template>
<map name="itemsreadable"><star/></map>
</template>
</category>
This will produce the following:

Related

AIML how to check if the input string matches one from a map

I am trying to compare if the user's input matches the expected answer in AIML. I found this code that works well when the value is true but, for some reason I can't understand, fails when the match is false (there is no match for the and goes to UDC). If it worked, I could easily replace the second * with my maps result.
From: https://github.com/pandorabots/aiml-utilities/blob/master/lib/aimlstandardlibrary.aiml
<!-- STRING EQUALS-->
<category>
<pattern>XEQ * XS *</pattern>
<template>
<learn>
<category>
<pattern>
<eval>
<uppercase>XFALSE <star/></uppercase>
</eval>
</pattern>
<template>TRUE</template>
</category>
</learn>
<srai>XFALSE <star index="2"/></srai>
<learn>
<category>
<pattern>
<eval>
<uppercase>XFALSE <star/></uppercase>
</eval>
</pattern>
<template>FALSE</template>
</category>
</learn>
</template>
</category>
Does anyone have a better way to do it? Thanks a lot.
Did you include the entire library AIML file? You need this category for it to work (it's at the top of the file):
<category>
<pattern>
XFALSE *
</pattern>
<template>FALSE</template>
</category>
Without it, the UDC will be called. A more efficient method would be to use the condition tag. This removes the need to use the <learn> tag to set up extra categories:
<category>
<pattern>XEQ * XS *</pattern>
<template>
<think>
<set name="value1"><star/></set>
<set name="value2"><star index="2"/></set>
</think>
<condition name="value1">
<li><value><get name="value2"/></value>TRUE</li>
<li>FALSE</li>
</condition>
</template>
</category>

reach a webservice on a java angular project deployed on jetty 9.4.12

I have a java angular project that I deploy on jetty 9.4.12
Here is my web.xml file
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>Tourism Applicationwith Angular</display-name>
<description>
This is a simple web application with a source code organization
based on the recommendations of the Application Developer's Guide.
</description>
<display-name>Archetype Created Web Application</display-name>
<listener>
<listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>
</listener>
<listener>
<listener-class>
org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap
</listener-class>
</listener>
<resource-env-ref>
<description>Object factory for the CDI Bean Manager</description>
<resource-env-ref-name>BeanManager</resource-env-ref-name>
<resource-env-ref-type>javax.enterprise.inject.spi.BeanManager</resource-env-ref-type>
</resource-env-ref>
<servlet>
<servlet-name>Resteasy</servlet-name>
<servlet-class>
org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher
</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>webservice.TourismWebService</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Resteasy</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<context-param>
<param-name>resteasy.injector.factory</param-name>
<param-value>org.jboss.resteasy.cdi.CdiInjectorFactory</param-value>
</context-param>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
Here is my web service
package webservice;
import java.util.ArrayList;
import java.util.List;
import javax.inject.Inject;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Application;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.jboss.resteasy.cdi.CdiInjectorFactory;
import org.slf4j.Logger;
import business.TourismBusinessService;
import dto.SearchPathDto;
import dto.TourismPathDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
#Path("/tourism")
#Api(value = "analyses", description = "search path by userId, location and max distance")
#Produces(MediaType.APPLICATION_JSON)
#Consumes(MediaType.APPLICATION_JSON)
public class TourismWebService extends Application {
#Inject
private Logger logger;
#Inject
private TourismBusinessService tourismBusinessService;
#GET
#Path("searchPath/{userId}/{longitude}/{latitude}/{distanceMax}")
#ApiOperation("Get analysis by Id")
#ApiResponse(code = 200, message = "OK")
public Response searchPath(#PathParam("userId") long userId,#PathParam("longitude") double longitude,#PathParam("latitude") double latitude,#PathParam("distanceMax") double distanceMax) {
SearchPathDto responseDto = new SearchPathDto();
//org.jboss.resteasy.cdi.CdiInjectorFactory test = new org.jboss.resteasy.cdi.CdiInjectorFactory();
List<TourismPathDto> tourismPathDtoList = new ArrayList<>();
TourismPathDto tourismPathDto1 = new TourismPathDto();
tourismPathDto1.setCategoryId(1);
tourismPathDto1.setDistance((double)100);
tourismPathDto1.setLongitude(2.3313926);
tourismPathDto1.setLatitude(48.873278);
tourismPathDto1.setRoot("root1");
tourismPathDto1.setLeaf("leaf1");
tourismPathDto1.setWeight((double)2);
tourismPathDto1.setMark((double)3);
tourismPathDtoList.add(tourismPathDto1);
TourismPathDto tourismPathDto2 = new TourismPathDto();
tourismPathDto2.setCategoryId(2);
tourismPathDto2.setDistance((double)200);
tourismPathDto2.setLongitude(2.3368291);
tourismPathDto2.setLatitude(48.8747394);
tourismPathDto2.setRoot("root2");
tourismPathDto2.setLeaf("leaf2");
tourismPathDto2.setWeight((double)3);
tourismPathDto2.setMark((double)4);
tourismPathDtoList.add(tourismPathDto2);
responseDto.setDistanceMax(distanceMax);
responseDto.setLatitude(latitude);
responseDto.setLongitude(longitude);
responseDto.setUserId(userId);
responseDto.setTourismPathDtoList(tourismPathDtoList);
//SearchPathDto responseDto = tourismBusinessService.getTourismPathList(userId, longitude, latitude, distanceMax);
if (responseDto == null)
throw new WebApplicationException(Response.Status.NOT_FOUND);
return Response.ok(responseDto).build();
}
}
I ran jetty : java -jar start.jar
But when I try to reach the following web service
http://localhost:8080/tourism-services/tourism/searchPath/1/2.3313926/48.873278/200
I have a
HTTP ERROR 404
Problem accessing /tourism-services/tourism/searchPath/1/2.3313926/48.873278/200. Reason:
Not Found
error
Thank you for your help
Here is the continuation......
the jetty.xml that I modified is the following
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">
<!-- =============================================================== -->
<!-- Documentation of this file format can be found at: -->
<!-- https://www.eclipse.org/jetty/documentation/current/ -->
<!-- -->
<!-- Additional configuration files are available in $JETTY_HOME/etc -->
<!-- and can be mixed in. See start.ini file for the default -->
<!-- configuration files. -->
<!-- -->
<!-- For a description of the configuration mechanism, see the -->
<!-- output of: -->
<!-- java -jar start.jar -? -->
<!-- =============================================================== -->
<!-- =============================================================== -->
<!-- Configure a Jetty Server instance with an ID "Server" -->
<!-- Other configuration files may also configure the "Server" -->
<!-- ID, in which case they are adding configuration to the same -->
<!-- instance. If other configuration have a different ID, they -->
<!-- will create and configure another instance of Jetty. -->
<!-- Consult the javadoc of o.e.j.server.Server for all -->
<!-- configuration that may be set here. -->
<!-- =============================================================== -->
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<Arg name="threadpool"><Ref refid="threadPool"/></Arg>
<!-- =========================================================== -->
<!-- Add shared Scheduler instance -->
<!-- =========================================================== -->
<Call name="addBean">
<Arg>
<New class="org.eclipse.jetty.util.thread.ScheduledExecutorScheduler"/>
</Arg>
</Call>
<Ref refid="DeploymentManager">
<Call name="addLifeCycleBinding">
<Arg>
<New
class="org.eclipse.jetty.cdi.servlet.WeldDeploymentBinding">
</New>
</Arg>
</Call>
</Ref>
<!-- =========================================================== -->
<!-- Http Configuration. -->
<!-- This is a common configuration instance used by all -->
<!-- connectors that can carry HTTP semantics (HTTP, HTTPS, etc.)-->
<!-- It configures the non wire protocol aspects of the HTTP -->
<!-- semantic. -->
<!-- -->
<!-- This configuration is only defined here and is used by -->
<!-- reference from other XML files such as jetty-http.xml, -->
<!-- jetty-https.xml and other configuration files which -->
<!-- instantiate the connectors. -->
<!-- -->
<!-- Consult the javadoc of o.e.j.server.HttpConfiguration -->
<!-- for all configuration that may be set here. -->
<!-- =========================================================== -->
<New id="httpConfig" class="org.eclipse.jetty.server.HttpConfiguration">
<Set name="secureScheme"><Property name="jetty.httpConfig.secureScheme" default="https" /></Set>
<Set name="securePort"><Property name="jetty.httpConfig.securePort" deprecated="jetty.secure.port" default="8443" /></Set>
<Set name="outputBufferSize"><Property name="jetty.httpConfig.outputBufferSize" deprecated="jetty.output.buffer.size" default="32768" /></Set>
<Set name="outputAggregationSize"><Property name="jetty.httpConfig.outputAggregationSize" deprecated="jetty.output.aggregation.size" default="8192" /></Set>
<Set name="requestHeaderSize"><Property name="jetty.httpConfig.requestHeaderSize" deprecated="jetty.request.header.size" default="8192" /></Set>
<Set name="responseHeaderSize"><Property name="jetty.httpConfig.responseHeaderSize" deprecated="jetty.response.header.size" default="8192" /></Set>
<Set name="sendServerVersion"><Property name="jetty.httpConfig.sendServerVersion" deprecated="jetty.send.server.version" default="true" /></Set>
<Set name="sendDateHeader"><Property name="jetty.httpConfig.sendDateHeader" deprecated="jetty.send.date.header" default="false" /></Set>
<Set name="headerCacheSize"><Property name="jetty.httpConfig.headerCacheSize" default="4096" /></Set>
<Set name="delayDispatchUntilContent"><Property name="jetty.httpConfig.delayDispatchUntilContent" deprecated="jetty.delayDispatchUntilContent" default="true"/></Set>
<Set name="maxErrorDispatches"><Property name="jetty.httpConfig.maxErrorDispatches" default="10"/></Set>
<Set name="blockingTimeout"><Property deprecated="jetty.httpConfig.blockingTimeout" name="jetty.httpConfig.blockingTimeout.DEPRECATED" default="-1"/></Set>
<Set name="persistentConnectionsEnabled"><Property name="jetty.httpConfig.persistentConnectionsEnabled" default="true"/></Set>
<Set name="cookieCompliance"><Call class="org.eclipse.jetty.http.CookieCompliance" name="valueOf"><Arg><Property name="jetty.httpConfig.cookieCompliance" default="RFC6265"/></Arg></Call></Set>
<Set name="multiPartFormDataCompliance"><Call class="org.eclipse.jetty.server.MultiPartFormDataCompliance" name="valueOf"><Arg><Property name="jetty.httpConfig.multiPartFormDataCompliance" default="RFC7578"/></Arg></Call></Set>
</New>
<!-- =========================================================== -->
<!-- Set the default handler structure for the Server -->
<!-- A handler collection is used to pass received requests to -->
<!-- both the ContextHandlerCollection, which selects the next -->
<!-- handler by context path and virtual host, and the -->
<!-- DefaultHandler, which handles any requests not handled by -->
<!-- the context handlers. -->
<!-- Other handlers may be added to the "Handlers" collection, -->
<!-- for example the jetty-requestlog.xml file adds the -->
<!-- RequestLogHandler after the default handler -->
<!-- =========================================================== -->
<Set name="handler">
<New id="Handlers" class="org.eclipse.jetty.server.handler.HandlerCollection">
<Set name="handlers">
<Array type="org.eclipse.jetty.server.Handler">
<Item>
<New id="Contexts" class="org.eclipse.jetty.server.handler.ContextHandlerCollection"/>
</Item>
<Item>
<New id="DefaultHandler" class="org.eclipse.jetty.server.handler.DefaultHandler"/>
</Item>
</Array>
</Set>
</New>
</Set>
<!-- =========================================================== -->
<!-- extra server options -->
<!-- =========================================================== -->
<Set name="stopAtShutdown"><Property name="jetty.server.stopAtShutdown" default="true"/></Set>
<Set name="stopTimeout"><Property name="jetty.server.stopTimeout" default="5000"/></Set>
<Set name="dumpAfterStart"><Property name="jetty.server.dumpAfterStart" deprecated="jetty.dump.start" default="false"/></Set>
<Set name="dumpBeforeStop"><Property name="jetty.server.dumpBeforeStop" deprecated="jetty.dump.stop" default="false"/></Set>
</Configure>
In this file, I added the following
<Ref refid="DeploymentManager">
<Call name="addLifeCycleBinding">
<Arg>
<New
class="org.eclipse.jetty.cdi.servlet.WeldDeploymentBinding">
</New>
</Arg>
</Call>
and I added this dependency to maven
<dependency>
<groupId>org.eclipse.jetty.cdi</groupId>
<artifactId>cdi-servlet</artifactId>
<version>9.4.12.v20180830</version>
</dependency>
But I got this error
MBP-de-Admin:jetty-distribution-9.4.12.v20180830 admin$ java -jar start.jar
2019-02-06 07:49:05.745:INFO::main: Logging initialized #841ms to org.eclipse.jetty.util.log.StdErrLog
2019-02-06 07:49:05.912:WARN:oejx.XmlConfiguration:main: Config error at <Ref refid="DeploymentManager"><Call name="addLifeCycleBinding"><Arg>| <New class="org.eclipse.jetty.cdi.servlet.WeldDeploymentBinding"/>| </Arg></Call></Ref> java.lang.IllegalStateException: No object for refid=DeploymentManager in file:/Users/admin/Application-Marwen/Jetty/jetty-distribution-9.4.12.v20180830/etc/jetty.xml
2019-02-06 07:49:05.913:WARN:oejx.XmlConfiguration:main:
java.lang.IllegalStateException: No object for refid=DeploymentManager
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.refObj(XmlConfiguration.java:891)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.configure(XmlConfiguration.java:487)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.configure(XmlConfiguration.java:413)
at org.eclipse.jetty.xml.XmlConfiguration.configure(XmlConfiguration.java:311)
at org.eclipse.jetty.xml.XmlConfiguration$1.run(XmlConfiguration.java:1558)
at org.eclipse.jetty.xml.XmlConfiguration$1.run(XmlConfiguration.java:1512)

QT XML reader reads the same tag everytime

I try to read an XML file and the reader reads it well, until it reads one specific tag (the close tag of Categories) and afterwards it read this tag infinite times.
This is the xml file:
<?xml version="1.0" encoding="utf-8"?>
<MovieMain MovieName="movie1" Version="1.29746.011215">
<FrameGroups FirstFrame="START" LastFrame="END">
<GroupFramesDescription>ALL MOVIE</GroupFramesDescription>
<frames Framenumber="1" >
<ObjectsGroup Name="1">
<LeftUpCorner X="30" Y="124" Z="0" />
<RightDownCorner X="53" Y="160" Z="0" />
<InfoAtt AttName="INDEX" AttInfo="1" />
<Categories>
<Category Name="computer" Probability="0.79" />
<Category Name="pen" Probability="0.7" />
<Category Name="desktop" Probability="0.1" />
<Category Name="mug" Probability="0.09" />
</categories>
</ObjectsGroup>
</frames>
</FrameGroups>
</MarkingChanges>
<ChangesList UserName="ooo" Date="12/3/2015" ChangesetIndex="1" />
</MarkingChanges>
</MovieMain>
And this is the function that I call to read the next element:
orXmlReader->readNextStartElement();
It gives me every time the next element till the close tag of Categories and than it read it again and again (I tried a loop of 100 times...).
I hope that you will help me as soon as you can,
Thanks.
Opening tag is <Categories> and closing is </categories> , i believe that search is case sensitive. Can you try with </Categories> as closing tag?

Adding dynamic parameters in fremarker android studio

I am creating a template using freemarker. I want to add few parameters at runtime. How it can be done. The following is a sample template code:
<?xml version="1.0"?>
<template
minApi="7"
minBuildApi="8">
<category />
<dependency name="android-support-v4" revision="8" />
<parameter
id="packageName"
name="Package name"
type="string"
constraints="package"
default="com.mycompany.myapp" />
...
...
...
<!-- 128x128 thumbnails relative to template.xml -->
<thumbs>
<!-- default thumbnail is required -->
<thumb>thumb_file.png</thumb>
</thumbs>
<globals file="globals.xml.ftl" />
<execute file="recipe.xml.ftl" />
I want to generate a parameter while clicking a button in the template. Is it possible to do so? Is there any proper documentation available.
You can use the visibility attribute. For example, in the following:
<parameter
id="includeLayout"
name="Create layout XML?"
type="boolean"
default="true"
help="Generate a layout XML" />
<parameter
id="layoutName"
name="Layout Name"
type="string"
constraints="layout|nonempty|unique"
default="fragment_default"
visibility="includeLayout"
suggest="fragment_${camelCaseToUnderscore(className)}"
help="The name of the fragment layout to create" />
visibility="includeLayout" means that that field will only be visible when includeLayout is checked as true

How to prevent Jetty from showing context related information

I am using Jetty to deploy a production website. Let's assume my website is foo.com When I point my browser to a context which does not exist (say foo.com/notavailable), Jetty shows an error page with information of all the contexts which are deployed on it.
It looks something like this:
No context on this server matched or handled this request.
Contexts known to this server are:
/test ---> org.mortbay.jetty.webapp.WebAppContext#6910fe28{/test,/root/webserver/jetty-6.1.4/webapps/test}
I want to prevent Jetty from showing this message because it contains the full path to the context on the server.
Is there a way to do this?
When configuring Jetty XML you can set showContexts to false on the DefaultHandler.
If you are using older Jetty versions replace org.eclipse.jetty on my example with the old org.mortbay.jetty package structure.
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<!-- =========================================================== -->
<!-- Set handler Collection Structure -->
<!-- =========================================================== -->
<Set name="handler">
<!-- the collection of handlers that will handle the request -->
<New id="Handlers" class="org.eclipse.jetty.server.handler.HandlerCollection">
<Set name="handlers">
<Array type="org.eclipse.jetty.server.Handler">
<!-- primarily handles the request and maps the request to a ContextHandler -->
<Item>
<New id="Contexts" class="org.eclipse.jetty.server.handler.ContextHandlerCollection"/>
</Item>
<!-- The default handler ... handles the request if not yet handled -->
<Item>
<New id="DefaultHandler" class="org.eclipse.jetty.server.handler.DefaultHandler"/>
</Item>
<!-- The handler for your request logs -->
<Item>
<New id="RequestLog" class="org.eclipse.jetty.server.handler.RequestLogHandler"/>
</Item>
</Array>
</Set>
</New>
</Set>
<!-- ===================== -->
<!-- DefaultHandler config -->
<!-- ===================== -->
<Ref id="DefaultHandler">
<Set name="showContexts">false</Set>
</Ref>
</Configure>
Maybe you'll also be wanting to prevent directory browsing configuring the DefaultServlet of your web.xml,
<servlet>
<servlet-name>default</servlet-name>
<servlet-class>org.eclipse.jetty.servlet.DefaultServlet</servlet-class>
<init-param>
<param-name>dirAllowed</param-name>
<param-value>false</param-value>
</init-param>
<load-on-startup>0</load-on-startup>
</servlet>
That page is provided by the Jetty "DefaultHandler"
http://svn.codehaus.org/jetty/jetty/branches/jetty-6.1/modules/jetty/src/main/java/org/mortbay/jetty/handler/DefaultHandler.java
To stop that page from displaying, you should remove that handler from your server (it's configured in your jetty.xml file)
You don't really need (or want) the default handler on a production (internet facing) server, so it's a good idea to remove it.
Note, that it also provides the regular 404 page, and the favicon.ico so if you're relying on those behaviours then you'll need to put in a replacement.
Jetty 9.X version has come up with showContexts property in org.eclipse.jetty.servlet.DefaultServlet class. Hence we can set the showContexts to flase, if you do not want to show the contexts list.
<Item>
<New id="DefaultHandler" class="org.eclipse.jetty.server.handler.DefaultHandler">
<Set name="showContexts">false</Set>
</New>
</Item>