clipsruby 0.0.12 → 0.0.14
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 -8
- data/ext/clipsruby/clipsruby.c +153 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f33a751deeebf96aa16135763365063f9facdd95c2cd7e7df7de0e3e90bea56b
|
4
|
+
data.tar.gz: f24d9c9901986b83ce38ffd97d5ef9f06c2409ae3b24de85094a73b78f39dbc4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d8d10e392c06bb956d2c889e3090afce100ae4b9ef27a2a8463da231d5d00c645890b82376656bc7f17cdc33f248d49f8dd274ac341a7e60fdaf76d8a3d8496
|
7
|
+
data.tar.gz: caf7c237fb87e4e04d842593fb7cb23d7d65b4494a373cd59fb5fc775a48dbe6c71a7cd86fbfa2d2efc93b338994079f26b9f406f47390cdad52d352476e1846
|
data/README.md
CHANGED
@@ -39,6 +39,54 @@ CLIPS::Environment.batch_star(env, "./my-batch.bat")
|
|
39
39
|
env.batch_star("./my-batch.bat")
|
40
40
|
```
|
41
41
|
|
42
|
+
### `CLIPS::Environment.save`
|
43
|
+
### `env.save`
|
44
|
+
|
45
|
+
Pass the path in which we'll save the environment constructs.
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
CLIPS::Environment.save(env, "./my-save.bin")
|
49
|
+
env.save("./my-save.bin")
|
50
|
+
```
|
51
|
+
|
52
|
+
### `CLIPS::Environment.load`
|
53
|
+
### `env.load`
|
54
|
+
|
55
|
+
Pass the path to a file that will load the constructs stored in the file
|
56
|
+
into the environment. Remember to `reset` the environment if you need.
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
CLIPS::Environment.load(env, "./my-load.bin")
|
60
|
+
env.load("./my-load.bin")
|
61
|
+
```
|
62
|
+
|
63
|
+
### `CLIPS::Environment.save_facts`
|
64
|
+
### `env.save_facts`
|
65
|
+
|
66
|
+
Pass the path in which we'll save the environment facts.
|
67
|
+
The third argument is optional, and determines whether to store the visible or local facts.
|
68
|
+
By default, it'll store local.
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
CLIPS::Environment.save_facts(env, "./my-save-facts.bin")
|
72
|
+
env.save_facts("./my-save-facts.bin")
|
73
|
+
CLIPS::Environment.save_facts(env, "./my-save-facts.bin", :local)
|
74
|
+
env.save_facts("./my-save-facts.bin", :local)
|
75
|
+
CLIPS::Environment.save_facts(env, "./my-save-facts.bin", :visible)
|
76
|
+
env.save_facts("./my-save-facts.bin", :visible)
|
77
|
+
```
|
78
|
+
|
79
|
+
### `CLIPS::Environment.load_facts`
|
80
|
+
### `env.load_facts`
|
81
|
+
|
82
|
+
Pass the path to a file that will load the facts stored in the file
|
83
|
+
into the environment.
|
84
|
+
|
85
|
+
```ruby
|
86
|
+
CLIPS::Environment.load_facts(env, "./my-load-facts.bin")
|
87
|
+
env.load_facts("./my-load-facts.bin")
|
88
|
+
```
|
89
|
+
|
42
90
|
### `CLIPS::Environment.bsave`
|
43
91
|
### `env.bsave`
|
44
92
|
|
@@ -68,12 +116,12 @@ The third argument is optional, and determines whether to store the visible or l
|
|
68
116
|
By default, it'll store local.
|
69
117
|
|
70
118
|
```ruby
|
71
|
-
CLIPS::Environment.
|
72
|
-
env.
|
73
|
-
CLIPS::Environment.
|
74
|
-
env.
|
75
|
-
CLIPS::Environment.
|
76
|
-
env.
|
119
|
+
CLIPS::Environment.bsave_facts(env, "./my-bsave-facts.bin")
|
120
|
+
env.bsave_facts("./my-bsave-facts.bin")
|
121
|
+
CLIPS::Environment.bsave_facts(env, "./my-bsave-facts.bin", :local)
|
122
|
+
env.bsave_facts("./my-bsave-facts.bin", :local)
|
123
|
+
CLIPS::Environment.bsave_facts(env, "./my-bsave-facts.bin", :visible)
|
124
|
+
env.bsave_facts("./my-bsave-facts.bin", :visible)
|
77
125
|
```
|
78
126
|
|
79
127
|
### `CLIPS::Environment.bload_facts`
|
@@ -83,8 +131,8 @@ Pass the path to a binary file that will load the facts stored in the file
|
|
83
131
|
into the environment.
|
84
132
|
|
85
133
|
```ruby
|
86
|
-
CLIPS::Environment.
|
87
|
-
env.
|
134
|
+
CLIPS::Environment.bload_facts(env, "./my-bload-facts.bin")
|
135
|
+
env.bload_facts("./my-bload-facts.bin")
|
88
136
|
```
|
89
137
|
|
90
138
|
### `CLIPS::Environment.assert_string`
|
@@ -107,6 +155,19 @@ fact = CLIPS::Environment.assert_hash(env, :my_deftemplate, a: 1, b: "asdf", c:
|
|
107
155
|
fact2 = env.assert_hash(:my_deftemplate, d: 4.5, e: :asdf)
|
108
156
|
```
|
109
157
|
|
158
|
+
### `CLIPS::Environment.find_fact`
|
159
|
+
### `CLIPS::Environment#find_fact`
|
160
|
+
|
161
|
+
A light wrapper around the CLIPS find-fact function. Accepts a fact set template and query,
|
162
|
+
returns the first Facts in the environment that match as Ruby objects.
|
163
|
+
|
164
|
+
```ruby
|
165
|
+
CLIPS::Environment.find_facts(env, "(?f my_deftemplate)")
|
166
|
+
env.find_fact("(?f my_deftemplate)")
|
167
|
+
CLIPS::Environment.find_fact(env, "(?f my_deftemplate)", "(eq ?f:b \"asdf\")")
|
168
|
+
env.find_fact("(?f my_deftemplate)", "(= ?f:a 1)")
|
169
|
+
```
|
170
|
+
|
110
171
|
### `CLIPS::Environment.find_all_facts`
|
111
172
|
### `CLIPS::Environment#find_all_facts`
|
112
173
|
|
@@ -215,6 +276,16 @@ CLIPS::Environment::Fact.to_h(fact)
|
|
215
276
|
fact.to_h
|
216
277
|
```
|
217
278
|
|
279
|
+
### `CLIPS::Environment::Fact.index`
|
280
|
+
### `CLIPS::Environment::Fact#index`
|
281
|
+
|
282
|
+
Returns the index of the fact in working memory
|
283
|
+
|
284
|
+
```ruby
|
285
|
+
CLIPS::Environment::Fact.index(fact)
|
286
|
+
fact.index
|
287
|
+
```
|
288
|
+
|
218
289
|
### `CLIPS::Environment::Fact.deftemplate_name`
|
219
290
|
### `CLIPS::Environment::Fact#deftemplate_name`
|
220
291
|
|
data/ext/clipsruby/clipsruby.c
CHANGED
@@ -642,6 +642,32 @@ static VALUE clips_environment_static_eval(VALUE self, VALUE rbEnvironment, VALU
|
|
642
642
|
return clips_environment_eval(rbEnvironment, string);
|
643
643
|
}
|
644
644
|
|
645
|
+
static VALUE clips_environment_find_fact(int argc, VALUE *argv, VALUE environment) {
|
646
|
+
VALUE fact_set_template, query;
|
647
|
+
|
648
|
+
rb_scan_args(argc, argv, "11", &fact_set_template, &query);
|
649
|
+
if (NIL_P(query)) {
|
650
|
+
query = rb_str_new_cstr("TRUE");
|
651
|
+
}
|
652
|
+
|
653
|
+
return clips_environment_eval(
|
654
|
+
environment,
|
655
|
+
rb_sprintf("(find-fact (%s) %s)", StringValueCStr(fact_set_template), StringValueCStr(query)));
|
656
|
+
}
|
657
|
+
|
658
|
+
static VALUE clips_environment_static_find_fact(int argc, VALUE *argv, VALUE klass) {
|
659
|
+
VALUE rbEnvironment, fact_set_template, query;
|
660
|
+
|
661
|
+
rb_scan_args(argc, argv, "21", &rbEnvironment, &fact_set_template, &query);
|
662
|
+
if (NIL_P(query)) {
|
663
|
+
query = rb_str_new_cstr("TRUE");
|
664
|
+
}
|
665
|
+
|
666
|
+
return clips_environment_eval(
|
667
|
+
rbEnvironment,
|
668
|
+
rb_sprintf("(find-fact (%s) %s)", StringValueCStr(fact_set_template), StringValueCStr(query)));
|
669
|
+
}
|
670
|
+
|
645
671
|
static VALUE clips_environment_find_all_facts(int argc, VALUE *argv, VALUE environment) {
|
646
672
|
VALUE fact_set_template, query;
|
647
673
|
|
@@ -747,6 +773,117 @@ static VALUE clips_environment_static_reset(VALUE self, VALUE rbEnvironment)
|
|
747
773
|
return clips_environment_reset(rbEnvironment);
|
748
774
|
}
|
749
775
|
|
776
|
+
static VALUE clips_environment_save(VALUE self, VALUE path)
|
777
|
+
{
|
778
|
+
Environment *env;
|
779
|
+
|
780
|
+
TypedData_Get_Struct(self, Environment, &Environment_type, env);
|
781
|
+
|
782
|
+
if (Save(env, StringValueCStr(path))) {
|
783
|
+
return Qtrue;
|
784
|
+
} else {
|
785
|
+
return Qfalse;
|
786
|
+
}
|
787
|
+
}
|
788
|
+
|
789
|
+
static VALUE clips_environment_static_save(VALUE self, VALUE rbEnvironment, VALUE path)
|
790
|
+
{
|
791
|
+
return clips_environment_save(rbEnvironment, path);
|
792
|
+
}
|
793
|
+
|
794
|
+
static VALUE clips_environment_load(VALUE self, VALUE path)
|
795
|
+
{
|
796
|
+
Environment *env;
|
797
|
+
|
798
|
+
TypedData_Get_Struct(self, Environment, &Environment_type, env);
|
799
|
+
|
800
|
+
switch (Load(env, StringValueCStr(path)))
|
801
|
+
{
|
802
|
+
case LE_NO_ERROR:
|
803
|
+
break;
|
804
|
+
case LE_OPEN_FILE_ERROR:
|
805
|
+
rb_warn("could not load: issue opening file.");
|
806
|
+
return Qnil;
|
807
|
+
case LE_PARSING_ERROR:
|
808
|
+
rb_warn("could not load: parsing issue.");
|
809
|
+
return Qnil;
|
810
|
+
}
|
811
|
+
return Qtrue;
|
812
|
+
}
|
813
|
+
|
814
|
+
static VALUE clips_environment_static_load(VALUE self, VALUE rbEnvironment, VALUE path)
|
815
|
+
{
|
816
|
+
return clips_environment_load(rbEnvironment, path);
|
817
|
+
}
|
818
|
+
|
819
|
+
static VALUE clips_environment_save_facts(int argc, VALUE *argv, VALUE rbEnvironment) {
|
820
|
+
VALUE path, scope;
|
821
|
+
Environment *env;
|
822
|
+
|
823
|
+
TypedData_Get_Struct(rbEnvironment, Environment, &Environment_type, env);
|
824
|
+
|
825
|
+
rb_scan_args(argc, argv, "11", &path, &scope);
|
826
|
+
if (NIL_P(scope)) {
|
827
|
+
scope = ID2SYM(rb_intern("local"));
|
828
|
+
}
|
829
|
+
|
830
|
+
int number_of_facts_saved;
|
831
|
+
|
832
|
+
if (scope == ID2SYM(rb_intern("visible"))) {
|
833
|
+
number_of_facts_saved = SaveFacts(env, StringValueCStr(path), VISIBLE_SAVE);
|
834
|
+
} else if (scope == ID2SYM(rb_intern("local"))) {
|
835
|
+
number_of_facts_saved = SaveFacts(env, StringValueCStr(path), LOCAL_SAVE);
|
836
|
+
} else {
|
837
|
+
rb_warn("could not bsave_facts: unsupported scope.");
|
838
|
+
return Qnil;
|
839
|
+
}
|
840
|
+
return INT2NUM(number_of_facts_saved);
|
841
|
+
}
|
842
|
+
|
843
|
+
static VALUE clips_environment_static_save_facts(int argc, VALUE *argv, VALUE klass) {
|
844
|
+
VALUE rbEnvironment, path, scope;
|
845
|
+
Environment *env;
|
846
|
+
|
847
|
+
rb_scan_args(argc, argv, "21", &rbEnvironment, &path, &scope);
|
848
|
+
|
849
|
+
TypedData_Get_Struct(rbEnvironment, Environment, &Environment_type, env);
|
850
|
+
|
851
|
+
if (NIL_P(scope)) {
|
852
|
+
scope = ID2SYM(rb_intern("local"));
|
853
|
+
}
|
854
|
+
|
855
|
+
int number_of_facts_saved;
|
856
|
+
|
857
|
+
if (scope == ID2SYM(rb_intern("visible"))) {
|
858
|
+
number_of_facts_saved = SaveFacts(env, StringValueCStr(path), VISIBLE_SAVE);
|
859
|
+
} else if (scope == ID2SYM(rb_intern("local"))) {
|
860
|
+
number_of_facts_saved = SaveFacts(env, StringValueCStr(path), LOCAL_SAVE);
|
861
|
+
} else {
|
862
|
+
rb_warn("could not bsave_facts: unsupported scope.");
|
863
|
+
return Qnil;
|
864
|
+
}
|
865
|
+
return INT2NUM(number_of_facts_saved);
|
866
|
+
}
|
867
|
+
|
868
|
+
static VALUE clips_environment_load_facts(VALUE self, VALUE path)
|
869
|
+
{
|
870
|
+
Environment *env;
|
871
|
+
|
872
|
+
TypedData_Get_Struct(self, Environment, &Environment_type, env);
|
873
|
+
int number_of_facts_loaded = LoadFacts(env, StringValueCStr(path));
|
874
|
+
|
875
|
+
if (number_of_facts_loaded == -1) {
|
876
|
+
return Qnil;
|
877
|
+
} else {
|
878
|
+
return INT2NUM(number_of_facts_loaded);
|
879
|
+
}
|
880
|
+
}
|
881
|
+
|
882
|
+
static VALUE clips_environment_static_load_facts(VALUE self, VALUE rbEnvironment, VALUE path)
|
883
|
+
{
|
884
|
+
return clips_environment_load_facts(rbEnvironment, path);
|
885
|
+
}
|
886
|
+
|
750
887
|
static VALUE clips_environment_bsave(VALUE self, VALUE path)
|
751
888
|
{
|
752
889
|
Environment *env;
|
@@ -794,14 +931,18 @@ static VALUE clips_environment_bsave_facts(int argc, VALUE *argv, VALUE rbEnviro
|
|
794
931
|
scope = ID2SYM(rb_intern("local"));
|
795
932
|
}
|
796
933
|
|
934
|
+
int number_of_facts_saved;
|
935
|
+
|
797
936
|
if (scope == ID2SYM(rb_intern("visible"))) {
|
798
|
-
|
937
|
+
number_of_facts_saved = BinarySaveFacts(env, StringValueCStr(path), VISIBLE_SAVE);
|
799
938
|
} else if (scope == ID2SYM(rb_intern("local"))) {
|
800
|
-
|
939
|
+
number_of_facts_saved = BinarySaveFacts(env, StringValueCStr(path), LOCAL_SAVE);
|
801
940
|
} else {
|
802
941
|
rb_warn("could not bsave_facts: unsupported scope.");
|
803
942
|
return Qnil;
|
804
943
|
}
|
944
|
+
|
945
|
+
return INT2NUM(number_of_facts_saved);
|
805
946
|
}
|
806
947
|
|
807
948
|
static VALUE clips_environment_static_bsave_facts(int argc, VALUE *argv, VALUE klass) {
|
@@ -1048,6 +1189,8 @@ void Init_clipsruby(void)
|
|
1048
1189
|
rb_define_method(rbEnvironment, "run", clips_environment_run, -1);
|
1049
1190
|
rb_define_singleton_method(rbEnvironment, "_eval", clips_environment_static_eval, 2);
|
1050
1191
|
rb_define_method(rbEnvironment, "_eval", clips_environment_eval, 1);
|
1192
|
+
rb_define_singleton_method(rbEnvironment, "find_fact", clips_environment_static_find_fact, -1);
|
1193
|
+
rb_define_method(rbEnvironment, "find_fact", clips_environment_find_fact, -1);
|
1051
1194
|
rb_define_singleton_method(rbEnvironment, "find_all_facts", clips_environment_static_find_all_facts, -1);
|
1052
1195
|
rb_define_method(rbEnvironment, "find_all_facts", clips_environment_find_all_facts, -1);
|
1053
1196
|
rb_define_singleton_method(rbEnvironment, "batch_star", clips_environment_static_batch_star, 2);
|
@@ -1056,6 +1199,14 @@ void Init_clipsruby(void)
|
|
1056
1199
|
rb_define_method(rbEnvironment, "clear", clips_environment_clear, 0);
|
1057
1200
|
rb_define_singleton_method(rbEnvironment, "reset", clips_environment_static_reset, 1);
|
1058
1201
|
rb_define_method(rbEnvironment, "reset", clips_environment_reset, 0);
|
1202
|
+
rb_define_singleton_method(rbEnvironment, "save", clips_environment_static_save, 2);
|
1203
|
+
rb_define_method(rbEnvironment, "save", clips_environment_save, 1);
|
1204
|
+
rb_define_singleton_method(rbEnvironment, "load", clips_environment_static_load, 2);
|
1205
|
+
rb_define_method(rbEnvironment, "load", clips_environment_load, 1);
|
1206
|
+
rb_define_singleton_method(rbEnvironment, "save_facts", clips_environment_static_save_facts, -1);
|
1207
|
+
rb_define_method(rbEnvironment, "save_facts", clips_environment_save_facts, -1);
|
1208
|
+
rb_define_singleton_method(rbEnvironment, "load_facts", clips_environment_static_load_facts, 2);
|
1209
|
+
rb_define_method(rbEnvironment, "load_facts", clips_environment_load_facts, 1);
|
1059
1210
|
rb_define_singleton_method(rbEnvironment, "bsave", clips_environment_static_bsave, 2);
|
1060
1211
|
rb_define_method(rbEnvironment, "bsave", clips_environment_bsave, 1);
|
1061
1212
|
rb_define_singleton_method(rbEnvironment, "bload", clips_environment_static_bload, 2);
|