Giter Site home page Giter Site logo

fished's Introduction

fished

Migrated to https://github.coupang.net/coupang/couplay-fished

Fish answers from rules and facts

Install

$ go get -u github.com/jonathansudibya/fished

or using dep

$ dep ensure -add github.com/jonathansudibya/fished

Structs

Rule :

type Rule struct {
	Output 			string   `json:"output"`
	Input  			[]string `json:"input"`
	Expression   	string   `json:"expression"`
	...
}

Engine:

type Engine struct {
    Facts         map[string]interface{}
	Rules         []Rule
	RuleFunctions map[string]govaluate.ExpressionFunction
	Jobs          chan int
    ...
}

Example

Please see in test file especially TestRun() function.

package main

import "github.com/jonathansudibya/fished"

func main() {
	e := fished.New(nil)
	e.SetRules([]Rule{
		Rule{
			Input: []string{"hello"},
			Output: "result_end",
			Expression: "hello == 'world'",
		}
	})
	e.SetFacts = map[string]interface{}{
		"hello": "world"
	}
	res, errs := e.Run()

	fmt.Println(res) // will result true
}

Notes

Remember it is more expensive to set new rules than to set facts.

Credits

This project is powered by

LICENSE

See LICENSE.md

fished's People

Contributors

irfannurhakim avatar jonathansudibya avatar marwahaha avatar rendyfebry avatar

Stargazers

 avatar

Watchers

 avatar

fished's Issues

A more complex test

Fine work boss @JonathanSudibya. Looking at the test, I think testing a more complex rule might illustrate the engine's capability even better. For example, a common scenario is testing a rule that contains calling an API. Here is such scenario:

{
    "input": ["pokemon_name"],
    "output": ["pokemon"],
    "rule": "getPokemon(pokemon_name)",
    "value": "???"
},
{
    "input": ["pokemon"],
    "output": ["isGoodPokemon"],
    "rule": "['dragon', 'fairy'].includes(pokemon.type)",
    "value": "true"
}

From the above sample, some questions arose:

  1. How to call an API inside the rule?
  2. How to store pokemon data fetched from the API to the output?
  3. How to store pokemon data (that is probably a struct that contains a lot of attributes?
  4. How to check array inclusion as seen in the second rule?
  5. How to handle error that we might get from calling the API?

Double execution

In current algorithm, fished will map rules to a index:
example if we have input : ["A", "B"] it will be transform into { "A": [1], "B": [1] } (assume only one rule and in index 1 in the rule arrays) at runtime if both "required parameters" are met the rule will fire. In this case because the rule is successfully verified for both of these inputs, it will be fired twice hence double execution.

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.