Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance nools to include a query, basically LHS only execution #160

Open
williamwsmith opened this issue Oct 26, 2015 · 0 comments
Open

Comments

@williamwsmith
Copy link

In the nools DSL something like this:

query GoodbyeQuery {
when
{
m : Message m.text =~ /.*goodbye$/;
}

The results is an array of matched facts.
To use from a session:

//Accumlate the matching facts by pushing them onto an array
var matchedFacts = session.getQueryResults("GoodbyeQuery");
console.log(matchedFacts[0].m);

Adding parameters would be very helpful. Might use some for of the existing
options syntax to define params:

query GoodbyeQuery {
parameters : { regex : null };
when
{
m : Message m.text =~ parameters.regex; // or just regex
}

//To run:
var matchedFacts = session.getQueryResults("GoodbyeQuery", { regex : ' /.*goodbye$/'} );
console.log(matchedFacts);

Note that multiple matches and parameters can be supplied:

query FindFriends {
parameters : { $zipcode : null, $firstName:null, $lastName:null };
when
{
p: Person:
a: Address a.zipcode == $zipcode from p.address;
first: String first ==$firstName from p.firstName;
last: String last == $lastName from p.lastName;
}
var matchedFacts = session.getQueryResults("FindFriends", { $zipcode: '88847' , $firstName:'bob' , $lastName:'yukon'} );
console.log(matchedFacts);

Don't have a pull request on this, but, have done some experimental coding locally.
To be like DROOLs you would drop the "when" all together of course, and handle the parameters
differently. We just
made it easy on ourselves my lightly tweaking the existing parsing code..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants