clipsruby 0.0.7 → 0.0.9
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 +25 -0
- data/ext/clipsruby/clipsruby.c +49 -4
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ede586e45827a7552e087b61a6f454a0d5c0c779e9d94b34deb2b13d1c7b5846
|
4
|
+
data.tar.gz: d46fdf1c8b9efd85600c976d414d4919ad8cd3c27171d15685f5dc059dd7c1e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7a4ee2975ebcb75e69f6dd5efd2a3c4c3d9b1c31fdd27a1e3fcbc918342d894bcae35cacdfbfd7c3ecdd3535474ccefe456dcc7ff7fb571b7254c4baf78812e1
|
7
|
+
data.tar.gz: 689887738a961e056658085ef49b1aa52de1679a630db22f6ca8e5b57bd562a65e87574f4b1f5dd96a4caf957aad22311f434356d7a5ea59272674a790bd5d58
|
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`
|
@@ -113,6 +124,16 @@ CLIPS::Environment.facts(env)
|
|
113
124
|
env.facts
|
114
125
|
```
|
115
126
|
|
127
|
+
### `CLIPS::Environment::Fact.to_h`
|
128
|
+
### `CLIPS::Environment::Fact#to_h`
|
129
|
+
|
130
|
+
Returns a hash representing the fact slot names and their values
|
131
|
+
|
132
|
+
```ruby
|
133
|
+
CLIPS::Environment::Fact.to_h(fact)
|
134
|
+
fact.to_h
|
135
|
+
```
|
136
|
+
|
116
137
|
### `CLIPS::Environment::Fact.deftemplate_name`
|
117
138
|
### `CLIPS::Environment::Fact#deftemplate_name`
|
118
139
|
|
@@ -122,3 +143,7 @@ Returns the name of the Deftemplate for a fact as a symbol
|
|
122
143
|
CLIPS::Environment::Fact.deftemplate_name(fact)
|
123
144
|
fact.deftemplate_name
|
124
145
|
```
|
146
|
+
|
147
|
+
## Running the tests
|
148
|
+
|
149
|
+
Simply do `rake compile` and then `rake test` in order to run the tests.
|
data/ext/clipsruby/clipsruby.c
CHANGED
@@ -350,7 +350,7 @@ static void CLIPSValue_to_VALUE(CLIPSValue *from, VALUE *value, VALUE *rbEnviron
|
|
350
350
|
} else if (from->lexemeValue == FalseSymbol(env)) {
|
351
351
|
*value = Qfalse;
|
352
352
|
} else {
|
353
|
-
*value =
|
353
|
+
*value = ID2SYM(rb_intern(from->lexemeValue->contents));
|
354
354
|
}
|
355
355
|
break;
|
356
356
|
case INTEGER_TYPE:
|
@@ -402,7 +402,7 @@ static void UDFValue_to_VALUE(UDFValue *from, VALUE *value, VALUE *rbEnvironment
|
|
402
402
|
} else if (from->lexemeValue == FalseSymbol(env)) {
|
403
403
|
*value = Qfalse;
|
404
404
|
} else {
|
405
|
-
*value =
|
405
|
+
*value = ID2SYM(rb_intern(from->lexemeValue->contents));
|
406
406
|
}
|
407
407
|
break;
|
408
408
|
case INTEGER_TYPE:
|
@@ -657,6 +657,51 @@ static VALUE clips_environment_static_find_all_facts(int argc, VALUE *argv, VALU
|
|
657
657
|
rb_sprintf("(find-all-facts (%s) %s)", StringValueCStr(fact_set_template), StringValueCStr(query)));
|
658
658
|
}
|
659
659
|
|
660
|
+
static VALUE clips_environment_fact_to_h(VALUE self)
|
661
|
+
{
|
662
|
+
Fact *fact;
|
663
|
+
CLIPSValue key, value;
|
664
|
+
VALUE rbEnvironment = rb_iv_get(self, "@environment");
|
665
|
+
|
666
|
+
TypedData_Get_Struct(self, Fact, &Fact_type, fact);
|
667
|
+
|
668
|
+
FactSlotNames(fact, &key);
|
669
|
+
|
670
|
+
VALUE hash = rb_hash_new();
|
671
|
+
for (size_t i = 0; i < key.multifieldValue->length; i++)
|
672
|
+
{
|
673
|
+
VALUE innerValue;
|
674
|
+
GetFactSlot(fact, key.multifieldValue->contents[i].lexemeValue->contents, &value);
|
675
|
+
CLIPSValue_to_VALUE(&value, &innerValue, &rbEnvironment);
|
676
|
+
rb_hash_aset(hash, ID2SYM(rb_intern(key.multifieldValue->contents[i].lexemeValue->contents)), innerValue);
|
677
|
+
}
|
678
|
+
|
679
|
+
return hash;
|
680
|
+
}
|
681
|
+
|
682
|
+
static VALUE clips_environment_fact_static_to_h(VALUE self, VALUE rbFact)
|
683
|
+
{
|
684
|
+
return clips_environment_fact_to_h(rbFact);
|
685
|
+
}
|
686
|
+
|
687
|
+
static VALUE clips_environment_batch_star(VALUE self, VALUE path)
|
688
|
+
{
|
689
|
+
Environment *env;
|
690
|
+
|
691
|
+
TypedData_Get_Struct(self, Environment, &Environment_type, env);
|
692
|
+
|
693
|
+
if (BatchStar(env, StringValueCStr(path))) {
|
694
|
+
return Qtrue;
|
695
|
+
} else {
|
696
|
+
return Qfalse;
|
697
|
+
}
|
698
|
+
}
|
699
|
+
|
700
|
+
static VALUE clips_environment_static_batch_star(VALUE self, VALUE rbEnvironment, VALUE path)
|
701
|
+
{
|
702
|
+
return clips_environment_batch_star(rbEnvironment, path);
|
703
|
+
}
|
704
|
+
|
660
705
|
void Init_clipsruby(void)
|
661
706
|
{
|
662
707
|
VALUE rbCLIPS = rb_define_module("CLIPS");
|
@@ -680,14 +725,14 @@ void Init_clipsruby(void)
|
|
680
725
|
rb_define_method(rbEnvironment, "_eval", clips_environment_eval, 1);
|
681
726
|
rb_define_singleton_method(rbEnvironment, "find_all_facts", clips_environment_static_find_all_facts, -1);
|
682
727
|
rb_define_method(rbEnvironment, "find_all_facts", clips_environment_find_all_facts, -1);
|
728
|
+
rb_define_singleton_method(rbEnvironment, "batch_star", clips_environment_static_batch_star, 2);
|
729
|
+
rb_define_method(rbEnvironment, "batch_star", clips_environment_batch_star, 1);
|
683
730
|
|
684
731
|
VALUE rbFact = rb_define_class_under(rbEnvironment, "Fact", rb_cObject);
|
685
732
|
rb_define_singleton_method(rbFact, "deftemplate_name", clips_environment_fact_static_deftemplate_name, 1);
|
686
733
|
rb_define_method(rbFact, "deftemplate_name", clips_environment_fact_deftemplate_name, 0);
|
687
|
-
/*
|
688
734
|
rb_define_singleton_method(rbFact, "to_h", clips_environment_fact_static_to_h, 1);
|
689
735
|
rb_define_method(rbFact, "to_h", clips_environment_fact_to_h, 0);
|
690
|
-
*/
|
691
736
|
|
692
737
|
VALUE rbInstance = rb_define_class_under(rbEnvironment, "Instance", rb_cObject);
|
693
738
|
}
|
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.9
|
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
|
@@ -367,6 +367,7 @@ homepage: https://rubygems.org/gems/clipsruby
|
|
367
367
|
licenses:
|
368
368
|
- MIT
|
369
369
|
metadata:
|
370
|
+
documentation_uri: https://github.com/mrryanjohnston/clipsruby/blob/main/README.md
|
370
371
|
source_code_uri: https://github.com/mrryanjohnston/clipsruby
|
371
372
|
post_install_message:
|
372
373
|
rdoc_options: []
|