Code Monkey home page Code Monkey logo

fact-engine's Introduction

Fact Engine

A simple fact storage and querying system for storing and matching facts.

Table of Contents

Introduction

FactEngine is a straightforward fact storage and querying system that enables users to store facts and then query or match against them. This guide will walk you through the basic usage of the FactEngine.

Getting Started

Using IEx Session

  1. Navigate to your project directory in your terminal.
  2. Start an IEx session with your project using:
    iex -S mix
    

Initialization

To start the FactEngine, execute:

FactEngine.start()

Inputting Facts

To input facts into the engine, use:

FactEngine.input("fact_name(value1, value2)")

For example:

FactEngine.input("likes(alex, sam)")
FactEngine.input("likes(sam, sam)")
FactEngine.input("dislikes(sam, alex)")
FactEngine.input("is_a_cat(biscuit)")
FactEngine.input("is_a_cat(beetlejuice)")

Querying Facts

You can query facts using variables (X, Y). For example, if you have inputted the fact likes(alex, sam), you can query:

FactEngine.query_facts("likes(X, sam)")

Expected output:
[["alex"], ["sam"]]

if you have inputted the fact likes(sam, sam), you can query:

FactEngine.query_facts("likes(Y, Y)")

Expected output:
[["sam"]]

you can also query the like facts likes(X, Y) Expected output:

FactEngine.query_facts("likes(X, Y)")

[[%{"X" => "alex", "Y" => "sam"}], [%{"X" => "sam", "Y" => "sam"}]]

if you have inputted the fact is_a_cat(x), you can query:

FactEngine.query_facts("is_a_cat(x)")

[["biscuit"], ["beetlejuice"]]

Processing a .txt File

You can also process a .txt file that contains a list of inputs and queries. The format of the file should be:

INPUT fact_name1(value1, value2)
INPUT fact_name2(value1, value2)
...
QUERY your_query
...

For example, fact_file.txt might contain:

INPUT likes(alex, sam)
INPUT likes (sam, sam)
QUERY likes(X, sam)

To process the file, use an IEx session with your project using:

iex -S mix
FactEngine.process_file("path_to_your_file.txt")

The results of the queries will be printed to the console.

Processing a .txt File Output

When you process a file or make a query in an IEx session, the results will be printed to the console. For file processing, the output for each query in the file will be displayed sequentially.

The expected output for fact_file.txt with data:

INPUT likes(alex, sam)
INPUT likes (sam, sam)
QUERY likes(X, sam)

Expected output:
Result of query likes (X, sam): [["alex"], ["sam"]]

fact-engine's People

Contributors

zzeroyzz 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.