npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@radiantone/inferencegraph

v0.0.2

Published

A knowledge graph based forward chain inferencing engine in typescript/node.

Downloads

8

Readme

inferencegraph

A knowledge graph based forward chain inferencing engine in typescript/node.

Overview

Notes

This is 'in development' and is only a working draft at the moment, not a complete system. Updates will come regularly.

Install

$ npm i

Build

$ npm run build

Run

$ npm run test

Design Goals

  • Primitive typed fact values (string, boolean, number, object)
  • Operator evaluation (=,!=,>,<,true,false)
  • Cycle detection
  • Composition based. Can create separate fact graphs and add them to a knowledge graph at different times
  • Clean. Simple. Easy to understand
  • Extensible
  • Uses Classes. Typescript
  • Powerful rules with conditions (when), assertions, retractions and functional side-effects (do's)
  • Automatic planning. Functional attributes of rules are built into a functional "plan" during inference chaining. Once the engine has completed its inferences, an executable (and ordered) plan is returned that executes asynchronously returning Promises.
  • Ability to solve inferencing logic problems. A more detailed logic problem example will be forthcoming.
  • Low memory consumption, simple data structures

Classes

Factoids

An untyped data container

new Factoid({
        'name': 'fact1',
        'value': 'value0'
    })

Facts

A typed data container used with Knowledge Bases

const newFact = new Fact(new Factoid({
    'name':'fact1',
    'value':'value1'
}))

Rules

Rule is a container for conditions, assertions and functions associated with facts that are evaluated by the inference engine. Each rule evaluates to either true or false based on it's when conditions, which all must be true for the rule to fire.

 new Rule({
        name: "rule2",
        when: [
            {
            name:'factB',
            value: 'valueB',
            operator: '='
        },
            {
            name:'fact3',
            value: 6,
            operator: '<'
        }],
        retract:[],
        fire:[],
        do:[],
        assert: [{
            name:'fact4',
            value: "I'm done!"
        },{
            name:'fact1',
            value: "value1"
        }]
    })

KnowledgeBase

KnowledgeBase is a container for a collection of facts and operations on them

const facts = [
    new Factoid({
        'name': 'fact1',
        'value': 'value0'
    }),
    new Factoid({
        'name': 'fact2',
        'value': 'value2'
    }),
    new Factoid({
        'name': 'factB',
        'value': 'valueB'
    })
]

const kb = new KnowledgeBase()
kb.assertFacts(facts, true);

Graph

Graph is a container for rules

const graph = new Graph([
    new Rule({
        name: "rule1",
        when: [{
            name: 'fact1',
            value: 'value1',
            operator: '='
        }],
        do:[(function() {
            console.log("DO: fact1 is value1!")
        })],
        retract:[],
        fire:[],
        assert: [{
            name:'fact2',
            value: 'Finished!'
        }]
    }),
    new Rule({
        name: "rule2",
        when: [{
            name:'fact2',
            value: 'Finished!',
            operator: '='
        }],
        retract:[],
        fire:[],
        do:[(function() {
            console.log("DO: fact2 is Finished!")
        })],
        assert: [{
            name:'fact3',
            value: 5
        }]
    })
]);

KnowledgeGraph

KnowledgeGraph is a container for graphs

const kg = new KnowledgeGraph(kb)
kg.addGraph(graph)

Brain

Brain is a container for knowledge graphs and high-level API over them

const brain = new Brain(kg, true);

const newFact = new Fact(new Factoid({
    'name':'fact1',
    'value':'value1'
}))

var plan = [];

// Infer a plan stemming from this fact assertion
brain.assertFact(newFact, plan);

console.log("PLAN:",plan);

plan.forEach( func => {
    func();  // Execute plan functions
})