clipsruby 0.0.8 → 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.
- checksums.yaml +4 -4
- data/README.md +79 -0
- data/ext/clipsruby/clipsruby.c +158 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e97c3ac1ef91f6eace7ed6f45290fd832c3bf5cf862f0da15bf0c4efd59d3b7
|
4
|
+
data.tar.gz: f33b1fd96f3e2c505e47e23cea1a3244bb50f345382f44ad52f88ef409008c77
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a933862a2f9d59f2efcbdeb3c67c7fb9d0f1b87467a56ed8e8a38d91954a79acbbde5a997b111161444128a891f25d272c6941bf65e688415875147748b427a3
|
7
|
+
data.tar.gz: 17cc9ec2838a396877c30da3201bdf4c9641d13a918555bc2e46f0ec6531983802377a079d529f063ee27ae4d9ef27e47ae734e82eecbdfcf27e6c4cf93b85d1
|
data/README.md
CHANGED
@@ -4,6 +4,17 @@
|
|
4
4
|
|
5
5
|
Use the CLIPS programming language from within Ruby
|
6
6
|
|
7
|
+
## Installation/Usage
|
8
|
+
|
9
|
+
This is available as a Ruby gem:
|
10
|
+
|
11
|
+
```
|
12
|
+
gem install clipsruby
|
13
|
+
```
|
14
|
+
|
15
|
+
From there, you should be able to `require "clipsruby"` in your code
|
16
|
+
and use the below API as described.
|
17
|
+
|
7
18
|
## API
|
8
19
|
|
9
20
|
### `CLIPS.create_environment`
|
@@ -17,6 +28,17 @@ env = CLIPS.create_environment
|
|
17
28
|
env2 = CLIPS::Environment.new
|
18
29
|
```
|
19
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
|
+
|
20
42
|
### `CLIPS::Environment.assert_string`
|
21
43
|
### `CLIPS::Environment#assert_string`
|
22
44
|
|
@@ -103,6 +125,28 @@ env.run(1)
|
|
103
125
|
env.run
|
104
126
|
```
|
105
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
|
+
|
106
150
|
### `CLIPS::Environment.facts`
|
107
151
|
### `CLIPS::Environment#facts`
|
108
152
|
|
@@ -132,3 +176,38 @@ Returns the name of the Deftemplate for a fact as a symbol
|
|
132
176
|
CLIPS::Environment::Fact.deftemplate_name(fact)
|
133
177
|
fact.deftemplate_name
|
134
178
|
```
|
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
|
+
|
211
|
+
## Running the tests
|
212
|
+
|
213
|
+
Simply do `rake compile` and then `rake test` in order to run the tests.
|
data/ext/clipsruby/clipsruby.c
CHANGED
@@ -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);
|
@@ -673,7 +684,7 @@ static VALUE clips_environment_fact_to_h(VALUE self)
|
|
673
684
|
VALUE innerValue;
|
674
685
|
GetFactSlot(fact, key.multifieldValue->contents[i].lexemeValue->contents, &value);
|
675
686
|
CLIPSValue_to_VALUE(&value, &innerValue, &rbEnvironment);
|
676
|
-
rb_hash_aset(hash,
|
687
|
+
rb_hash_aset(hash, ID2SYM(rb_intern(key.multifieldValue->contents[i].lexemeValue->contents)), innerValue);
|
677
688
|
}
|
678
689
|
|
679
690
|
return hash;
|
@@ -684,6 +695,140 @@ static VALUE clips_environment_fact_static_to_h(VALUE self, VALUE rbFact)
|
|
684
695
|
return clips_environment_fact_to_h(rbFact);
|
685
696
|
}
|
686
697
|
|
698
|
+
static VALUE clips_environment_batch_star(VALUE self, VALUE path)
|
699
|
+
{
|
700
|
+
Environment *env;
|
701
|
+
|
702
|
+
TypedData_Get_Struct(self, Environment, &Environment_type, env);
|
703
|
+
|
704
|
+
if (BatchStar(env, StringValueCStr(path))) {
|
705
|
+
return Qtrue;
|
706
|
+
} else {
|
707
|
+
return Qfalse;
|
708
|
+
}
|
709
|
+
}
|
710
|
+
|
711
|
+
static VALUE clips_environment_static_batch_star(VALUE self, VALUE rbEnvironment, VALUE path)
|
712
|
+
{
|
713
|
+
return clips_environment_batch_star(rbEnvironment, path);
|
714
|
+
}
|
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
|
+
|
687
832
|
void Init_clipsruby(void)
|
688
833
|
{
|
689
834
|
VALUE rbCLIPS = rb_define_module("CLIPS");
|
@@ -707,12 +852,24 @@ void Init_clipsruby(void)
|
|
707
852
|
rb_define_method(rbEnvironment, "_eval", clips_environment_eval, 1);
|
708
853
|
rb_define_singleton_method(rbEnvironment, "find_all_facts", clips_environment_static_find_all_facts, -1);
|
709
854
|
rb_define_method(rbEnvironment, "find_all_facts", clips_environment_find_all_facts, -1);
|
855
|
+
rb_define_singleton_method(rbEnvironment, "batch_star", clips_environment_static_batch_star, 2);
|
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);
|
710
861
|
|
711
862
|
VALUE rbFact = rb_define_class_under(rbEnvironment, "Fact", rb_cObject);
|
712
863
|
rb_define_singleton_method(rbFact, "deftemplate_name", clips_environment_fact_static_deftemplate_name, 1);
|
713
864
|
rb_define_method(rbFact, "deftemplate_name", clips_environment_fact_deftemplate_name, 0);
|
714
865
|
rb_define_singleton_method(rbFact, "to_h", clips_environment_fact_static_to_h, 1);
|
715
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);
|
716
873
|
|
717
874
|
VALUE rbInstance = rb_define_class_under(rbEnvironment, "Instance", rb_cObject);
|
718
875
|
}
|
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.
|
4
|
+
version: 0.0.10
|
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-09-
|
11
|
+
date: 2024-09-06 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
|