clipsruby 0.0.21 → 0.0.23
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 +47 -0
- data/ext/clipsruby/clipsruby.c +177 -0
- 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: 994b076d823d294b992d1621ec327e72cd415602c744d3214b16e15b6624dcbd
|
4
|
+
data.tar.gz: 864a892fb3405400362b6ceeea13d24f3c22bf4508f4013b14c6f3a6dd102e4f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a2bbd8b165667a1a2b07b19b8099ec0dfae9ccbf4b669d469421f5db66c53840a00a0855f07479b272e030b0fb06430f28382340af1e3efe60af13858542ca4
|
7
|
+
data.tar.gz: 918c4ffd67a5623d761805e4f60920c4ac250e321cb33fca2f61ad26ff5ac28b4cc92acaaeaa1478e8110c3697d719a9c8e69da5da96fcda88d5b2a4d078bef0
|
data/README.md
CHANGED
@@ -332,6 +332,16 @@ CLIPS::Environment::Fact.index(fact)
|
|
332
332
|
fact.index
|
333
333
|
```
|
334
334
|
|
335
|
+
### `CLIPS::Environment::Fact.deftemplate`
|
336
|
+
### `CLIPS::Environment::Fact#deftemplate`
|
337
|
+
|
338
|
+
Returns the Deftemplate object for a fact
|
339
|
+
|
340
|
+
```ruby
|
341
|
+
CLIPS::Environment::Fact.deftemplate(fact)
|
342
|
+
fact.deftemplate
|
343
|
+
```
|
344
|
+
|
335
345
|
### `CLIPS::Environment::Fact.deftemplate_name`
|
336
346
|
### `CLIPS::Environment::Fact#deftemplate_name`
|
337
347
|
|
@@ -504,6 +514,22 @@ CLIPS::Environment::Defmodule.get_fact_list(defmodule)
|
|
504
514
|
defmodule.get_fact_list
|
505
515
|
```
|
506
516
|
|
517
|
+
### `CLIPS::Environment.get_deftemplate_list`
|
518
|
+
### `CLIPS::Environment#get_deftemplate_list`
|
519
|
+
|
520
|
+
Return an array of Deftemplate names as symbols in the environment. Pass an argument of a
|
521
|
+
symbol, string, or Defmodule object in order to only get Deftemplates
|
522
|
+
in that Defmodule. If you do not, it will return all Deftemplate names in all modules.
|
523
|
+
|
524
|
+
```ruby
|
525
|
+
CLIPS::Environment.get_deftemplate_list
|
526
|
+
env.get_deftemplate_list
|
527
|
+
CLIPS::Environment.get_deftemplate_list(:MAIN)
|
528
|
+
env.get_deftemplate_list(:MAIN)
|
529
|
+
CLIPS::Environment.get_deftemplate_list(defmodule)
|
530
|
+
env.get_deftemplate_list(defmodule)
|
531
|
+
```
|
532
|
+
|
507
533
|
### `CLIPS::Environment.find_deftemplate`
|
508
534
|
### `CLIPS::Environment#find_deftemplate`
|
509
535
|
|
@@ -534,6 +560,27 @@ CLIPS::Environment::Deftemplate.pp_form(deftemplate)
|
|
534
560
|
deftemplate.pp_form
|
535
561
|
```
|
536
562
|
|
563
|
+
### `CLIPS::Environment::Deftemplate.assert_hash`
|
564
|
+
### `CLIPS::Environment::Deftemplate#assert_hash`
|
565
|
+
|
566
|
+
Asserts a hash in the clips environment that a Deftemplate is defined in.
|
567
|
+
Returns the Fact object that was just asserted
|
568
|
+
|
569
|
+
```ruby
|
570
|
+
CLIPS::Environment::Deftemplate.assert_hash(deftemplate, foo: :bar)
|
571
|
+
deftemplate.assert_hash(foo: :bar)
|
572
|
+
```
|
573
|
+
|
574
|
+
### `CLIPS::Environment::Defmodule.get_deftemplate_list`
|
575
|
+
### `CLIPS::Environment::Defmodule#get_deftemplate_list`
|
576
|
+
|
577
|
+
Return an array of Deftemplate names as symboles in the Defmodule
|
578
|
+
|
579
|
+
```ruby
|
580
|
+
CLIPS::Environment::Defmodule.get_deftemplate_list(defmodule)
|
581
|
+
defmodule.get_deftemplate_list
|
582
|
+
```
|
583
|
+
|
537
584
|
### `CLIPS::Environment.find_deffacts`
|
538
585
|
### `CLIPS::Environment#find_deffacts`
|
539
586
|
|
data/ext/clipsruby/clipsruby.c
CHANGED
@@ -62,6 +62,26 @@ static const rb_data_type_t Fact_type = {
|
|
62
62
|
.flags = RUBY_TYPED_FREE_IMMEDIATELY
|
63
63
|
};
|
64
64
|
|
65
|
+
static VALUE clips_environment_fact_deftemplate(VALUE self)
|
66
|
+
{
|
67
|
+
VALUE rbDeftemplate, rbEnvironment;
|
68
|
+
Fact *fact;
|
69
|
+
Deftemplate *template;
|
70
|
+
|
71
|
+
TypedData_Get_Struct(self, Fact, &Fact_type, fact);
|
72
|
+
|
73
|
+
template = FactDeftemplate(fact);
|
74
|
+
rbEnvironment = rb_iv_get(self, "@environment");
|
75
|
+
rbDeftemplate = TypedData_Wrap_Struct(rb_const_get(rb_obj_class(rbEnvironment), rb_intern("Deftemplate")), &Deftemplate_type, template);
|
76
|
+
rb_iv_set(rbDeftemplate, "@environment", rbEnvironment);
|
77
|
+
return rbDeftemplate;
|
78
|
+
}
|
79
|
+
|
80
|
+
static VALUE clips_environment_fact_static_deftemplate(VALUE self, VALUE rbFact)
|
81
|
+
{
|
82
|
+
return clips_environment_fact_deftemplate(rbFact);
|
83
|
+
}
|
84
|
+
|
65
85
|
static VALUE clips_environment_fact_deftemplate_name(VALUE self)
|
66
86
|
{
|
67
87
|
Fact *fact;
|
@@ -408,6 +428,64 @@ static VALUE clips_environment_static_assert_hash(VALUE self, VALUE environment,
|
|
408
428
|
return clips_environment_assert_hash(environment, deftemplate_name, hash);
|
409
429
|
}
|
410
430
|
|
431
|
+
static VALUE clips_environment_deftemplate_assert_hash(VALUE self, VALUE hash)
|
432
|
+
{
|
433
|
+
const char *cdeftemplate_name;
|
434
|
+
|
435
|
+
Environment *env;
|
436
|
+
Deftemplate *template;
|
437
|
+
|
438
|
+
VALUE rbEnvironment = rb_iv_get(self, "@environment");
|
439
|
+
TypedData_Get_Struct(self, Deftemplate, &Deftemplate_type, template);
|
440
|
+
TypedData_Get_Struct(rbEnvironment, Environment, &Environment_type, env);
|
441
|
+
|
442
|
+
cdeftemplate_name = DeftemplateName(template);
|
443
|
+
|
444
|
+
FactBuilder *fb = CreateFactBuilder(env, cdeftemplate_name);
|
445
|
+
switch (FBError(env))
|
446
|
+
{
|
447
|
+
case FBE_NO_ERROR:
|
448
|
+
break;
|
449
|
+
case FBE_DEFTEMPLATE_NOT_FOUND_ERROR:
|
450
|
+
rb_warn("Could not assert fact; deftemplate not found!");
|
451
|
+
return Qnil;
|
452
|
+
case FBE_IMPLIED_DEFTEMPLATE_ERROR:
|
453
|
+
rb_warn("Could not assert fact; cannot use assert_hash to create non-deftemplated facts!");
|
454
|
+
return Qnil;
|
455
|
+
}
|
456
|
+
void *args[2] = { (void *)fb, (void *)env };
|
457
|
+
rb_hash_foreach(hash, _clips_environment_assert_hash, (VALUE)args);
|
458
|
+
Fact *fact = FBAssert(fb);
|
459
|
+
FBDispose(fb);
|
460
|
+
|
461
|
+
switch (FBError(env))
|
462
|
+
{
|
463
|
+
case FBE_NO_ERROR:
|
464
|
+
break;
|
465
|
+
case FBE_NULL_POINTER_ERROR:
|
466
|
+
rb_warn("Could not assert fact. This might be a bug in clipsruby!");
|
467
|
+
return Qnil;
|
468
|
+
case FBE_COULD_NOT_ASSERT_ERROR:
|
469
|
+
rb_warn("Could not assert fact. Pattern matching of a fact or instance is already occurring.");
|
470
|
+
return Qnil;
|
471
|
+
case FBE_RULE_NETWORK_ERROR:
|
472
|
+
rb_warn("Could not assert fact. An error occurs while the assertion was being processed in the rule network.");
|
473
|
+
return Qnil;
|
474
|
+
}
|
475
|
+
|
476
|
+
VALUE rb_fact =
|
477
|
+
TypedData_Wrap_Struct(rb_const_get(CLASS_OF(rbEnvironment), rb_intern("Fact")), &Fact_type, fact);
|
478
|
+
|
479
|
+
rb_iv_set(rb_fact, "@environment", rbEnvironment);
|
480
|
+
|
481
|
+
return rb_fact;
|
482
|
+
}
|
483
|
+
|
484
|
+
static VALUE clips_environment_deftemplate_static_assert_hash(VALUE self, VALUE deftemplate, VALUE hash)
|
485
|
+
{
|
486
|
+
return clips_environment_deftemplate_assert_hash(deftemplate, hash);
|
487
|
+
}
|
488
|
+
|
411
489
|
static void CLIPSValue_to_VALUE(CLIPSValue *from, VALUE *value, VALUE *rbEnvironment)
|
412
490
|
{
|
413
491
|
Environment *env;
|
@@ -1586,7 +1664,74 @@ static VALUE clips_environment_static_get_fact_list(int argc, VALUE *argv, VALUE
|
|
1586
1664
|
CLIPSValue_to_VALUE(&value, &out, &rbEnvironment);
|
1587
1665
|
|
1588
1666
|
return out;
|
1667
|
+
}
|
1668
|
+
|
1669
|
+
static VALUE clips_environment_get_deftemplate_list(int argc, VALUE *argv, VALUE rbEnvironment) {
|
1670
|
+
VALUE defmodule_or_defmodule_name;
|
1671
|
+
Environment *env;
|
1672
|
+
Defmodule *module;
|
1673
|
+
CLIPSValue value;
|
1674
|
+
VALUE out;
|
1675
|
+
|
1676
|
+
TypedData_Get_Struct(rbEnvironment, Environment, &Environment_type, env);
|
1677
|
+
|
1678
|
+
rb_scan_args(argc, argv, "01", &defmodule_or_defmodule_name);
|
1679
|
+
switch (TYPE(defmodule_or_defmodule_name)) {
|
1680
|
+
case T_NIL:
|
1681
|
+
module = NULL;
|
1682
|
+
break;
|
1683
|
+
case T_STRING:
|
1684
|
+
case T_SYMBOL:
|
1685
|
+
TypedData_Get_Struct(
|
1686
|
+
clips_environment_find_defmodule(rbEnvironment, defmodule_or_defmodule_name),
|
1687
|
+
Defmodule, &Defmodule_type, module);
|
1688
|
+
break;
|
1689
|
+
case T_DATA:
|
1690
|
+
TypedData_Get_Struct(defmodule_or_defmodule_name, Defmodule, &Defmodule_type, module);
|
1691
|
+
break;
|
1692
|
+
default:
|
1693
|
+
rb_warn("defmodule name must be a symbol or string");
|
1694
|
+
return Qnil;
|
1695
|
+
}
|
1696
|
+
GetDeftemplateList(env, &value, module);
|
1697
|
+
|
1698
|
+
CLIPSValue_to_VALUE(&value, &out, &rbEnvironment);
|
1699
|
+
|
1700
|
+
return out;
|
1701
|
+
}
|
1702
|
+
|
1703
|
+
static VALUE clips_environment_static_get_deftemplate_list(int argc, VALUE *argv, VALUE klass) {
|
1704
|
+
VALUE rbEnvironment, defmodule_or_defmodule_name;
|
1705
|
+
Environment *env;
|
1706
|
+
Defmodule *module;
|
1707
|
+
CLIPSValue value;
|
1708
|
+
VALUE out;
|
1709
|
+
|
1710
|
+
rb_scan_args(argc, argv, "11", &rbEnvironment, &defmodule_or_defmodule_name);
|
1589
1711
|
|
1712
|
+
TypedData_Get_Struct(rbEnvironment, Environment, &Environment_type, env);
|
1713
|
+
switch (TYPE(defmodule_or_defmodule_name)) {
|
1714
|
+
case T_NIL:
|
1715
|
+
module = NULL;
|
1716
|
+
break;
|
1717
|
+
case T_STRING:
|
1718
|
+
case T_SYMBOL:
|
1719
|
+
TypedData_Get_Struct(
|
1720
|
+
clips_environment_find_defmodule(rbEnvironment, defmodule_or_defmodule_name),
|
1721
|
+
Defmodule, &Defmodule_type, module);
|
1722
|
+
break;
|
1723
|
+
case T_DATA:
|
1724
|
+
TypedData_Get_Struct(defmodule_or_defmodule_name, Defmodule, &Defmodule_type, module);
|
1725
|
+
break;
|
1726
|
+
default:
|
1727
|
+
rb_warn("defmodule name must be a symbol or string");
|
1728
|
+
return Qnil;
|
1729
|
+
}
|
1730
|
+
GetDeftemplateList(env, &value, module);
|
1731
|
+
|
1732
|
+
CLIPSValue_to_VALUE(&value, &out, &rbEnvironment);
|
1733
|
+
|
1734
|
+
return out;
|
1590
1735
|
}
|
1591
1736
|
|
1592
1737
|
static VALUE clips_environment_defmodule_name(VALUE self)
|
@@ -1661,6 +1806,30 @@ static VALUE clips_environment_defmodule_static_get_fact_list(VALUE self, VALUE
|
|
1661
1806
|
return clips_environment_defmodule_get_fact_list(rbDefmodule);
|
1662
1807
|
}
|
1663
1808
|
|
1809
|
+
static VALUE clips_environment_defmodule_get_deftemplate_list(VALUE self)
|
1810
|
+
{
|
1811
|
+
Defmodule *module;
|
1812
|
+
Environment *env;
|
1813
|
+
CLIPSValue value;
|
1814
|
+
VALUE out;
|
1815
|
+
|
1816
|
+
VALUE rbEnvironment = rb_iv_get(self, "@environment");
|
1817
|
+
|
1818
|
+
TypedData_Get_Struct(self, Defmodule, &Defmodule_type, module);
|
1819
|
+
TypedData_Get_Struct(rbEnvironment, Environment, &Environment_type, env);
|
1820
|
+
|
1821
|
+
GetDeftemplateList(env, &value, module);
|
1822
|
+
|
1823
|
+
CLIPSValue_to_VALUE(&value, &out, &rbEnvironment);
|
1824
|
+
|
1825
|
+
return out;
|
1826
|
+
}
|
1827
|
+
|
1828
|
+
static VALUE clips_environment_defmodule_static_get_deftemplate_list(VALUE self, VALUE rbDefmodule)
|
1829
|
+
{
|
1830
|
+
return clips_environment_defmodule_get_deftemplate_list(rbDefmodule);
|
1831
|
+
}
|
1832
|
+
|
1664
1833
|
static VALUE clips_environment_defrule_name(VALUE self)
|
1665
1834
|
{
|
1666
1835
|
Defrule *defrule;
|
@@ -1818,6 +1987,8 @@ void Init_clipsruby(void)
|
|
1818
1987
|
rb_define_method(rbEnvironment, "set_current_module", clips_environment_set_current_module, 1);
|
1819
1988
|
rb_define_singleton_method(rbEnvironment, "get_fact_list", clips_environment_static_get_fact_list, -1);
|
1820
1989
|
rb_define_method(rbEnvironment, "get_fact_list", clips_environment_get_fact_list, -1);
|
1990
|
+
rb_define_singleton_method(rbEnvironment, "get_deftemplate_list", clips_environment_static_get_deftemplate_list, -1);
|
1991
|
+
rb_define_method(rbEnvironment, "get_deftemplate_list", clips_environment_get_deftemplate_list, -1);
|
1821
1992
|
rb_define_singleton_method(rbEnvironment, "find_deffacts", clips_environment_static_find_deffacts, 2);
|
1822
1993
|
rb_define_method(rbEnvironment, "find_deffacts", clips_environment_find_deffacts, 1);
|
1823
1994
|
|
@@ -1834,6 +2005,8 @@ void Init_clipsruby(void)
|
|
1834
2005
|
rb_define_method(rbDeftemplate, "name", clips_environment_deftemplate_name, 0);
|
1835
2006
|
rb_define_singleton_method(rbDeftemplate, "pp_form", clips_environment_deftemplate_static_pp_form, 1);
|
1836
2007
|
rb_define_method(rbDeftemplate, "pp_form", clips_environment_deftemplate_pp_form, 0);
|
2008
|
+
rb_define_singleton_method(rbDeftemplate, "assert_hash", clips_environment_deftemplate_static_assert_hash, 2);
|
2009
|
+
rb_define_method(rbDeftemplate, "assert_hash", clips_environment_deftemplate_assert_hash, 1);
|
1837
2010
|
|
1838
2011
|
VALUE rbDefmodule = rb_define_class_under(rbEnvironment, "Defmodule", rb_cObject);
|
1839
2012
|
rb_define_alloc_func(rbDefmodule, defmodule_alloc);
|
@@ -1845,9 +2018,13 @@ void Init_clipsruby(void)
|
|
1845
2018
|
rb_define_method(rbDefmodule, "set_current", clips_environment_defmodule_set_current, 0);
|
1846
2019
|
rb_define_singleton_method(rbDefmodule, "get_fact_list", clips_environment_defmodule_static_get_fact_list, 1);
|
1847
2020
|
rb_define_method(rbDefmodule, "get_fact_list", clips_environment_defmodule_get_fact_list, 0);
|
2021
|
+
rb_define_singleton_method(rbDefmodule, "get_deftemplate_list", clips_environment_defmodule_static_get_deftemplate_list, 1);
|
2022
|
+
rb_define_method(rbDefmodule, "get_deftemplate_list", clips_environment_defmodule_get_deftemplate_list, 0);
|
1848
2023
|
|
1849
2024
|
VALUE rbFact = rb_define_class_under(rbEnvironment, "Fact", rb_cObject);
|
1850
2025
|
rb_define_alloc_func(rbFact, fact_alloc);
|
2026
|
+
rb_define_singleton_method(rbFact, "deftemplate", clips_environment_fact_static_deftemplate, 1);
|
2027
|
+
rb_define_method(rbFact, "deftemplate", clips_environment_fact_deftemplate, 0);
|
1851
2028
|
rb_define_singleton_method(rbFact, "deftemplate_name", clips_environment_fact_static_deftemplate_name, 1);
|
1852
2029
|
rb_define_method(rbFact, "deftemplate_name", clips_environment_fact_deftemplate_name, 0);
|
1853
2030
|
rb_define_singleton_method(rbFact, "to_h", clips_environment_fact_static_to_h, 1);
|
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.23
|
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-14 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
|