Coder Social home page Coder Social logo

andygeiss / diego Goto Github PK

View Code? Open in Web Editor NEW
6.0 1.0 3.0 117 KB

DIEGO is a data driven, forward-chaining, rule-based expert system written from scratch.

License: MIT License

Go 100.00%
go golang inference-engine forward-chaining rules concepts facts conditions

diego's Introduction

DIEGO - A Data Driven Inference Engine written in GO

Go Report Card

DIEGO is a data driven, forward-chaining, rule-based expert system written from scratch.

Overview

An expert system usually consists of a Knowledge Base, an Inference Engine and the User Interface.

  • A Knowledge Base is a collection of different concepts with its facts and rules of a specific problem domain.
  • An Inference Engine uses a top-down method to take facts as they become available and apply rules to draw conclusions.
  • The User Interface uses an Explanation facility to explain the reasoning process to the user.
Table of Contents

Installation

From Source

go get -u github.com/andygeiss/diego

Usage

Example Rules

IF      A   (the "traffic light" is green)
THEN    X   (the action is "go")

IF      B   (the "traffic light" is red)
THEN    Y   (the action is "stop")

This Concept could be defined as:

concept := []*inference.Concept{
    &inference.Concept{
        Name:  "Example 1",
        Facts: []string{},
        Rules: []*inference.Rule{
            &inference.Rule{
                Conditions:  []string{"A"},
                Conclusions: []string{"X"},
            },
            &inference.Rule{
                Conditions:  []string{"B"},
                Conclusions: []string{"Y"},
            },
        },
    },
}

Example Explanation

The conclusion "X" maybe is not obvious for the user of the expert system. Thus a Explanation facility is used to map different questions which its option to the facts, which its hidden from the users eye.

survey := return []*explanation.Survey{
    &explanation.Survey{
        Name: "Example 1",
        Questions: []*explanation.Question{
            &explanation.Question{
                Prompt: "The traffic light is?",
                Options: []*explanation.Option{
                    &explanation.Option{
                        Name:  "green",
                        Value: "A",
                    },
                    &explanation.Option{
                        Name:  "red",
                        Value: "B",
                    },
                },
            },
        },
    },
}

See the testdata directory for more examples.

import (
	expRepos "github.com/andygeiss/diego/pkg/explanation/repositories"
	"github.com/andygeiss/diego/pkg/inference/engines"
	infRepos "github.com/andygeiss/diego/pkg/inference/repositories"
	"github.com/andygeiss/diego/pkg/survey/services"
)

func main() {
    // Initialize the repositories by using JSON-files.
    expRepo := expRepos.NewFileRepository("../../../testdata/explanation.json")
    infRepo := infRepos.NewFileRepository("../../../testdata/inference.json")
    // Configure the engine to use a specific survey by name.
    engine := engines.NewDefaultEngine("SURVEY NAME", infRepo)
    // Combine the explanation repository and inference engine.
    service := services.NewDefaultService(expRepo, engine)
    // Get the facts by setting a specific condition.
    facts, err := service.GetResultsByFacts([]string{"#Q1 = 1"})
    ...    
}

diego's People

Contributors

andygeiss avatar imgbotapp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

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.