clipsruby 0.0.6 → 0.0.7
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 +124 -0
- data/ext/clipsruby/clipsruby.c +28 -21
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 75e4ce843f3549eb6b8508d4d97ab8193dc8434acab30659af50871953759991
|
4
|
+
data.tar.gz: 5372088f0743df5a5e3e94833bb7334608bfe85c0ede4879476e3a014eeb034d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e3700fb8eb942640cd698985ecf00190ad447b89dfeed35df3125924e577de0be0f6b56695a1f0e2adfc078b2cdc7655bbdf08c22f40624eb305d4d539da2fd5
|
7
|
+
data.tar.gz: 7626b936453007c332c1cc1f191e449ce3c68f9447281a595fceef524a0cc9bc5a5c603d2afd5553887049d380c6297d0a8e27e9256f9fc54330722cdaaf8ba5
|
data/README.md
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
# clipsruby
|
2
|
+
|
3
|
+
## Description
|
4
|
+
|
5
|
+
Use the CLIPS programming language from within Ruby
|
6
|
+
|
7
|
+
## API
|
8
|
+
|
9
|
+
### `CLIPS.create_environment`
|
10
|
+
### `CLIPS::Environment.new`
|
11
|
+
|
12
|
+
Create a new CLIPS environment in which you may define Rules,
|
13
|
+
assert Facts, and instantiate Objects.
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
env = CLIPS.create_environment
|
17
|
+
env2 = CLIPS::Environment.new
|
18
|
+
```
|
19
|
+
|
20
|
+
### `CLIPS::Environment.assert_string`
|
21
|
+
### `CLIPS::Environment#assert_string`
|
22
|
+
|
23
|
+
Assert a string as a Fact in the CLIPS environment.
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
fact = CLIPS::Environment.assert_string(env, "(foo bar)")
|
27
|
+
fact2 = env.assert_string("(bat baz)")
|
28
|
+
```
|
29
|
+
|
30
|
+
### `CLIPS::Environment.assert_hash`
|
31
|
+
### `CLIPS::Environment#assert_hash`
|
32
|
+
|
33
|
+
Asserts a Deftemplate fact into the CLIPS environment
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
fact = CLIPS::Environment.assert_hash(env, :my_deftemplate, a: 1, b: "asdf", c: :C)
|
37
|
+
fact2 = env.assert_hash(:my_deftemplate, d: 4.5, e: :asdf)
|
38
|
+
```
|
39
|
+
|
40
|
+
### `CLIPS::Environment.find_all_facts`
|
41
|
+
### `CLIPS::Environment#find_all_facts`
|
42
|
+
|
43
|
+
A light wrapper around the CLIPS find-all-facts function. Accepts a fact set template and query,
|
44
|
+
returns Facts in the environment that match as Ruby objects.
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
CLIPS::Environment.find_all_facts(env, "(?f my_deftemplate)")
|
48
|
+
env.find_all_facts("(?f my_deftemplate)")
|
49
|
+
CLIPS::Environment.find_all_facts(env, "(?f my_deftemplate)", "(eq ?f:b \"asdf\")")
|
50
|
+
env.find_all_facts("(?f my_deftemplate)", "(= ?f:a 1)")
|
51
|
+
```
|
52
|
+
|
53
|
+
### `CLIPS::Environment._eval`
|
54
|
+
### `CLIPS::Environment#_eval`
|
55
|
+
|
56
|
+
Evaluates a passed string in the CLIPS environment and returns the results.
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
CLIPS::Environment._eval(env, "(find-all-facts ((?f my_deftemplate)) TRUE)")
|
60
|
+
env._eval("(find-all-facts ((?f my_deftemplate)) TRUE)")
|
61
|
+
```
|
62
|
+
|
63
|
+
### `CLIPS::Environment.build`
|
64
|
+
### `CLIPS::Environment#build`
|
65
|
+
|
66
|
+
Build the constructs in the env as defined in a string
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
CLIPS::Environment.build(env, "(deftemplate my_template (slot a) (slot b) (slot c))")
|
70
|
+
env.build("(defrule do-a-thing (my_template (a ?a)) => (println \"a: \" ?a))")
|
71
|
+
```
|
72
|
+
|
73
|
+
### `CLIPS::Environment.add_udf`
|
74
|
+
### `CLIPS::Environment#add_udf`
|
75
|
+
|
76
|
+
Adds a ruby method as a User Defined Function (udf) to the CLIPS environment
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
class CLIPS::Environment
|
80
|
+
def foo(a, b=2)
|
81
|
+
a + b
|
82
|
+
end
|
83
|
+
|
84
|
+
def bar(word)
|
85
|
+
"You said #{word}!"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
env.add_udf(:foo)
|
90
|
+
CLIPS::Environment.add_udf(env, :bar)
|
91
|
+
```
|
92
|
+
|
93
|
+
### `CLIPS::Environment.run`
|
94
|
+
### `CLIPS::Environment#run`
|
95
|
+
|
96
|
+
Runs the rules engine, executing items on the agenda.
|
97
|
+
Optionally may take the number of items to run from the agenda as an argument.
|
98
|
+
|
99
|
+
```ruby
|
100
|
+
CLIPS::Environment.run(env, 1)
|
101
|
+
CLIPS::Environment.run(env)
|
102
|
+
env.run(1)
|
103
|
+
env.run
|
104
|
+
```
|
105
|
+
|
106
|
+
### `CLIPS::Environment.facts`
|
107
|
+
### `CLIPS::Environment#facts`
|
108
|
+
|
109
|
+
Print all Facts defined in the CLIPS environment
|
110
|
+
|
111
|
+
```ruby
|
112
|
+
CLIPS::Environment.facts(env)
|
113
|
+
env.facts
|
114
|
+
```
|
115
|
+
|
116
|
+
### `CLIPS::Environment::Fact.deftemplate_name`
|
117
|
+
### `CLIPS::Environment::Fact#deftemplate_name`
|
118
|
+
|
119
|
+
Returns the name of the Deftemplate for a fact as a symbol
|
120
|
+
|
121
|
+
```ruby
|
122
|
+
CLIPS::Environment::Fact.deftemplate_name(fact)
|
123
|
+
fact.deftemplate_name
|
124
|
+
```
|
data/ext/clipsruby/clipsruby.c
CHANGED
@@ -437,7 +437,6 @@ void UDFGenericFunction(
|
|
437
437
|
VALUE *current_argv = argv;
|
438
438
|
UDFValue theArg;
|
439
439
|
VALUE method = (VALUE)(context->context);
|
440
|
-
VALUE theValue;
|
441
440
|
VALUE rbEnvironment = rb_funcall(method, rb_intern("receiver"), 0);
|
442
441
|
while (UDFHasNextArgument(context))
|
443
442
|
{
|
@@ -602,22 +601,6 @@ static VALUE clips_environment_static_run(int argc, VALUE *argv, VALUE klass) {
|
|
602
601
|
return INT2NUM(Run(env, NUM2INT(integer)));
|
603
602
|
}
|
604
603
|
|
605
|
-
/*
|
606
|
-
static VALUE clips_environment_find_all_facts(VALUE self)
|
607
|
-
{
|
608
|
-
Fact *fact;
|
609
|
-
|
610
|
-
TypedData_Get_Struct(self, Fact, &Fact_type, fact);
|
611
|
-
|
612
|
-
return ID2SYM(rb_intern(DeftemplateName(FactDeftemplate(fact))));
|
613
|
-
}
|
614
|
-
|
615
|
-
static VALUE clips_environment_static_find_all_facts(VALUE self, VALUE rbFact)
|
616
|
-
{
|
617
|
-
return clips_environment_fact_deftemplate_name(rbFact);
|
618
|
-
}
|
619
|
-
*/
|
620
|
-
|
621
604
|
static VALUE clips_environment_eval(VALUE self, VALUE string)
|
622
605
|
{
|
623
606
|
Environment *env;
|
@@ -648,6 +631,32 @@ static VALUE clips_environment_static_eval(VALUE self, VALUE rbEnvironment, VALU
|
|
648
631
|
return clips_environment_eval(rbEnvironment, string);
|
649
632
|
}
|
650
633
|
|
634
|
+
static VALUE clips_environment_find_all_facts(int argc, VALUE *argv, VALUE environment) {
|
635
|
+
VALUE fact_set_template, query;
|
636
|
+
|
637
|
+
rb_scan_args(argc, argv, "11", &fact_set_template, &query);
|
638
|
+
if (NIL_P(query)) {
|
639
|
+
query = rb_str_new_cstr("TRUE");
|
640
|
+
}
|
641
|
+
|
642
|
+
return clips_environment_eval(
|
643
|
+
environment,
|
644
|
+
rb_sprintf("(find-all-facts (%s) %s)", StringValueCStr(fact_set_template), StringValueCStr(query)));
|
645
|
+
}
|
646
|
+
|
647
|
+
static VALUE clips_environment_static_find_all_facts(int argc, VALUE *argv, VALUE klass) {
|
648
|
+
VALUE rbEnvironment, fact_set_template, query;
|
649
|
+
|
650
|
+
rb_scan_args(argc, argv, "21", &rbEnvironment, &fact_set_template, &query);
|
651
|
+
if (NIL_P(query)) {
|
652
|
+
query = rb_str_new_cstr("TRUE");
|
653
|
+
}
|
654
|
+
|
655
|
+
return clips_environment_eval(
|
656
|
+
rbEnvironment,
|
657
|
+
rb_sprintf("(find-all-facts (%s) %s)", StringValueCStr(fact_set_template), StringValueCStr(query)));
|
658
|
+
}
|
659
|
+
|
651
660
|
void Init_clipsruby(void)
|
652
661
|
{
|
653
662
|
VALUE rbCLIPS = rb_define_module("CLIPS");
|
@@ -667,12 +676,10 @@ void Init_clipsruby(void)
|
|
667
676
|
rb_define_method(rbEnvironment, "add_udf", clips_environment_add_udf, -1);
|
668
677
|
rb_define_singleton_method(rbEnvironment, "run", clips_environment_static_run, -1);
|
669
678
|
rb_define_method(rbEnvironment, "run", clips_environment_run, -1);
|
670
|
-
/*
|
671
|
-
rb_define_singleton_method(rbEnvironment, "find_all_facts", clips_environment_static_find_all_facts, 2);
|
672
|
-
rb_define_method(rbEnvironment, "find_all_facts", clips_environment_find_all_facts, 1);
|
673
|
-
*/
|
674
679
|
rb_define_singleton_method(rbEnvironment, "_eval", clips_environment_static_eval, 2);
|
675
680
|
rb_define_method(rbEnvironment, "_eval", clips_environment_eval, 1);
|
681
|
+
rb_define_singleton_method(rbEnvironment, "find_all_facts", clips_environment_static_find_all_facts, -1);
|
682
|
+
rb_define_method(rbEnvironment, "find_all_facts", clips_environment_find_all_facts, -1);
|
676
683
|
|
677
684
|
VALUE rbFact = rb_define_class_under(rbEnvironment, "Fact", rb_cObject);
|
678
685
|
rb_define_singleton_method(rbFact, "deftemplate_name", clips_environment_fact_static_deftemplate_name, 1);
|
metadata
CHANGED
@@ -1,22 +1,24 @@
|
|
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.7
|
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-05 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
|
15
15
|
executables: []
|
16
16
|
extensions:
|
17
17
|
- ext/clipsruby/extconf.rb
|
18
|
-
extra_rdoc_files:
|
18
|
+
extra_rdoc_files:
|
19
|
+
- README.md
|
19
20
|
files:
|
21
|
+
- README.md
|
20
22
|
- ext/clipsruby/agenda.c
|
21
23
|
- ext/clipsruby/agenda.h
|
22
24
|
- ext/clipsruby/analysis.c
|