Giter VIP home page Giter VIP logo

clara-examples's Introduction

About

This project contains example use clara-rules, a Clojure-based rule engine. It is primarily for documentation and examples for those learning Clara.

Usage

The Clojure examples can be run via the Leiningen build system. Simply check out this project and run the following from its root directory on a system where Leiningen is installed:

lein run -m clara.examples

To run the ClojureScript examples, compile the code with lein compile or lein cljsbuild once, and then open the resources/public/index.html file in a browser. This will run the shopping example in ClojureScript and display the result.

Building

Like clara-rules, this example project is built, tested, and deployed using Leiningen.

Communication

Questions can be posted to the Clara Rules Google Group or the Slack channel.

Contributing

See CONTRIBUTING.md

LICENSE

Copyright 2016 Cerner Innovation, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

clara-examples's People

Contributors

williamparker avatar rbrush avatar

Stargazers

Eliezer Foster avatar Erich Ocean avatar Maciej Łotysz avatar seeumara avatar Cesar Marinho avatar  avatar  avatar Shawn Zhang avatar Adam Harris avatar Thomas G Henry avatar Elias Levy avatar ebigram avatar  avatar Justin Greisiger Frost avatar Orlin M Bozhinov avatar  avatar Kamil Adam avatar Matheus Cunha avatar koma avatar Eric avatar Lucas Severo avatar Daniele avatar endrebak.ada avatar Mikko Karjalainen avatar Matt Pettis avatar 洪盟翔 avatar Muhammad Ridho avatar Raphaël Saunier avatar Narendra Joshi avatar Serapheim Dimitropoulos avatar Charlotte Fereday avatar Ronen avatar Alessandro Siletto avatar Vic avatar zhongxiao avatar Jody Alford avatar Ticean Bennett avatar  avatar  avatar Steffen Dienst avatar justthefracts avatar Benjamin Chi avatar Kenji Nakamura avatar Rod Gaither avatar  avatar Robert Medeiros avatar Veha Suwatphisankij avatar  avatar  avatar Thinh P. Tran avatar Burin Choomnuan avatar David Rupp avatar Petrus Theron avatar Naresh Rayapati avatar yāλu avatar Alex Dixon avatar Ray McDermott  avatar Sergey Grankin avatar Carl Steinbach avatar Mike Rodriguez avatar Marc Christophe avatar  avatar Novak Boškov avatar stephen avatar Devin Walters avatar Brian Zhou avatar Jelle Akkerman avatar Mohammad Reza Taesiri avatar Boris Kourtoukov avatar Bahadir Cambel avatar Nilesh Ashra avatar Michał Marczyk avatar  avatar Bruno Vecchi avatar Stefan Bleibinhaus avatar Koji Yusa avatar Pascal Hirsch avatar Richard Wofford avatar Richard Davies avatar Martin Clausen avatar Peter Rudenko avatar  avatar Ceri Storey avatar  avatar Ryan Kohl avatar Don Jackson avatar James Thornton avatar Gordon Stratton avatar Nils Grünwald avatar

Watchers

Martin Clausen avatar Nathaniel Bomberger avatar  avatar James Cloos avatar Nilton Lessa avatar Mike Rodriguez avatar Matt Pettis avatar Ethan Christian avatar Naresh Rayapati avatar  avatar Deus Eks avatar Kamil Adam avatar  avatar

clara-examples's Issues

Add tests

Without them, it is impossible to assess how to use this library with TDD...

Unable to run Clara Examples

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

  1. I cloned the repository from https://github.com/cerner/clara-examples
  2. Followed the installation command at https://leiningen.org/
  3. Run "lein run -m clara.examples"
  4. Getting the attached error.

Could you please help.
error.txt

Regards,
Sundar.

Add example demonstrating usage of session inspection

An example demonstrating session inspection would be helpful. Things to target:

  • The purposes of individual keys.
  • Examples of using session inspection in debugging.
  • When the use of truth maintenance impacts session inspection.

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.

Instaparse example

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.

archive this project

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.

Issue calling examples from the REPL

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?

Example fails to compile when clojurescript and lein-cljsbuild versions are upgraded

Steps to reproduce:

  1. Clone examples repo
  2. Change to the following dependencies:
:dependencies [ ...
[org.clojure/clojurescript "0.0-2371"] ;2156 - original
...]

:plugins [[lein-cljsbuild "1.0.3"]] ;1.0.0 - original
  1. Expected: Successful compile
  2. Observed: NullPointerException - see below

$ 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

Clara-examples Java example missing the rules in the package

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.

Add example of rules session immutability

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.

Missing dependency on clojure.tools.nrepl

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.