clipsruby 0.0.42 → 0.0.43

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +33 -0
  3. data/ext/clipsruby/clipsruby.c +128 -0
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: abe99d4312fdbfdef1029a782a1fba4300a125c4509da2d567de45beedcbd6b3
4
- data.tar.gz: e97ad52abe0327927ac725d232abb2768ba0f19664f49045400b3be9697860a2
3
+ metadata.gz: 6fc073e3a6ed11b566b2aff954ff17fcb2874fa1cf83f8b4fbeba5b893d204bc
4
+ data.tar.gz: f9c000d65fae9a2140f43bf234e8b3360937f461df35e5b2e659dac942048063
5
5
  SHA512:
6
- metadata.gz: c95269f840906a2dbb7cc334b4a96e94d11ad88371bed342ae184ffec38e3496cd0a09407f0d2f1de18e340212592df2993bbe601e3acbe943345cc17ef569d8
7
- data.tar.gz: c091dc218dd4becdcb69a8670339528ab5ab247b0c01256e6e1c796e827a65880743a3599113c55439e9c1afb63bc27705599c1ea965c82ab4baef83612d9310
6
+ metadata.gz: 522fe0e9ca9ad792684bac67b24708897f68840586c180e5e8712fa9920561b1f9316e968d22bb7cf5371f1467705b2b6e739a649cff0d7fa22f76433164e60e
7
+ data.tar.gz: 630373e7297ac2945d7a560d4db06262b482b526591e7a7d685a6305ffbd6e5f2864ad58b49eea0e8481f7806515dba5d4cd29388685b7d2429cf79a18307097
data/README.md CHANGED
@@ -401,6 +401,15 @@ CLIPS::Environment.find_defmodule(:a)
401
401
  env.find_defmodule("foo")
402
402
  ```
403
403
 
404
+ #### `CLIPS::Environment.get_activation_list` / `CLIPS::Environment#get_activation_list`
405
+
406
+ Return an array of Activation objects in the current demodule.
407
+
408
+ ```ruby
409
+ CLIPS::Environment.get_activation_list
410
+ env.get_activation_list
411
+ ```
412
+
404
413
  #### `CLIPS::Environment.get_defclass_list` / `CLIPS::Environment#get_defclass_list`
405
414
 
406
415
  Return an array of Defclass names as symbols in the environment. Pass an argument of a
@@ -850,6 +859,19 @@ CLIPS::Environment::Defrule.salience(defrule)
850
859
  defrule.salience
851
860
  ```
852
861
 
862
+ #### `CLIPS::Environment::Defrule.matches` / `CLIPS::Environment::Defrule#matches`
863
+
864
+ Returns an array holding the number of pattern matches, partial matches,
865
+ and activations for a given rule. Pass a first argument of
866
+ `:verbose`, `:succinct`, or `:terse` to determine the amount of information
867
+ to print to `STDOUT` (`:verbose` by default).
868
+
869
+ ```ruby
870
+ CLIPS::Environment::Defrule.matches(defrule, :succinct)
871
+ defrule.matches(:terse)
872
+ [pattern, partial, activations] = defrule.matches
873
+ ```
874
+
853
875
  ### Defmodule Methods
854
876
 
855
877
  #### `CLIPS::Environment::Defmodule.name` / `CLIPS::Environment::Defmodule#name`
@@ -1141,6 +1163,17 @@ CLIPS::Environment::Deffacts.pp_form(deffacts)
1141
1163
  deffacts.pp_form
1142
1164
  ```
1143
1165
 
1166
+ ### Activation Methods
1167
+
1168
+ #### `CLIPS::Environment::Activation.defule_name` / `CLIPS::Environment::Activation#defule_name`
1169
+
1170
+ Returns the name of a defrule that triggered this activation.
1171
+
1172
+ ```ruby
1173
+ CLIPS::Environment::Activation.defrule_name
1174
+ activation.defrule_name
1175
+ ```
1176
+
1144
1177
  ## Running the tests
1145
1178
 
1146
1179
  Simply do `rake compile` and then `rake test` in order to run the tests.
@@ -103,6 +103,18 @@ static const rb_data_type_t Instance_type = {
103
103
  .flags = RUBY_TYPED_FREE_IMMEDIATELY
104
104
  };
105
105
 
106
+ size_t activation_size(const void *data)
107
+ {
108
+ return sizeof(Activation);
109
+ }
110
+
111
+ static const rb_data_type_t Activation_type = {
112
+ .function = {
113
+ .dsize = activation_size
114
+ },
115
+ .flags = RUBY_TYPED_FREE_IMMEDIATELY
116
+ };
117
+
106
118
  static VALUE clips_environment_fact_deftemplate(VALUE self)
107
119
  {
108
120
  VALUE rbDeftemplate, rbEnvironment;
@@ -276,6 +288,11 @@ VALUE instance_alloc(VALUE self)
276
288
  return TypedData_Wrap_Struct(self, &Instance_type, NULL);
277
289
  }
278
290
 
291
+ VALUE activation_alloc(VALUE self)
292
+ {
293
+ return TypedData_Wrap_Struct(self, &Activation_type, NULL);
294
+ }
295
+
279
296
  VALUE environment_alloc(VALUE self)
280
297
  {
281
298
  return TypedData_Wrap_Struct(self, &Environment_type, CreateEnvironment());
@@ -1633,6 +1650,63 @@ static VALUE clips_environment_defclass_static_slots(int argc, VALUE *argv, VALU
1633
1650
  return out;
1634
1651
  }
1635
1652
 
1653
+ static VALUE clips_environment_defrule_matches(int argc, VALUE *argv, VALUE rbDefrule)
1654
+ {
1655
+ VALUE verbosity, rbEnvironment, out;
1656
+ Defrule *defrule;
1657
+ CLIPSValue value;
1658
+
1659
+ rb_scan_args(argc, argv, "01", &verbosity);
1660
+
1661
+ TypedData_Get_Struct(rbDefrule, Defrule, &Defrule_type, defrule);
1662
+
1663
+ rbEnvironment = rb_iv_get(rbDefrule, "@environment");
1664
+
1665
+ if (NIL_P(verbosity) || verbosity == ID2SYM(rb_intern("verbose"))) {
1666
+ Matches(defrule, VERBOSE, &value);
1667
+ } else if (verbosity == ID2SYM(rb_intern("succinct"))) {
1668
+ Matches(defrule, SUCCINCT, &value);
1669
+ } else if (verbosity == ID2SYM(rb_intern("terse"))) {
1670
+ Matches(defrule, TERSE, &value);
1671
+ } else {
1672
+ rb_warn("could not find matches for defrule: unsupported verbosity.");
1673
+ return Qnil;
1674
+ }
1675
+
1676
+ CLIPSValue_to_VALUE(&value, &out, &rbEnvironment);
1677
+
1678
+ return out;
1679
+ }
1680
+
1681
+
1682
+ static VALUE clips_environment_defrule_static_matches(int argc, VALUE *argv, VALUE klass)
1683
+ {
1684
+ VALUE rbDefrule, verbosity, rbEnvironment, out;
1685
+ Defrule *defrule;
1686
+ CLIPSValue value;
1687
+
1688
+ rb_scan_args(argc, argv, "11", &rbDefrule, &verbosity);
1689
+
1690
+ TypedData_Get_Struct(rbDefrule, Defrule, &Defrule_type, defrule);
1691
+
1692
+ rbEnvironment = rb_iv_get(rbDefrule, "@environment");
1693
+
1694
+ if (verbosity == ID2SYM(rb_intern("verbose"))) {
1695
+ Matches(defrule, VERBOSE, &value);
1696
+ } else if (verbosity == ID2SYM(rb_intern("succinct"))) {
1697
+ Matches(defrule, SUCCINCT, &value);
1698
+ } else if (verbosity == ID2SYM(rb_intern("terse"))) {
1699
+ Matches(defrule, TERSE, &value);
1700
+ } else {
1701
+ rb_warn("could not find matches for defrule: unsupported verbosity.");
1702
+ return Qnil;
1703
+ }
1704
+
1705
+ CLIPSValue_to_VALUE(&value, &out, &rbEnvironment);
1706
+
1707
+ return out;
1708
+ }
1709
+
1636
1710
  static VALUE clips_environment_run(int argc, VALUE *argv, VALUE environment) {
1637
1711
  VALUE integer;
1638
1712
  Environment *env;
@@ -3748,6 +3822,36 @@ static VALUE clips_environment_static_get_defmodule_list(VALUE self, VALUE rbEnv
3748
3822
  return clips_environment_get_defmodule_list(rbEnvironment);
3749
3823
  }
3750
3824
 
3825
+ static VALUE clips_environment_get_activation_list(VALUE self)
3826
+ {
3827
+ Activation *theActivation;
3828
+ Environment *env;
3829
+ VALUE rbActivation, returnArray;
3830
+
3831
+ returnArray = rb_ary_new2(0);
3832
+
3833
+ TypedData_Get_Struct(self, Environment, &Environment_type, env);
3834
+
3835
+ for (
3836
+ theActivation = GetNextActivation(env,NULL);
3837
+ theActivation != NULL;
3838
+ theActivation = GetNextActivation(env,theActivation)
3839
+ ) {
3840
+ rbActivation =
3841
+ TypedData_Wrap_Struct(rb_const_get(CLASS_OF(self), rb_intern("Activation")), &Activation_type, theActivation);
3842
+
3843
+ rb_iv_set(rbActivation, "@environment", self);
3844
+ rb_ary_push(returnArray, rbActivation);
3845
+ }
3846
+
3847
+ return returnArray;
3848
+ }
3849
+
3850
+ static VALUE clips_environment_static_get_activation_list(VALUE self, VALUE rbEnvironment)
3851
+ {
3852
+ return clips_environment_get_activation_list(rbEnvironment);
3853
+ }
3854
+
3751
3855
  static VALUE clips_environment_defrule_name(VALUE self)
3752
3856
  {
3753
3857
  Defrule *defrule;
@@ -4672,6 +4776,21 @@ static VALUE clips_environment_static_get_watch_state(VALUE self, VALUE rbEnviro
4672
4776
  return clips_environment_get_watch_state(rbEnvironment, item);
4673
4777
  }
4674
4778
 
4779
+ static VALUE clips_environment_activation_defrule_name(VALUE self)
4780
+ {
4781
+ Activation *activation;
4782
+
4783
+ TypedData_Get_Struct(self, Activation, &Activation_type, activation);
4784
+
4785
+ return ID2SYM(rb_intern(ActivationRuleName(activation)));
4786
+ }
4787
+
4788
+ static VALUE clips_environment_activation_static_defrule_name(VALUE self, VALUE rbActivation)
4789
+ {
4790
+ return clips_environment_activation_defrule_name(rbActivation);
4791
+ }
4792
+
4793
+
4675
4794
  void Init_clipsruby(void)
4676
4795
  {
4677
4796
  VALUE rbCLIPS = rb_define_module("CLIPS");
@@ -4753,6 +4872,8 @@ void Init_clipsruby(void)
4753
4872
  rb_define_method(rbEnvironment, "get_defrule_list", clips_environment_get_defrule_list, -1);
4754
4873
  rb_define_singleton_method(rbEnvironment, "get_defmodule_list", clips_environment_static_get_defmodule_list, 1);
4755
4874
  rb_define_method(rbEnvironment, "get_defmodule_list", clips_environment_get_defmodule_list, 0);
4875
+ rb_define_singleton_method(rbEnvironment, "get_activation_list", clips_environment_static_get_activation_list, 1);
4876
+ rb_define_method(rbEnvironment, "get_activation_list", clips_environment_get_activation_list, 0);
4756
4877
  rb_define_singleton_method(rbEnvironment, "find_deffacts", clips_environment_static_find_deffacts, 2);
4757
4878
  rb_define_method(rbEnvironment, "find_deffacts", clips_environment_find_deffacts, 1);
4758
4879
  rb_define_singleton_method(rbEnvironment, "watch", clips_environment_static_watch, 2);
@@ -4930,6 +5051,8 @@ void Init_clipsruby(void)
4930
5051
  rb_define_method(rbDefrule, "defmodule_name", clips_environment_defrule_defmodule_name, 0);
4931
5052
  rb_define_singleton_method(rbDefrule, "defmodule", clips_environment_defrule_static_defmodule, 1);
4932
5053
  rb_define_method(rbDefrule, "defmodule", clips_environment_defrule_defmodule, 0);
5054
+ rb_define_singleton_method(rbDefrule, "matches", clips_environment_defrule_static_matches, -1);
5055
+ rb_define_method(rbDefrule, "matches", clips_environment_defrule_matches, -1);
4933
5056
 
4934
5057
  VALUE rbDefclass = rb_define_class_under(rbEnvironment, "Defclass", rb_cObject);
4935
5058
  rb_define_alloc_func(rbDefclass, defclass_alloc);
@@ -4964,4 +5087,9 @@ void Init_clipsruby(void)
4964
5087
  rb_define_method(rbInstance, "pp_form", clips_environment_instance_pp_form, 0);
4965
5088
  rb_define_singleton_method(rbInstance, "to_h", clips_environment_instance_static_to_h, -1);
4966
5089
  rb_define_method(rbInstance, "to_h", clips_environment_instance_to_h, -1);
5090
+
5091
+ VALUE rbActivation = rb_define_class_under(rbEnvironment, "Activation", rb_cObject);
5092
+ rb_define_alloc_func(rbActivation, activation_alloc);
5093
+ rb_define_singleton_method(rbActivation, "defrule_name", clips_environment_activation_static_defrule_name, 1);
5094
+ rb_define_method(rbActivation, "defrule_name", clips_environment_activation_defrule_name, 0);
4967
5095
  }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clipsruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.42
4
+ version: 0.0.43
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Johnston
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-10-08 00:00:00.000000000 Z
11
+ date: 2024-10-13 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Calling the CLIPS programming language from within Ruby
14
14
  email: mrryanjohnston@gmail.com