What conditions can be checked in the "Found" options for a Watson Assistant dialog's slots? - watson-assistant

What kinds of conditions can go in the "If Assistant Recognizes" entries in the "Found" options for a Watson Assistant dialog's slots?
For example, if Assistant recognizes #sys-location how do do I configure responses based on the recognized value?
The following does not work:

Your best bet for "if assistant recognizes" is to use entities. In your example above, where you might want to customize a response based on a specific location, you could define a #location entity and add target values like #location:germany and #location:france. One benefit to this approach is that you can use entity value synonyms to easily expand recognition of common alternate names (e.g. for #location:germany you could have synonyms like deutschland, berlin, bavaria, etc.) so your bot can handle those without you needing to build all of that out in the dialog logic.

Related

How I can send command to the person agents living in one specific GIS region? Consider there are several GIS regions

Suppose there are 1000 Person agent on 4 (a,b, c,d) GIS region area. On a certain event, I want to communicate with all the agents living inside GIS region "a" . In "a" region we have 200 person agents.If I send message or command to Person state chart, how I can make sure that only those 200 person agents living on that specific GIS region "a" is getting my command? Is there any way to model that?
You can filter messages inside the Agent's statechart transition, in order to only executethe transition when a certain expression is true (in your case: Agent is in the right region).
Of course you could do this filtering in a lot of other places too, for example when sending the message, or when receiving it. However you can always use this code to check if the Agent is located inside of a GISRegion:
main.gisRegion1.contains(this.getLatitude(), this.getLongitude())
This is assuming you executed this inside the Agent (therefore main. and this.) and the region you are looking for is named gisRegion1.

How to get all allowed languages for Wikidata

I'm writing a tool for interacting with Wikidata where labels and descriptions are added to items. But I would like to validate that the language is supported before trying to add it.
So my question is how do I get a list of the allowed language codes. The documentation describes this as UserLanguageCode but gives no info on retrieving the allowed values.
I know I can get a list of all of the used languages by doing the following SQL operation on the database, but that is both slow and inefficient: SELECT DISTINCT term_language FROM wb_terms.
As an aside is the list of allowed languages the same for MonolingualText statements?
There is now an API for getting the supported content languages (API sandbox):
https://www.wikidata.org/w/api.php?action=query&meta=wbcontentlanguages&wbclcontext=term&format=json&formatversion=2
By default it just returns the language code, but you can add the name and/or autonym (name in that language) via the wbclprop parameter. (To control the language in which the name is returned, set the global uselang parameter.)
To get allowed monolingual text languages, set wbclcontext to monolingualtext instead of term; on Wikidata, you can also set it to term-lexicographical for all language codes supported on lexicographical data (almost but not quite identical to the term languages).
User hoo on IRC channel #wikidata found this solution:
Get the JSON payload at this address:
https://www.wikidata.org/w/api.php?action=paraminfo&modules=wbsetlabel
And extract
modules[0].parameters[8].type
There are indeed less languages in this list than all the UI languages for MediaWiki.

How to negate this regex

The following regex will do validation for the P. O. Box is entered in the text box,
\b[P|p](OST|ost)?[.\s-]+[O|o](FFICE|ffice)?[.\s-]+[B|b](OX|ox)\b
i want to negate this so as to detect whether user is not entering P. O. Box it in the text box,
I know that we can do it by using javascript also, but my platform has different form structure, its demandware form, where i have regex as the field attribute.
We can submit a regex in this field and it will validate it automatically.Any idea?
I recommend not attempting to do this with a regular expression. It is way too easy to defeat1. Instead, you need to out source the problem to someone who knows what they are doing. In this case, since you are dealing with US addresses only, the USPS.
So, you should use the USPS address standarization/verification API. You can submit an address, and it will return to you a "cleaned" version of that address. It will tell you whether or not the address is valid. And if it is a post office box, it will return it to you in a standardized format and now you don't need a regular expression that can be defeated, now you only need a simple string match. And, as an added bonanza, you'll get a standardized and validated representation of the delivery address reducing2 the possibility of error.
I recognize I am sidestepping your actual engineering question. But part of engineering is abandoning solutions that are the wrong path. You need to validate addresses. So validate addresses rather than trying to build a state machine that can detect some inputs that represent post office boxes but will fail on others. And the USPS provides a validation service and they are the authoritative experts here.
1: I am not saying that you'll face adversaries, just you'll face all the creative, sloppy, lazy ways that people have for entering in their addresses.
2: But not eliminating.
You need to use a negative lookaround: (?!pattern).
In this case
(?! \b[P|p](OST|ost)?[.\s-]+[O|o](FFICE|ffice)?[.\s-]+[B|b](OX|ox)\b )
For reference:
Regex lookarounds
You can use this pattern:
^(?:[^p]+|\Bp+|p(?!(?:ost)?[.\s-]+o(?:ffice)?[.\s-]+box\b))+$
The idea is to test only substrings that begin with "p" (for more performances). To make this check case insensitive, you can add (?i) at the begining of the pattern:
^(?i)(?:[^p]+|\Bp+|p(?!(?:ost)?[.\s-]+o(?:ffice)?[.\s-]+box\b))+$
If the regex flavor is JavaScript's, then you can use negative look-ahead:
^(?!.*?\b[Pp](OST|ost)?[.\s-]+[Oo](FFICE|ffice)?[.\s-]+[Bb](OX|ox)\b)

authorized.net ambiguity in country names

Hi I am working on a site and integrating authorize.net payment gateway. I am thinking of adding a dropdown for country names, will passing of "United States Of America" as country variable work? Or should I use "US"? Should I use ISO codes for every country? I tried on test developer account but it seems to accept everything I passes to it as correct!
~Ajit
I know authorize.net doesn't require country names. A simple way to see if they even validate them would be to run a transaction through the production gateway, pass a nonsense value and see if the transaction still goes through.
If you do standardize to support authorize.net (or for another reason), I'd suggest country codes versus full names. Codes seem to change less often, and also can be useful as identifiers. For example, I have an application which presents data for roughly 200 countries; I have flag icons (multiple sizes for each country) that use a 2 digit country code in their name. Using codes made this fairly easy to implement and maintain.
According to their AIM Guide:
x_country: Optional
Value: The country of the customer’s billing
Format: Up to 60 characters (no symbols)

Deal with undefined values in code or in the template?

I'm writing a web application (in Python, not that it matters). One of the features is that people can leave comments on things. I have a class for comments, basically like so:
class Comment:
user = ...
# other stuff
where user is an instance of another class,
class User:
name = ...
# other stuff
And of course in my template, I have
<div>${comment.user.name}</div>
Problem: Let's say I allow people to post comments anonymously. In that case comment.user is None (undefined), and of course accessing comment.user.name is going to raise an error. What's the best way to deal with that? I see three possibilities:
Use a conditional in the template to test for that case and display something different. This is the most versatile solution, since I can change the way anonymous comments are displayed to, say, "Posted anonymously" (instead of "Posted by ..."), but I've often been told that templates should be mindless display machines and not include logic like that. Also, other people might wind up writing alternate templates for the same application, and I feel like I should be making things as easy as possible for the template writer.
Implement an accessor method for the user property of a Comment that returns a dummy user object when the real user is undefined. This dummy object would have user.name = 'Anonymous' or something like that and so the template could access it and print its name with no error.
Put an actual record in my database corresponding to a user with user.name = Anonymous (or something like that), and just assign that user to any comment posted when nobody's logged in. I know I've seen some real-world systems that operate this way. (phpBB?)
Is there a prevailing wisdom among people who write these sorts of systems about which of these (or some other solution) is the best? Any pitfalls I should watch out for if I go one way vs. another? Whoever gives the best explanation gets the checkmark.
I'd go with the first option, using an if switch in the template.
Consider the case of localization: You'll possibly have different templates for each language. You can easily localize the "anonymous" case in the template itself.
Also, the data model should have nothing to do with the output side. What would you do in the rest of the code if you wanted to test whether a user has a name or not? Check for == 'Anonymous' each time?
The template should indeed only be concerned with outputting data, but that doesn't mean it has to consist solely of output statements. You usually have some sort of if user is logged in, display "Logout", otherwise display "Register" and "Login" case in the templates. It's almost impossible to avoid these.
Personally, I like for clean code, and agree that templates should not have major logic. So in my implementations I make sure that all values have "safe" default values, typically a blank string, pointer to a base class or equivalent. That allows for two major improvements to the code, first that you don't have to constantly test for null or missing values, and you can output default values without too much logic in your display templates.
So in your situation, making a default pointer to a base value sounds like the best solution.
Your 3rd option: Create a regular User entity that represents an anonymous user.
I'm not a fan of None for database integrity reasons.