How to find multiple patterns in single category using AIML - aiml

I have been using AIML to make chatbot. I am unable to find multiple patterns in same category. How can we use OR clause in the pattern?

In AIML version 2, you can do this using sets or maps. Basically you define the set which is a list of one or more members, then you can refer to it in the pattern. Imagine you had a set with the names of the countries of the world, you could code this:
<category>
<pattern>IS <set>countries</set> A COUNTRY</pattern>
<template>
Yes, <star/> is a country.
</template>
</category>
<category>
<pattern>IS * A COUNTRY</pattern>
<template>
I never heard of a country called <star/>.
</template>
</category>
This works because the set is higher priority than the star in AIML version 2. So if you typed IS GERMANY A COUNTRY it would reply "Yes, Germany is a country". But if you typed IS EREWHON A COUNTRY it would reply "I never heard of a country called Erewhon".

No, currently AIML supports only single pattern in a category. However, you may define multiple pattern and redirect them to original one by using 'srai' tag like:
<category><pattern># USA # Capital #</pattern><template>Capital of USA is DC.</template></category>
<category><pattern># Capital # USA #</pattern><template><srai># USA # Capital #</srai></template></category>

Related

Reg Expression, Handling a URL exclusions

I am trying to write a regexp to use with Crazyegg that will allow me to only gather data from my product pages.
My site structure is:
category page: www.sitename.com/categoryname/sub-categoryname
product page: www.sitename.com/productname/
My regex so far is:
^https?://([A-Za-z0-9.-]*\.)?sitename\.com/[A-Za-z0-9.-]*(/|/\?|)$
This allows everything that isnt at the sub category level (2nd level folder?)
the issue is that this allow top level categories so I need to exclude these by their name for example:
^https?://([A-Za-z0-9.-]*\.)?sitename\.com/(?!\babout\b|\bcheckout\b)(/|/\?|)$
Could you please help me get the exclusion correct? ive also tried doing using [^\babout\b|\bcheckout\b]
if you only want product pages, the regex for capture product pages is:
".*productname"
For capture category pages: ".*categoryname/sub-categoryname"
I hope help you. If you have more questions, ask me!

Tokenizing Product Models

Looking to match some product info, returning structured data and rewriting or looking up the value.
Example input:
"I have a 1999 Cat (D-6) and an Ingersoll Rand Model Z for sale"
From which I want to create something like
[ { year:1999, brand:"CATERPILLAR", model:"D6" },
{ year:null, brand:"INGERSOLL-RAND", model:"MODEL Z" } ]
Based on known data:
/\d{4}/, YEAR
...
/cat(erpill[ae]r)/, BRAND, "CATERPILLAR"
...
/d[\-\s]6/, MODEL, "D6"
Can this be done with Regex alone? Or do I need a Lexer?
I can figure out the regexes no problem, but confused about the re-writing part, and grouping things together
I think you want to extract car trading details.
Here you need NLP ,You can use Stanford Core NLP to design your own NLP regex or you can train a dataset.
but Stanford NER is developed model which will give you entities like Date and time , organization also location , person ,percentage and price.
other related tools: apache openNLP , aylien

Use Yahoo Pipes to convert RSS html tags to standard tag items

I want to move from using bookmarking service Delicious to Diigo, but the way diigo organise tags in their RSS is preventing the move.
I want to use a Yahoo Pipe to turn Diigo rss tags into the same format as Delicious rss tags
Diigo tags are stored as a html list at the bottom of the 'Description' item, like this:
Some test describing the link.
<p class="diigo-tags"><strong>Tags:</strong>
<a rel="nofollow" target="_blank" href='https://www.diigo.com/user/username/firsttag'>firsttag</a>
<a rel="nofollow" target="_blank" href='https://www.diigo.com/user/username/2ndtag'>2ndtag</a>
<a rel="nofollow" target="_blank" href='https://www.diigo.com/user/username/anothertag'>anothertag</a>
etc... </p>
I need to extract each of these and store them in their own item. Delicious stores each tag in a nested field category by number, like this:
category
0
domain http://delicious.com/username/
content firsttag
1
domain http://delicious.com/username/
content 2ndtag
So, the Yahoo Pipe needs to strip the html list and separate each tag into single category fields.
Not sure where to start, except maybe this regular expression in regex to strip the html:
(?si)<a[^<>]*?[^<>]*>(.*?)</a>
Any advice appreciated.
You can extract the tags from the diigo stream by performing the following replacements using the Regex operator:
replace <a[^<>]*?[^<>]*>(.*?)</a> with $1, using options g and s (the tag itself within the <a>...</a>)
replace <.+> with nothing, using options g and m (delete all HTML tags)
replace [\s]+ with a single space, using options g and s
As a result, the description field now contains the list of tags separated by spaces. I'm not sure what you need next, if you tell me I can try to help.
Here's the pipe:
https://pipes.yahoo.com/pipes/pipe.info?_id=1656d9fcab9d9ed6016bdae7486ee71f
UPDATE
I see, the tricky part is adding multiple category nodes to an RSS feed. Unfortunately, I don't think that's possible. I updated the pipe, so that now you have item.category.1, .2, .3, and so on, but when you look at the RSS output of the pipe, it doesn't show any categories. (I think this might be related to the fact that the Create RSS operator doesn't have a category field either.)
In the JSON output there are multiple categories correctly.
I also tested that if there is only one category field, it would show up correctly in the RSS output. If there are more than one then no.
And I'm afraid this is as far as I can get you.

Regex Input Validation Limit to maximum no. of commas

I am running jQuery Autocomplete with a Laravel form field.
It grabs data from my db
Specialty Area Examples: Real Estate, Mortgage Lenders, Renovation, Buyer's Agent, Listing Agent, Relocation, Short-Sale, Consulting, Local Experts, Refinancing, Architecture, Home Building, Carpentry, Electrical, Engineering, Interior Design, Landscaping, Painting, Plumbing, Appraisal, Commercial Property, Insurance, Legal, Conveyancing,
Users can type in one of the examples and the autocomplete will complete the rest in the field.
I want to limit the user to being allowed to input a maximum of 4 Specialty Area Examples into the form field. So a user can type in for example:
Real Estate, Short-Sale, Consulting, Local Experts
After that the user should not be allowed to input more data. So the maximum number of commas I need to set in the form field is 3.
Try this:
$("#txtBox").keypress(function (e) {
var input = $(this).val() + String.fromCharCode(e.which);
if (input.split(',').length > 4) {
e.preventDefault();
}
});
Demo: http://jsfiddle.net/y6eQF/
This RegEx should do what you want: ([a-zA-Z0-9\-\_\ \'\"]+\,){3}[a-zA-Z0-9\-\_\ \'\"]+
You can also do it with split() as Vinod mentioned. In PHP you have split()/explode() as well.

Django countries order by translated name

I started using django_countries and added a field to one of my models
country = CountryField(blank=True)
The problem is the users language is spanish and when the form shows the list of countries they are correctly translated, but they ordered by the code I guess, or by the English name.
I want it to be ordered by the display name so the users can easily search any country by typing the first letter and then going down until the find it (the way most of people does).
Any ideas?
Thank uou for your time
This was the solution, based on this
function sort(a, b) {
return (a.innerHTML > b.innerHTML) ? 1 : -1;
};
$('#select_id option').sort(sort).appendTo('#select_id');
If you want to do it server side, you can do something like this:
things = sorted(things, key=lambda thing:Country(thing['country']).name)
That's what I used.