clipsruby 0.0.9 → 0.0.10

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 +64 -0
  3. data/ext/clipsruby/clipsruby.c +137 -0
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ede586e45827a7552e087b61a6f454a0d5c0c779e9d94b34deb2b13d1c7b5846
4
- data.tar.gz: d46fdf1c8b9efd85600c976d414d4919ad8cd3c27171d15685f5dc059dd7c1e3
3
+ metadata.gz: 4e97c3ac1ef91f6eace7ed6f45290fd832c3bf5cf862f0da15bf0c4efd59d3b7
4
+ data.tar.gz: f33b1fd96f3e2c505e47e23cea1a3244bb50f345382f44ad52f88ef409008c77
5
5
  SHA512:
6
- metadata.gz: 7a4ee2975ebcb75e69f6dd5efd2a3c4c3d9b1c31fdd27a1e3fcbc918342d894bcae35cacdfbfd7c3ecdd3535474ccefe456dcc7ff7fb571b7254c4baf78812e1
7
- data.tar.gz: 689887738a961e056658085ef49b1aa52de1679a630db22f6ca8e5b57bd562a65e87574f4b1f5dd96a4caf957aad22311f434356d7a5ea59272674a790bd5d58
6
+ metadata.gz: a933862a2f9d59f2efcbdeb3c67c7fb9d0f1b87467a56ed8e8a38d91954a79acbbde5a997b111161444128a891f25d272c6941bf65e688415875147748b427a3
7
+ data.tar.gz: 17cc9ec2838a396877c30da3201bdf4c9641d13a918555bc2e46f0ec6531983802377a079d529f063ee27ae4d9ef27e47ae734e82eecbdfcf27e6c4cf93b85d1
data/README.md CHANGED
@@ -28,6 +28,17 @@ env = CLIPS.create_environment
28
28
  env2 = CLIPS::Environment.new
29
29
  ```
30
30
 
31
+ ### `CLIPS::Environment.batch_star`
32
+ ### `env.batch_star`
33
+
34
+ Pass the path to a file that will be "batched" into the environment,
35
+ allowing many CLIPS commands to be entered at once.
36
+
37
+ ```ruby
38
+ CLIPS::Environment.batch_star(env, "./my-batch.bat")
39
+ env.batch_star("./my-batch.bat")
40
+ ```
41
+
31
42
  ### `CLIPS::Environment.assert_string`
32
43
  ### `CLIPS::Environment#assert_string`
33
44
 
@@ -114,6 +125,28 @@ env.run(1)
114
125
  env.run
115
126
  ```
116
127
 
128
+ ### `CLIPS::Environment.clear`
129
+ ### `CLIPS::Environment#clear`
130
+
131
+ Removes constructs and data from the environment.
132
+
133
+ ```ruby
134
+ CLIPS::Environment.clear(env)
135
+ env.clear
136
+ ```
137
+
138
+ ### `CLIPS::Environment.reset`
139
+ ### `CLIPS::Environment#reset`
140
+
141
+ Removes all facts and instances.
142
+ Creates facts and instances defined in deffacts and definstances constructs.
143
+ Resets the values of global variables in the specified environment.
144
+
145
+ ```ruby
146
+ CLIPS::Environment.reset(env)
147
+ env.reset
148
+ ```
149
+
117
150
  ### `CLIPS::Environment.facts`
118
151
  ### `CLIPS::Environment#facts`
119
152
 
@@ -144,6 +177,37 @@ CLIPS::Environment::Fact.deftemplate_name(fact)
144
177
  fact.deftemplate_name
145
178
  ```
146
179
 
180
+ ### `CLIPS::Environment::Fact.slot_names`
181
+ ### `CLIPS::Environment::Fact#slot_names`
182
+
183
+ Returns an array representing the slot names of a fact
184
+
185
+ ```ruby
186
+ CLIPS::Environment::Fact.slot_names(fact)
187
+ fact.slot_names
188
+ ```
189
+
190
+ ### `CLIPS::Environment::Fact.get_slot`
191
+ ### `CLIPS::Environment::Fact#get_slot`
192
+
193
+ Gets the value stored in the specified slot of a fact.
194
+ Can either pass a string or symbol for the slot name argument.
195
+
196
+ ```ruby
197
+ CLIPS::Environment::Fact.get_slot(fact, 'bar')
198
+ fact.get_slot(:foo)
199
+ ```
200
+
201
+ ### `CLIPS::Environment::Fact.retract`
202
+ ### `CLIPS::Environment::Fact#retract`
203
+
204
+ Retracts a fact from the environment.
205
+
206
+ ```ruby
207
+ CLIPS::Environment::Fact.retract(fact)
208
+ fact.retract
209
+ ```
210
+
147
211
  ## Running the tests
148
212
 
149
213
  Simply do `rake compile` and then `rake test` in order to run the tests.
@@ -290,6 +290,17 @@ static VALUE clips_environment_assert_hash(VALUE self, VALUE deftemplate_name, V
290
290
  TypedData_Get_Struct(self, Environment, &Environment_type, env);
291
291
 
292
292
  FactBuilder *fb = CreateFactBuilder(env, cdeftemplate_name);
293
+ switch (FBError(env))
294
+ {
295
+ case FBE_NO_ERROR:
296
+ break;
297
+ case FBE_DEFTEMPLATE_NOT_FOUND_ERROR:
298
+ rb_warn("Could not assert fact; deftemplate not found!");
299
+ return Qnil;
300
+ case FBE_IMPLIED_DEFTEMPLATE_ERROR:
301
+ rb_warn("Could not assert fact; cannot use assert_hash to create non-deftemplated facts!");
302
+ return Qnil;
303
+ }
293
304
  void *args[2] = { (void *)fb, (void *)env };
294
305
  rb_hash_foreach(hash, _clips_environment_assert_hash, (VALUE)args);
295
306
  Fact *fact = FBAssert(fb);
@@ -702,6 +713,122 @@ static VALUE clips_environment_static_batch_star(VALUE self, VALUE rbEnvironment
702
713
  return clips_environment_batch_star(rbEnvironment, path);
703
714
  }
704
715
 
716
+ static VALUE clips_environment_clear(VALUE self)
717
+ {
718
+ Environment *env;
719
+
720
+ TypedData_Get_Struct(self, Environment, &Environment_type, env);
721
+
722
+ if (Clear(env)) {
723
+ return Qtrue;
724
+ } else {
725
+ return Qfalse;
726
+ }
727
+ }
728
+
729
+ static VALUE clips_environment_static_clear(VALUE self, VALUE rbEnvironment)
730
+ {
731
+ return clips_environment_clear(rbEnvironment);
732
+ }
733
+
734
+ static VALUE clips_environment_reset(VALUE self)
735
+ {
736
+ Environment *env;
737
+
738
+ TypedData_Get_Struct(self, Environment, &Environment_type, env);
739
+
740
+ Reset(env);
741
+
742
+ return Qnil;
743
+ }
744
+
745
+ static VALUE clips_environment_static_reset(VALUE self, VALUE rbEnvironment)
746
+ {
747
+ return clips_environment_reset(rbEnvironment);
748
+ }
749
+
750
+ static VALUE clips_environment_fact_slot_names(VALUE self)
751
+ {
752
+ Fact *fact;
753
+ CLIPSValue slot_names;
754
+ VALUE rbEnvironment = rb_iv_get(self, "@environment");
755
+
756
+ TypedData_Get_Struct(self, Fact, &Fact_type, fact);
757
+
758
+ FactSlotNames(fact, &slot_names);
759
+
760
+ VALUE array;
761
+
762
+ CLIPSValue_to_VALUE(&slot_names, &array, &rbEnvironment);
763
+
764
+ return array;
765
+ }
766
+
767
+ static VALUE clips_environment_fact_static_slot_names(VALUE self, VALUE rbFact)
768
+ {
769
+ return clips_environment_fact_slot_names(rbFact);
770
+ }
771
+
772
+ static VALUE clips_environment_fact_get_slot(VALUE self, VALUE slot_name)
773
+ {
774
+ Fact *fact;
775
+ CLIPSValue slot_value;
776
+ VALUE rbEnvironment = rb_iv_get(self, "@environment");
777
+
778
+ TypedData_Get_Struct(self, Fact, &Fact_type, fact);
779
+
780
+ switch (TYPE(slot_name)) {
781
+ case T_STRING:
782
+ GetFactSlot(fact, StringValueCStr(slot_name), &slot_value);
783
+ break;
784
+ case T_SYMBOL:
785
+ GetFactSlot(fact, rb_id2name(SYM2ID(slot_name)), &slot_value);
786
+ break;
787
+ default:
788
+ rb_warn("slot name must be string or symbol in call to get_slot!");
789
+ return Qnil;
790
+ }
791
+
792
+ VALUE out;
793
+
794
+ CLIPSValue_to_VALUE(&slot_value, &out, &rbEnvironment);
795
+
796
+ return out;
797
+ }
798
+
799
+ static VALUE clips_environment_fact_static_get_slot(VALUE self, VALUE rbFact, VALUE slot_name)
800
+ {
801
+ return clips_environment_fact_get_slot(rbFact, slot_name);
802
+ }
803
+
804
+ static VALUE clips_environment_fact_retract(VALUE self)
805
+ {
806
+ Fact *fact;
807
+
808
+ TypedData_Get_Struct(self, Fact, &Fact_type, fact);
809
+
810
+ switch (Retract(fact)) {
811
+ case RE_NO_ERROR:
812
+ break;
813
+ case RE_NULL_POINTER_ERROR:
814
+ rb_warn("could not retract fact; null pointer error. This could be a bug in clipsruby!");
815
+ return Qfalse;
816
+ case RE_COULD_NOT_RETRACT_ERROR:
817
+ rb_warn("could not retract fact! is pattern matching currently happening with this fact?");
818
+ return Qfalse;
819
+ case RE_RULE_NETWORK_ERROR:
820
+ rb_warn("could not retract fact! An error occurs while the retraction was being processed in the rule network");
821
+ return Qfalse;
822
+ }
823
+
824
+ return Qtrue;
825
+ }
826
+
827
+ static VALUE clips_environment_fact_static_retract(VALUE self, VALUE rbFact)
828
+ {
829
+ return clips_environment_fact_retract(rbFact);
830
+ }
831
+
705
832
  void Init_clipsruby(void)
706
833
  {
707
834
  VALUE rbCLIPS = rb_define_module("CLIPS");
@@ -727,12 +854,22 @@ void Init_clipsruby(void)
727
854
  rb_define_method(rbEnvironment, "find_all_facts", clips_environment_find_all_facts, -1);
728
855
  rb_define_singleton_method(rbEnvironment, "batch_star", clips_environment_static_batch_star, 2);
729
856
  rb_define_method(rbEnvironment, "batch_star", clips_environment_batch_star, 1);
857
+ rb_define_singleton_method(rbEnvironment, "clear", clips_environment_static_clear, 1);
858
+ rb_define_method(rbEnvironment, "clear", clips_environment_clear, 0);
859
+ rb_define_singleton_method(rbEnvironment, "reset", clips_environment_static_reset, 1);
860
+ rb_define_method(rbEnvironment, "reset", clips_environment_reset, 0);
730
861
 
731
862
  VALUE rbFact = rb_define_class_under(rbEnvironment, "Fact", rb_cObject);
732
863
  rb_define_singleton_method(rbFact, "deftemplate_name", clips_environment_fact_static_deftemplate_name, 1);
733
864
  rb_define_method(rbFact, "deftemplate_name", clips_environment_fact_deftemplate_name, 0);
734
865
  rb_define_singleton_method(rbFact, "to_h", clips_environment_fact_static_to_h, 1);
735
866
  rb_define_method(rbFact, "to_h", clips_environment_fact_to_h, 0);
867
+ rb_define_singleton_method(rbFact, "slot_names", clips_environment_fact_static_slot_names, 1);
868
+ rb_define_method(rbFact, "slot_names", clips_environment_fact_slot_names, 0);
869
+ rb_define_singleton_method(rbFact, "get_slot", clips_environment_fact_static_get_slot, 2);
870
+ rb_define_method(rbFact, "get_slot", clips_environment_fact_get_slot, 1);
871
+ rb_define_singleton_method(rbFact, "retract", clips_environment_fact_static_retract, 1);
872
+ rb_define_method(rbFact, "retract", clips_environment_fact_retract, 0);
736
873
 
737
874
  VALUE rbInstance = rb_define_class_under(rbEnvironment, "Instance", rb_cObject);
738
875
  }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clipsruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Johnston