cerner / clara-examples Goto Github PK
View Code? Open in Web Editor NEWExample Clara Rules
License: Apache License 2.0
Example Clara Rules
License: Apache License 2.0
Hi,
I looking at the ExampleMain.java code in clara.examples.java.
It has below two lines of code
static final WorkingMemory emptyMemory = RuleLoader.loadRules("clara.examples.java.shopping");
static final String QUERY = "clara.examples.java.shopping/get-promotions";
However I don't see the rules in the java package.
Could you please add the two files mentioned in the code to the repository?
Regards,
Sundar.
Hi,
Just wanted to know if I can use the https://github.com/rbrush/clara-storm example with the latest version of clara-rules.
I see a check-in comment on the clara-examples repo that says :
"Upgrade to Clara 0.4 stream; drop Storm example for the time being."
Am particularly looking forward to a distributed working memory.
Thanks
Binita
I'm trying to test the examples in my REPL. I'm using the rules as defined in the examples but they don't seem to work as I get no output. I'm wondering if this is some sort of namespace issue.
Here is the code I'm running:
(ns clara.examples
(require [clara.examples.shopping :as shopping]
[clara.examples.validation :as validation]
[clara.examples.sensors :as sensors]
[clara.examples.durability :as durability]
[clara.examples.java.shopping :as jshopping]
[clara.rules :as r]))
(defn -main []
(println "Shopping examples:")
(shopping/run-examples)
(println)
(println "JavaBean Shopping examples from Clojure:")
(jshopping/run-examples)
(println)
(println "JavaBean Shopping examples from Java:")
(clara.examples.java.ExampleMain/main (into-array String []))
(println)
(println "Validation examples:")
(validation/run-examples)
(println)
(println "Sensor examples:")
(sensors/run-examples)
(println "Durability examples:")
(durability/run-examples))
(defn run-examples
"Function to run the above example."
[]
(println "VIP shopping example:")
;; prints "10 % :vip discount"
(-> (r/mk-session 'clara.examples.shopping) ; Load the rules.
(r/insert (shopping/->Customer :vip)
(shopping/->Order 2013 :march 20)
(shopping/->Purchase 20 :gizmo)
(shopping/->Purchase 120 :widget)) ; Insert some facts.
(r/fire-rules)
(shopping/print-discounts!))
(println "Summer special and widget promotion example:")
;; prints: "20 % :summer-special discount"
;; "Free :lunch for promotion :free-lunch-for-gizmo"
;; "Free :widget for promotion :free-widget-month"
(-> (r/mk-session 'clara.examples.shopping) ; Load the rules.
(r/insert (shopping/->Customer :vip)
(shopping/->Order 2013 :august 20)
(shopping/->Purchase 20 :gizmo)
(shopping/->Purchase 120 :widget)
(shopping/->Purchase 90 :widget)) ; Insert some facts.
(r/fire-rules)
(shopping/print-discounts!)
(shopping/print-promotions!))
nil)
If I call (-main), I get the correct output. If I call (run-examples), it get:
VIP shopping example:
Summer special and widget promotion example:
Is there some issue with inserting facts from a different namespace?
Various examples implicitly demonstrate the immutability of Clara sessions and it is alluded to, if not fully explained, at clara-rules.org. However, I've seen some confusion on the subject and think an example very narrowly targeted at demonstrating session immutability could help.
Without them, it is impossible to assess how to use this library with TDD...
This is a great example of the power of both instaparse and Clara.
Have you given any thought to how one could support end-user authoring of the DSL? It would be very cool if one could use the parser/grammar to somehow support structured editing where all possible options are shown to the user.
Steps to reproduce:
:dependencies [ ...
[org.clojure/clojurescript "0.0-2371"] ;2156 - original
...]
:plugins [[lein-cljsbuild "1.0.3"]] ;1.0.0 - original
$ git clone https://github.com/rbrush/clara-examples.git
Cloning into 'clara-examples'...
remote: Counting objects: 151, done.
remote: Total 151 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (151/151), 20.12 KiB | 0 bytes/s, done.
Resolving deltas: 100% (50/50), done.
Checking connectivity... done.
$ cd clara-examples
$ lein cljsbuild once
Compiling ClojureScript.
Compiling "resources/public/js/examples.js" from ["src/main/clojurescript"]...
Jan 25, 2015 11:09:17 PM com.google.javascript.jscomp.LoggerErrorManager println
WARNING: /Users/alanm/projects/clara-examples/target/cljsbuild-compiler-0/schema/core.js:853: WARNING - References to the global RegExp object prevents optimization of regular expressions.
schema.core.Regex = RegExp;
^
Jan 25, 2015 11:09:17 PM com.google.javascript.jscomp.LoggerErrorManager printSummary
WARNING: 0 error(s), 1 warning(s)
Successfully compiled "resources/public/js/examples.js" in 40.734713 seconds.
$ lein clean
Deleting files generated by lein-cljsbuild.
$ echo changed project.clj
changed project.clj
$ lein cljsbuild once
Compiling ClojureScript.
Compiling "resources/public/js/examples.js" from ["src/main/clojurescript"]...
Compiling "resources/public/js/examples.js" failed.
clojure.lang.ExceptionInfo: {:tag :cljs/analysis-error}
at clojure.core$ex_info.invoke(core.clj:4327)
at cljs.analyzer$error.invoke(analyzer.clj:287)
at cljs.analyzer$analyze.invoke(analyzer.clj:1571)
at cljs.analyzer$parse_ns$fn__1755$fn__1756.invoke(analyzer.clj:1642)
at cljs.analyzer$parse_ns$fn__1755.invoke(analyzer.clj:1642)
at cljs.analyzer$parse_ns.invoke(analyzer.clj:1637)
at cljs.analyzer$parse_ns.invoke(analyzer.clj:1632)
at cljs.compiler$compile_root.invoke(compiler.clj:1005)
at cljs.closure$compile_dir.invoke(closure.clj:343)
at cljs.closure$eval3071$fn__3072.invoke(closure.clj:383)
at cljs.closure$eval3006$fn__3007$G__2997__3014.invoke(closure.clj:293)
at cljs.closure$eval3058$fn__3059.invoke(closure.clj:397)
at cljs.closure$eval3006$fn__3007$G__2997__3014.invoke(closure.clj:293)
at cljsbuild.compiler.SourcePaths$fn__3269.invoke(compiler.clj:44)
at clojure.core$map$fn__4207.invoke(core.clj:2485)
at clojure.lang.LazySeq.sval(LazySeq.java:42)
at clojure.lang.LazySeq.seq(LazySeq.java:60)
at clojure.lang.RT.seq(RT.java:484)
at clojure.core$seq.invoke(core.clj:133)
at clojure.core$apply.invoke(core.clj:617)
at clojure.core$mapcat.doInvoke(core.clj:2514)
at clojure.lang.RestFn.invoke(RestFn.java:423)
at cljsbuild.compiler.SourcePaths._compile(compiler.clj:44)
at cljs.closure$build.invoke(closure.clj:962)
at cljs.closure$build.invoke(closure.clj:928)
at cljsbuild.compiler$compile_cljs$fn__3280.invoke(compiler.clj:58)
at cljsbuild.compiler$compile_cljs.invoke(compiler.clj:57)
at cljsbuild.compiler$run_compiler.invoke(compiler.clj:159)
at user$eval3406$iter__3424__3428$fn__3429$fn__3441.invoke(form-init1116806015832199295.clj:1)
at user$eval3406$iter__3424__3428$fn__3429.invoke(form-init1116806015832199295.clj:1)
at clojure.lang.LazySeq.sval(LazySeq.java:42)
at clojure.lang.LazySeq.seq(LazySeq.java:60)
at clojure.lang.RT.seq(RT.java:484)
at clojure.core$seq.invoke(core.clj:133)
at clojure.core$dorun.invoke(core.clj:2780)
at clojure.core$doall.invoke(core.clj:2796)
at user$eval3406.invoke(form-init1116806015832199295.clj:1)
at clojure.lang.Compiler.eval(Compiler.java:6619)
at clojure.lang.Compiler.eval(Compiler.java:6609)
at clojure.lang.Compiler.load(Compiler.java:7064)
at clojure.lang.Compiler.loadFile(Compiler.java:7020)
at clojure.main$load_script.invoke(main.clj:294)
at clojure.main$init_opt.invoke(main.clj:299)
at clojure.main$initialize.invoke(main.clj:327)
at clojure.main$null_opt.invoke(main.clj:362)
at clojure.main$main.doInvoke(main.clj:440)
at clojure.lang.RestFn.invoke(RestFn.java:421)
at clojure.lang.Var.invoke(Var.java:419)
at clojure.lang.AFn.applyToHelper(AFn.java:163)
at clojure.lang.Var.applyTo(Var.java:532)
at clojure.main.main(main.java:37)
Caused by: java.lang.NullPointerException
at cljs.core$import_macros$fn__3479.invoke(core.clj:49)
at clojure.core$map$fn__4207.invoke(core.clj:2485)
at clojure.lang.LazySeq.sval(LazySeq.java:42)
at clojure.lang.LazySeq.seq(LazySeq.java:60)
at clojure.lang.RT.seq(RT.java:484)
at clojure.core$seq.invoke(core.clj:133)
at clojure.core$map$fn__4211.invoke(core.clj:2490)
at clojure.lang.LazySeq.sval(LazySeq.java:42)
at clojure.lang.LazySeq.seq(LazySeq.java:67)
at clojure.lang.RT.seq(RT.java:484)
at clojure.core$seq.invoke(core.clj:133)
at clojure.core$concat$cat__3925$fn__3926.invoke(core.clj:687)
at clojure.lang.LazySeq.sval(LazySeq.java:42)
at clojure.lang.LazySeq.seq(LazySeq.java:60)
at clojure.lang.Cons.next(Cons.java:39)
at clojure.lang.RT.next(RT.java:598)
at clojure.lang.Compiler.eval(Compiler.java:6606)
at clojure.lang.Compiler.load(Compiler.java:7064)
at clojure.lang.RT.loadResourceScript(RT.java:370)
at clojure.lang.RT.loadResourceScript(RT.java:361)
at clojure.lang.RT.load(RT.java:440)
at clojure.lang.RT.load(RT.java:411)
at clojure.core$load$fn__5018.invoke(core.clj:5530)
at clojure.core$load.doInvoke(core.clj:5529)
at clojure.lang.RestFn.invoke(RestFn.java:408)
at cljs.analyzer$load_core.invoke(analyzer.clj:229)
at cljs.analyzer$analyze$fn__1738.invoke(analyzer.clj:1577)
at cljs.analyzer$analyze.invoke(analyzer.clj:1573)
... 48 more
Subprocess failed
An example demonstrating session inspection would be helpful. Things to target:
This example could then be linked from the page on session inspection in the docs. Some high-level discussion there is appropriate, but particularly when considering how truth maintenance impacts session inspection the details matter. While the information is on the docstrings that isn't necessarily the most accessible location. The changes in oracle-samples/clara-rules#386 increase the need for this.
Per a comment on the clara-rules google group,
Exception in thread "main" java.io.FileNotFoundException: Could not locate clojure/tools/nrepl/middleware/interruptible_eval__init.class or clojure/tools/nrepl/middleware/interruptible_eval.clj on classpath. Please check that namespaces with dashes use underscores in the Clojure file name., compiling:(cemerick/austin/repls.clj:1:1)
This is due to an undeclared dependency on clojure/tools.nrpel, this dependency was pulled transitively via leiningen prior to version 2.8.2, however that is no longer the case.
We've had a significant amount of confusion on truth maintenance, judging from both conversations on the Slack channel and offline conversations within Cerner with developers writing rules. A concrete example that uses it might help clarify its behavior. We could link to such an example from http://www.clara-rules.org/docs/truthmaint/
The example for durability is broken due to using the old API that we have completely replaced with oracle-samples/clara-rules@f7a0773#diff-ce5bba4c033cda865447745807a as discussed at oracle-samples/clara-rules#198
We should add an example that uses the new API. Until we create such an example I suggest that we remove the existing example since the new API is completely different and the old example merely misinforms. Any objections?
Hi,
Im getting started with Clara Rules. I have Clojure 1.10.3 and java version "11.0.11" 2021-04-20 LTS, installed in my Windows. I'm getting attached error when trying to run clara-examples project. Steps which I followed are
Could you please help.
error.txt
Regards,
Sundar.
Due to the inactivity of this project for over 1 year, this project is marked to be archived at end of January 2024. Previously release assets will be untouched, but support will cease for this project going forward. If anyone has any reasons this project should not be archived, please comment.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.