gotalog

package module
v0.0.0-...-3ebd540 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 21, 2020 License: GPL-3.0 Imports: 7 Imported by: 0

README

gotalog

Gotalog is a Golang implementation of datalog, a port of MITRE corporation's Lua implementation. Gotalog is licensed under the GPL; see LICENSE.

Package

Gotalog comes in two parts; a port of the search strategy in datalog.go, and a proof-of-concept implementation of a number of databases with different runtime behaviors.

Outside of database constructors, the public symbols are defined in interface.go

Usage

Gotalog can be interacted with either through text, or by directly constructing commands and passing them into Apply().

We provide three database implementations: an in-memory database, a log-backed database, and a threadsafe implementation.

The cli submodule has a minimal demonstration of use of the parsing API.

Performance

In some informal tests using large datalog problems from the web (see the files in tests/), gotalog's performance is better than the MITRE implementation (running using vanilla Lua, not luajit) by around 20%. At peak, its memory consumption is several times that of the MITRE implementation.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Scan

func Scan(input io.Reader) (chan DatalogCommand, chan error)

Scan iterates through a io reader, throwing commands into a channel as they are read from the reader.

func ToString

func ToString(results []Result) string

ToString reformats results for display. Coincidentally, it also generates valid datalog.

Types

type CommandType

type CommandType int

CommandType differentiates different possible datalog commands.

const (
	// Assert - this fact will be added to a database upon application.
	Assert CommandType = iota
	// Query - this command will return the results of querying a database
	// upon application.
	Query
	// Retract - remove a fact from a database.
	Retract
)

type Database

type Database interface {
	// contains filtered or unexported methods
}

Database holds and generates state for asserted facts and rules. We're mirroring the original implementation's use of 'database'. Unfortunately, this was used to describe a number of different uses for tables mapping From some string id to some type in the original implementation.

func NewDiskLogDB

func NewDiskLogDB(rw io.ReadWriter, backing Database) (Database, error)

NewDiskLogDB returns a database initialized from an io.ReadWritter. All assertions and retractions on this databased will be persisted in the log.

func NewLockingDatabase

func NewLockingDatabase() Database

NewLockingDatabase constructs a new in-memory database with simple locking behavior.

func NewMemDatabase

func NewMemDatabase() Database

NewMemDatabase constructs a new in-memory database.

type DatalogCommand

type DatalogCommand struct {
	Head        LiteralDefinition
	Body        []LiteralDefinition
	CommandType CommandType
}

DatalogCommand a command to mutate or query a gotalog database.

func Parse

func Parse(input io.Reader) ([]DatalogCommand, error)

Parse consumes a reader, producing a slice of datalogCommands.

type LiteralDefinition

type LiteralDefinition struct {
	PredicateName string
	Terms         []Term
}

LiteralDefinition defines a literal PredicateName(Term0, Term1, ...).

type Result

type Result struct {
	Name    string
	Arity   int
	Answers [][]Term
}

Result contain deduced facts that match a query.

func Apply

func Apply(cmd DatalogCommand, db Database) (*Result, error)

Apply applies a single command. TODO: do we really need this and ApplyAll?

func ApplyAll

func ApplyAll(cmds []DatalogCommand, db Database) (results []Result, err error)

ApplyAll iterates over a slice of commands, executes each in turn on a provided database, and accumulates and then returns results.

type Term

type Term struct {
	// contains filtered or unexported fields
}

Term contains either a variable or a constant.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL