styx

package module
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: May 12, 2020 License: MIT Imports: 19 Imported by: 2 modules, 6 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

styx

https://pkg.go.dev/github.com/underlay/styx

Styx is an experimental RDF database that works like a key/value store, where the keys are RDF IRI terms and the values are RDF datasets. It also exposes a subgraph iterator interface that lets you iterate over all the subgraphs of the database that match a given pattern.

You can use Styx as a Go module by importing github.com/underlay/styx. Alternatively, you can run in the background by building the package github.com/underlay/styx/api:

% cd api
% go build -o styx
% export STYX_PREFIX=http://example.com/
% ./styx

This will start an API server exposing get/set/delete via GET, PUT, and DELETE requests, and subgraph iteration over a websocket RPC interface.

Set the Styx database location by setting the STYX_PATH evironment variable. It will default to /tmp/styx.

Set the API port with STYX_PORT. It will default to 8086.

You also need to set the STYX_PREFIX variable to a string like http://... that all of the keys you'll set will start with. For example, setting STYX_PREFIX=http://example.com/ means that you'll be able to insert datasets with keys beginning with http://example.com/. It will default to http://localhost:${STYX_PORT}. You don't need this if you only ever use the default dataset.

Documentation

Index

Constants

View Source
const Algorithm = "URDNA2015"

Algorithm has to be URDNA2015

View Source
const DatasetPrefix = byte(':')

DatasetPrefix keys store the datasets in the database

View Source
const Format = "application/n-quads"

Format has to be application/n-quads

View Source
const IDToValuePrefix = byte('<')

IDToValuePrefix keys translate uint64 ids to string IRIs

View Source
const SequenceBandwidth = 512

SequenceBandwidth sets the lease block size of the ID counter

View Source
const UnaryPrefix = byte('u')

UnaryPrefix keys translate ld.Node values to uint64 ids

View Source
const ValueToIDPrefix = byte('>')

ValueToIDPrefix keys translate string IRIs to uint64 ids

Variables

View Source
var BinaryPrefixes = [6]byte{'i', 'j', 'k', 'l', 'm', 'n'}

BinaryPrefixes address the binary indices

View Source
var ErrEmptyInterset = errors.New("Empty intersection")

ErrEmptyInterset indicates that a constraint set had an empty join

View Source
var ErrEndOfSolutions = errors.New("No more solutions")

ErrEndOfSolutions is a generic out-of-reuslts signal

View Source
var ErrInvalidDomain = errors.New("Invalid domain")

ErrInvalidDomain means that provided domain included blank nodes that were not in the query

View Source
var ErrInvalidIndex = errors.New("Invalid index")

ErrInvalidIndex means that provided index included blank nodes or that it was too long

View Source
var ErrInvalidInput = errors.New("Invalid dataset")

ErrInvalidInput indicates that a given dataset was invalid

View Source
var ErrInvalidTerm = errors.New("Invalid term")

ErrInvalidTerm indicates that the given term was of an unexpected type

View Source
var ErrNotFound = errors.New("Not found")

ErrNotFound indicates that the given node was syntactically valid, but not present in the database.

View Source
var ErrParseQuads = errors.New("Error parsing quads from Badger datastore")

ErrParseQuads indicates that a TSV of quads could not be parsed

View Source
var ErrTagScheme = errors.New("URI did not validate the tag scheme")

ErrTagScheme indicates that a given URI did not validate the database's tag scheme

View Source
var SequenceKey = []byte("#")

SequenceKey to store the id counter

View Source
var TernaryPrefixes = [3]byte{'a', 'b', 'c'}

TernaryPrefixes address the ternary indices

Functions

func ToRDFDataset added in v0.2.0

func ToRDFDataset(quads []*rdf.Quad) *ld.RDFDataset

ToRDFDataset transforms the slice of quads into an *ld.RDFDataset

Types

type Config added in v0.2.0

type Config struct {
	TagScheme  TagScheme
	Dictionary DictionaryFactory
	QuadStore  QuadStore
}

Config contains the initialization options passed to Styx

type Dictionary added in v0.2.0

type Dictionary interface {
	GetID(term rdf.Term, origin rdf.Term) (ID, error)
	GetTerm(id ID, origin rdf.Term) (rdf.Term, error)
	Commit() error
}

A Dictionary is a scheme for serializing terms to and from strings

type DictionaryFactory added in v0.2.0

type DictionaryFactory interface {
	Open(update bool) Dictionary
	Close() error
}

A DictionaryFactory instantiates dictionaries

var StringDictionary DictionaryFactory = stringDictionary{}

StringDictionary is a dictionary that that serializes terms to and from their full N-Quads string representation

func MakeIriDictionary added in v0.3.0

func MakeIriDictionary(tags TagScheme, db *badger.DB) (DictionaryFactory, error)

MakeIriDictionary returns a new dictionary factory that compacts IRIs with base64 IDs

type ID added in v0.2.0

type ID string

ID is the type of terms of the index tuples

var NIL ID = ""

NIL is empty ID

type Iterator

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

An Iterator exposes Next and Seek operations

func (*Iterator) Close

func (iter *Iterator) Close()

Close the iterator

func (*Iterator) Collect

func (iter *Iterator) Collect() ([][]rdf.Term, error)

Collect calls Next(nil) on the iterator until there are no more solutions, and returns all the results in a slice.

func (*Iterator) Domain

func (iter *Iterator) Domain() []rdf.Term

Domain returns the total ordering of variables used by the iterator

func (*Iterator) Get

func (iter *Iterator) Get(node rdf.Term) rdf.Term

Get the value for a particular blank node

func (*Iterator) Graph

func (iter *Iterator) Graph() []*rdf.Quad

Graph returns a []*rdfjs.Quad representation of the iterator's current value

func (*Iterator) Index

func (iter *Iterator) Index() []rdf.Term

Index returns the iterator's current value as an ordered slice of ld.Nodes

func (*Iterator) Len

func (iter *Iterator) Len() int

Sort interface functions

func (*Iterator) Less

func (iter *Iterator) Less(a, b int) bool

TODO: put more thought into the sorting heuristic. Right now the variables are sorted their norm: in increasing order of their length-normalized sum of the squares of the counts of all their constraints (of any degree).

func (*Iterator) Log

func (iter *Iterator) Log()

Log pretty-prints the iterator

func (*Iterator) Next

func (iter *Iterator) Next(node rdf.Term) ([]rdf.Term, error)

Next advances the iterator to the next result that differs in the given node. If nil is passed, the last node in the domain is used.

func (*Iterator) Prov added in v0.2.2

func (iter *Iterator) Prov() ([][]rdf.Term, error)

Prov returns a matrix of graph sources

func (*Iterator) Seek

func (iter *Iterator) Seek(index []rdf.Term) (err error)

Seek advances the iterator to the first result greater than or equal to the given index path

func (*Iterator) String

func (iter *Iterator) String() string

func (*Iterator) Swap

func (iter *Iterator) Swap(a, b int)

type Permutation

type Permutation uint8

Permutation is a permutation of a triple

const (
	// SPO is the subject-predicate-object permutation
	SPO Permutation = iota
	// POS is the predicate-object-subject permutation
	POS
	// OSP is the object-subject-predicate permutation
	OSP
	// SOP is the subject-object-predicate permutation
	SOP
	// PSO is the predicate-subject-object permutation
	PSO
	// OPS is the object-predicate-subject permutation
	OPS
)

type QuadStore added in v0.2.0

type QuadStore interface {
	Set(id ID, quads [][4]ID) error
	Get(id ID) ([][4]ID, error)
	Delete(id ID) error
	List(id ID) interface {
		Next() (id ID, valid bool)
		Close()
	}
}

QuadStore is an interface for things that can persist datasets

func MakeBadgerStore added in v0.2.0

func MakeBadgerStore(db *badger.DB) QuadStore

MakeBadgerStore creates new badger quad store

func MakeEmptyStore added in v0.3.0

func MakeEmptyStore() QuadStore

MakeEmptyStore returns a quadstore that doesn't store any quads

func MakeMemoryStore added in v0.2.0

func MakeMemoryStore() QuadStore

MakeMemoryStore returns an in-memory quad store

type Statement

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

A Statement is a reference to a specific quad in a specific dataset

func (*Statement) Graph

func (statement *Statement) Graph(dictionary Dictionary) rdf.Term

Graph returns the URI for the statement's graph

func (*Statement) String added in v0.2.0

func (statement *Statement) String() string

func (*Statement) URI

func (statement *Statement) URI(dictionary Dictionary) string

URI returns the URI for the statement using path syntax

type Store

type Store struct {
	Badger *badger.DB
	Config *Config
}

A Store is a database instance

func NewMemoryStore added in v0.3.0

func NewMemoryStore(config *Config) (*Store, error)

NewMemoryStore opens a styx database in memory

func NewStore

func NewStore(config *Config, db *badger.DB) (*Store, error)

NewStore opens a styx database

func (*Store) Close

func (s *Store) Close() (err error)

Close the database

func (*Store) Delete

func (s *Store) Delete(node rdf.Term) (err error)

Delete a dataset from the database

func (*Store) Get

func (s *Store) Get(node rdf.Term) ([]*rdf.Quad, error)

Get a dataset from the database

func (*Store) List

func (s *Store) List(node rdf.Term) interface {
	Close()
	Next() rdf.Term
}

List lists the datasets in the database

func (*Store) Log

func (s *Store) Log()

Log will print the *entire database contents* to log

func (*Store) Query

func (s *Store) Query(pattern []*rdf.Quad, domain []rdf.Term, index []rdf.Term) (*Iterator, error)

Query satisfies the Styx interface

func (*Store) QueryJSONLD

func (s *Store) QueryJSONLD(query interface{}) (*Iterator, error)

QueryJSONLD exposes a JSON-LD query interface

func (*Store) Set

func (s *Store) Set(node rdf.Term, dataset []*rdf.Quad) (err error)

Set is the entrypoint to inserting stuff

func (*Store) SetJSONLD

func (s *Store) SetJSONLD(uri string, input interface{}, canonize bool) error

SetJSONLD sets a JSON-LD document

type TagScheme

type TagScheme interface {
	Test(uri string) bool
	Parse(uri string) (tag string, fragment string)
}

A TagScheme is an interface for testing whether a given URI is a dataset URI or not

func NewPrefixTagScheme

func NewPrefixTagScheme(prefix string) TagScheme

NewPrefixTagScheme creates a tag scheme that tests for the given prefix

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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