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

How to query for list of facts in the session? #52

Closed
devijvers opened this issue Aug 22, 2013 · 4 comments
Closed

How to query for list of facts in the session? #52

devijvers opened this issue Aug 22, 2013 · 4 comments
Assignees

Comments

@devijvers
Copy link

I have a rule that polls an external system at a fixed interval. This call returns a JSON array with objects that are converted to facts.

I want to assert some of these facts (these are new), I want to modify certain other facts (these are existing facts) and I want to retract other facts.

However, I can't seem to add the existing facts to the when { } clause, at least I think I can't. My facts use the Thing type. Is it possible to get an array of all Thing facts from the when { } clause?

@doug-martin
Copy link
Contributor

I dont think I understand, can you provide a code sample.

@ghost ghost assigned doug-martin Aug 22, 2013
@devijvers
Copy link
Author

define Thing {
  constructor: function() {}
}

rule "some rule" {
  when {
    $e: SomeClass;
  }
  then {
    // here I want to retract all the Thing facts.
    // how do I get hold of all the Thing facts?
    // I also want to retract the $e fact when the work is done.
    retract($e);
  }
}

@doug-martin
Copy link
Contributor

Oh ok I understand now....right now there is not a way to aggregate facts within your constraints and there is also not a way to retrieve all facts of a certain type from a session.

However I thing aggregation would be a great feature, so I will look at adding it in the next release.

@devijvers
Copy link
Author

Logic engines can typically produce multiple valid results. Maybe a way to get more solutions?

when {
  $e: SomeClass;
  $t: Thing;
}
then {
  all($t, retract); // applies the second argument to all possible solutions that match the $t constraint
                    // while also matching the other constraints.
  retract($e);
}

doug-martin added a commit to doug-martin/nools that referenced this issue Dec 17, 2013
* Added new `getFacts` method to allow for querying of facts currently in session. noolsjs#52;
* Added indexing on comparison operators (i.e. `>, <, >=, <=`).
* Updated documentation.
   * Added new section about retrieving facts from a session.
   * Created new section for async actions to address noolsjs#94
@doug-martin doug-martin mentioned this issue Dec 17, 2013
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