clipsruby 0.0.28 → 0.0.30

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 +49 -1
  3. data/ext/clipsruby/clipsruby.c +136 -0
  4. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c3422d24e21cf31d89d413801a5804b91bdca8cfab4adc230bcdaeb6d4da3085
4
- data.tar.gz: f34d498c8130445406058e05073abe0d48cc7c7a1c2fe5b4e2fb799bf4836f7a
3
+ metadata.gz: 4dca72773ba370d57fd7c96a94820ce857f550ca792c78958885919234c0e03b
4
+ data.tar.gz: 055b1e80563bfeb02135a9cad90fee07dac3dd85c13ba90f9771c7af388b4457
5
5
  SHA512:
6
- metadata.gz: 9b22a805380544262da7bf544c163159a5b5846a8ce2c0da2754f2bcdabaea6c8209cf6c5b8154606bb14498a38e0fac9751e51926e03cddab7f120018905291
7
- data.tar.gz: f13099a933300723e7e1062d6c4e144e286726476e942f172457cbc38c6e4957f982caf007cf0acbdb41b2a0c7713ce494712794670883a934580a4fd101b556
6
+ metadata.gz: 3f8e69b183b21759ebd410cc064901c99fb6de71f8a13e656dc133238be095e8b2d9c9bb4cb78db79efeb25cd3e68d386bac3df07a96045793f73259360fb2f1
7
+ data.tar.gz: 66930baf77b505500e1879db1c8cb83d5104c048b37a13e328331063fd4e55573f2d8ac917837b76cdea547b37a5798e4de0f704ef3a0524c91c8928c33f76ea
data/README.md CHANGED
@@ -474,6 +474,16 @@ CLIPS::Environment::Defrule.remove_break(defrule)
474
474
  defrule.remove_break
475
475
  ```
476
476
 
477
+ ### `CLIPS::Environment::Defrule.salience`
478
+ ### `CLIPS::Environment::Defrule#salience`
479
+
480
+ Returns the salience of a defrule
481
+
482
+ ```ruby
483
+ CLIPS::Environment::Defrule.salience(defrule)
484
+ defrule.salience
485
+ ```
486
+
477
487
  ### `CLIPS::Environment.find_defmodule`
478
488
  ### `CLIPS::Environment#find_defmodule`
479
489
 
@@ -540,6 +550,22 @@ CLIPS::Environment.get_deftemplate_list(defmodule)
540
550
  env.get_deftemplate_list(defmodule)
541
551
  ```
542
552
 
553
+ ### `CLIPS::Environment.get_defrule_list`
554
+ ### `CLIPS::Environment#get_defrule_list`
555
+
556
+ Return an array of Defrule names as symbols in the environment. Pass an argument of a
557
+ symbol, string, or Defmodule object in order to only get Defrules
558
+ in that Defmodule. If you do not, it will return all Defrule names in all modules.
559
+
560
+ ```ruby
561
+ CLIPS::Environment.get_defrule_list
562
+ env.get_defrule_list
563
+ CLIPS::Environment.get_defrule_list(:MAIN)
564
+ env.get_defrule_list(:MAIN)
565
+ CLIPS::Environment.get_defrule_list(defmodule)
566
+ env.get_defrule_list(defmodule)
567
+ ```
568
+
543
569
  ### `CLIPS::Environment.find_deftemplate`
544
570
  ### `CLIPS::Environment#find_deftemplate`
545
571
 
@@ -611,6 +637,18 @@ CLIPS::Environment::Deftemplate.is_deletable(deftemplate)
611
637
  deftemplate.is_deletable
612
638
  ```
613
639
 
640
+ ### `CLIPS::Environment::Deftemplate.is_implied`
641
+ ### `CLIPS::Environment::Deftemplate#is_implied`
642
+
643
+ Returns a boolean whether the Deftemplate is implied or not.
644
+ If the fact is an ordered fact, the Deftemplate is implied.
645
+ Otherwise, the Deftemplate is considered explicitly defined.
646
+
647
+ ```ruby
648
+ CLIPS::Environment::Deftemplate.is_implied(deftemplate)
649
+ deftemplate.is_implied
650
+ ```
651
+
614
652
  ### `CLIPS::Environment::Deftemplate.slot_allowed_values`
615
653
  ### `CLIPS::Environment::Deftemplate#slot_allowed_values`
616
654
 
@@ -729,13 +767,23 @@ deftemplate.slot_defaultp('bar')
729
767
  ### `CLIPS::Environment::Defmodule.get_deftemplate_list`
730
768
  ### `CLIPS::Environment::Defmodule#get_deftemplate_list`
731
769
 
732
- Return an array of Deftemplate names as symboles in the Defmodule
770
+ Return an array of Deftemplate names as symbols in the Defmodule
733
771
 
734
772
  ```ruby
735
773
  CLIPS::Environment::Defmodule.get_deftemplate_list(defmodule)
736
774
  defmodule.get_deftemplate_list
737
775
  ```
738
776
 
777
+ ### `CLIPS::Environment::Defmodule.get_defrule_list`
778
+ ### `CLIPS::Environment::Defmodule#get_defrule_list`
779
+
780
+ Return an array of Defrule names as symbols in the Defmodule
781
+
782
+ ```ruby
783
+ CLIPS::Environment::Defmodule.get_defrule_list(defmodule)
784
+ defmodule.get_defrule_list
785
+ ```
786
+
739
787
  ### `CLIPS::Environment.find_deffacts`
740
788
  ### `CLIPS::Environment#find_deffacts`
741
789
 
@@ -188,6 +188,10 @@ static VALUE clips_environment_assert_string(VALUE self, VALUE string)
188
188
 
189
189
  Fact *fact = AssertString(env, StringValueCStr(string));
190
190
 
191
+ if (fact == NULL) {
192
+ return Qnil;
193
+ }
194
+
191
195
  VALUE rb_fact =
192
196
  TypedData_Wrap_Struct(rb_const_get(CLASS_OF(self), rb_intern("Fact")), &Fact_type, fact);
193
197
 
@@ -1950,6 +1954,74 @@ static VALUE clips_environment_static_get_deftemplate_list(int argc, VALUE *argv
1950
1954
  return out;
1951
1955
  }
1952
1956
 
1957
+ static VALUE clips_environment_get_defrule_list(int argc, VALUE *argv, VALUE rbEnvironment) {
1958
+ VALUE defmodule_or_defmodule_name;
1959
+ Environment *env;
1960
+ Defmodule *module;
1961
+ CLIPSValue value;
1962
+ VALUE out;
1963
+
1964
+ TypedData_Get_Struct(rbEnvironment, Environment, &Environment_type, env);
1965
+
1966
+ rb_scan_args(argc, argv, "01", &defmodule_or_defmodule_name);
1967
+ switch (TYPE(defmodule_or_defmodule_name)) {
1968
+ case T_NIL:
1969
+ module = NULL;
1970
+ break;
1971
+ case T_STRING:
1972
+ case T_SYMBOL:
1973
+ TypedData_Get_Struct(
1974
+ clips_environment_find_defmodule(rbEnvironment, defmodule_or_defmodule_name),
1975
+ Defmodule, &Defmodule_type, module);
1976
+ break;
1977
+ case T_DATA:
1978
+ TypedData_Get_Struct(defmodule_or_defmodule_name, Defmodule, &Defmodule_type, module);
1979
+ break;
1980
+ default:
1981
+ rb_warn("defmodule name must be a symbol or string");
1982
+ return Qnil;
1983
+ }
1984
+ GetDefruleList(env, &value, module);
1985
+
1986
+ CLIPSValue_to_VALUE(&value, &out, &rbEnvironment);
1987
+
1988
+ return out;
1989
+ }
1990
+
1991
+ static VALUE clips_environment_static_get_defrule_list(int argc, VALUE *argv, VALUE klass) {
1992
+ VALUE rbEnvironment, defmodule_or_defmodule_name;
1993
+ Environment *env;
1994
+ Defmodule *module;
1995
+ CLIPSValue value;
1996
+ VALUE out;
1997
+
1998
+ rb_scan_args(argc, argv, "11", &rbEnvironment, &defmodule_or_defmodule_name);
1999
+
2000
+ TypedData_Get_Struct(rbEnvironment, Environment, &Environment_type, env);
2001
+ switch (TYPE(defmodule_or_defmodule_name)) {
2002
+ case T_NIL:
2003
+ module = NULL;
2004
+ break;
2005
+ case T_STRING:
2006
+ case T_SYMBOL:
2007
+ TypedData_Get_Struct(
2008
+ clips_environment_find_defmodule(rbEnvironment, defmodule_or_defmodule_name),
2009
+ Defmodule, &Defmodule_type, module);
2010
+ break;
2011
+ case T_DATA:
2012
+ TypedData_Get_Struct(defmodule_or_defmodule_name, Defmodule, &Defmodule_type, module);
2013
+ break;
2014
+ default:
2015
+ rb_warn("defmodule name must be a symbol or string");
2016
+ return Qnil;
2017
+ }
2018
+ GetDefruleList(env, &value, module);
2019
+
2020
+ CLIPSValue_to_VALUE(&value, &out, &rbEnvironment);
2021
+
2022
+ return out;
2023
+ }
2024
+
1953
2025
  static VALUE clips_environment_defmodule_name(VALUE self)
1954
2026
  {
1955
2027
  Defmodule *defmodule;
@@ -2046,6 +2118,30 @@ static VALUE clips_environment_defmodule_static_get_deftemplate_list(VALUE self,
2046
2118
  return clips_environment_defmodule_get_deftemplate_list(rbDefmodule);
2047
2119
  }
2048
2120
 
2121
+ static VALUE clips_environment_defmodule_get_defrule_list(VALUE self)
2122
+ {
2123
+ Defmodule *module;
2124
+ Environment *env;
2125
+ CLIPSValue value;
2126
+ VALUE out;
2127
+
2128
+ VALUE rbEnvironment = rb_iv_get(self, "@environment");
2129
+
2130
+ TypedData_Get_Struct(self, Defmodule, &Defmodule_type, module);
2131
+ TypedData_Get_Struct(rbEnvironment, Environment, &Environment_type, env);
2132
+
2133
+ GetDefruleList(env, &value, module);
2134
+
2135
+ CLIPSValue_to_VALUE(&value, &out, &rbEnvironment);
2136
+
2137
+ return out;
2138
+ }
2139
+
2140
+ static VALUE clips_environment_defmodule_static_get_defrule_list(VALUE self, VALUE rbDefmodule)
2141
+ {
2142
+ return clips_environment_defmodule_get_defrule_list(rbDefmodule);
2143
+ }
2144
+
2049
2145
  static VALUE clips_environment_defrule_name(VALUE self)
2050
2146
  {
2051
2147
  Defrule *defrule;
@@ -2110,6 +2206,24 @@ static VALUE clips_environment_deftemplate_static_is_deletable(VALUE self, VALUE
2110
2206
  return clips_environment_deftemplate_is_deletable(rbDeftemplate);
2111
2207
  }
2112
2208
 
2209
+ static VALUE clips_environment_deftemplate_is_implied(VALUE self)
2210
+ {
2211
+ Deftemplate *deftemplate;
2212
+
2213
+ TypedData_Get_Struct(self, Deftemplate, &Deftemplate_type, deftemplate);
2214
+
2215
+ if (deftemplate->implied) {
2216
+ return Qtrue;
2217
+ } else {
2218
+ return Qfalse;
2219
+ }
2220
+ }
2221
+
2222
+ static VALUE clips_environment_deftemplate_static_is_implied(VALUE self, VALUE rbDeftemplate)
2223
+ {
2224
+ return clips_environment_deftemplate_is_implied(rbDeftemplate);
2225
+ }
2226
+
2113
2227
  static VALUE clips_environment_deftemplate_slot_existp(VALUE self, VALUE slot_name)
2114
2228
  {
2115
2229
  Deftemplate *deftemplate;
@@ -2292,6 +2406,20 @@ static VALUE clips_environment_defrule_static_remove_break(VALUE self, VALUE rbD
2292
2406
  return clips_environment_defrule_remove_break(rbDefrule);
2293
2407
  }
2294
2408
 
2409
+ static VALUE clips_environment_defrule_salience(VALUE self)
2410
+ {
2411
+ Defrule *defrule;
2412
+
2413
+ TypedData_Get_Struct(self, Defrule, &Defrule_type, defrule);
2414
+
2415
+ return INT2NUM(defrule->salience);
2416
+ }
2417
+
2418
+ static VALUE clips_environment_defrule_static_salience(VALUE self, VALUE rbDefrule)
2419
+ {
2420
+ return clips_environment_defrule_salience(rbDefrule);
2421
+ }
2422
+
2295
2423
  static VALUE clips_environment_watch(VALUE self, VALUE item)
2296
2424
  {
2297
2425
  Environment *env;
@@ -2991,6 +3119,8 @@ void Init_clipsruby(void)
2991
3119
  rb_define_method(rbEnvironment, "get_fact_list", clips_environment_get_fact_list, -1);
2992
3120
  rb_define_singleton_method(rbEnvironment, "get_deftemplate_list", clips_environment_static_get_deftemplate_list, -1);
2993
3121
  rb_define_method(rbEnvironment, "get_deftemplate_list", clips_environment_get_deftemplate_list, -1);
3122
+ rb_define_singleton_method(rbEnvironment, "get_defrule_list", clips_environment_static_get_defrule_list, -1);
3123
+ rb_define_method(rbEnvironment, "get_defrule_list", clips_environment_get_defrule_list, -1);
2994
3124
  rb_define_singleton_method(rbEnvironment, "find_deffacts", clips_environment_static_find_deffacts, 2);
2995
3125
  rb_define_method(rbEnvironment, "find_deffacts", clips_environment_find_deffacts, 1);
2996
3126
  rb_define_singleton_method(rbEnvironment, "watch", clips_environment_static_watch, 2);
@@ -3099,6 +3229,8 @@ void Init_clipsruby(void)
3099
3229
  rb_define_method(rbDeftemplate, "slot_multip", clips_environment_deftemplate_slot_multip, 1);
3100
3230
  rb_define_singleton_method(rbDeftemplate, "slot_defaultp", clips_environment_deftemplate_static_slot_defaultp, 2);
3101
3231
  rb_define_method(rbDeftemplate, "slot_defaultp", clips_environment_deftemplate_slot_defaultp, 1);
3232
+ rb_define_singleton_method(rbDeftemplate, "is_implied", clips_environment_deftemplate_static_is_implied, 1);
3233
+ rb_define_method(rbDeftemplate, "is_implied", clips_environment_deftemplate_is_implied, 0);
3102
3234
 
3103
3235
  VALUE rbDefmodule = rb_define_class_under(rbEnvironment, "Defmodule", rb_cObject);
3104
3236
  rb_define_alloc_func(rbDefmodule, defmodule_alloc);
@@ -3112,6 +3244,8 @@ void Init_clipsruby(void)
3112
3244
  rb_define_method(rbDefmodule, "get_fact_list", clips_environment_defmodule_get_fact_list, 0);
3113
3245
  rb_define_singleton_method(rbDefmodule, "get_deftemplate_list", clips_environment_defmodule_static_get_deftemplate_list, 1);
3114
3246
  rb_define_method(rbDefmodule, "get_deftemplate_list", clips_environment_defmodule_get_deftemplate_list, 0);
3247
+ rb_define_singleton_method(rbDefmodule, "get_defrule_list", clips_environment_defmodule_static_get_defrule_list, 1);
3248
+ rb_define_method(rbDefmodule, "get_defrule_list", clips_environment_defmodule_get_defrule_list, 0);
3115
3249
 
3116
3250
  VALUE rbFact = rb_define_class_under(rbEnvironment, "Fact", rb_cObject);
3117
3251
  rb_define_alloc_func(rbFact, fact_alloc);
@@ -3150,6 +3284,8 @@ void Init_clipsruby(void)
3150
3284
  rb_define_method(rbDefrule, "set_break", clips_environment_defrule_set_break, 0);
3151
3285
  rb_define_singleton_method(rbDefrule, "remove_break", clips_environment_defrule_static_remove_break, 1);
3152
3286
  rb_define_method(rbDefrule, "remove_break", clips_environment_defrule_remove_break, 0);
3287
+ rb_define_singleton_method(rbDefrule, "salience", clips_environment_defrule_static_salience, 1);
3288
+ rb_define_method(rbDefrule, "salience", clips_environment_defrule_salience, 0);
3153
3289
 
3154
3290
  VALUE rbInstance = rb_define_class_under(rbEnvironment, "Instance", rb_cObject);
3155
3291
  }
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.28
4
+ version: 0.0.30
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-19 00:00:00.000000000 Z
11
+ date: 2024-09-23 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
@@ -385,7 +385,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
385
385
  - !ruby/object:Gem::Version
386
386
  version: '0'
387
387
  requirements: []
388
- rubygems_version: 3.5.11
388
+ rubygems_version: 3.5.16
389
389
  signing_key:
390
390
  specification_version: 4
391
391
  summary: Calling CLIPS from within Ruby