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

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

Comments

Projects
None yet
2 participants
@devijvers

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

This comment has been minimized.

Show comment
Hide comment
@doug-martin

doug-martin Aug 22, 2013

Contributor

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

Contributor

doug-martin commented Aug 22, 2013

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

@ghost ghost assigned doug-martin Aug 22, 2013

@devijvers

This comment has been minimized.

Show comment
Hide comment
@devijvers

devijvers Aug 22, 2013

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);
  }
}
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

This comment has been minimized.

Show comment
Hide comment
@doug-martin

doug-martin Aug 22, 2013

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.

Contributor

doug-martin commented Aug 22, 2013

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

This comment has been minimized.

Show comment
Hide comment
@devijvers

devijvers Aug 22, 2013

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);
}

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

v0.2.3
* Added new `getFacts` method to allow for querying of facts currently in session. #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 #94

@doug-martin doug-martin referenced this issue Dec 17, 2013

Merged

v0.2.3 #95

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