quad

package
v0.7.4-2 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2018 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package quad defines quad and triple handling.

Index

Constants

View Source
const HashSize = sha1.Size

HashSize is a size of the slice, returned by HashOf.

Variables

View Source
var (
	ErrInvalid    = errors.New("invalid N-Quad")
	ErrIncomplete = errors.New("incomplete N-Quad")
)
View Source
var DefaultBatch = 10000

Functions

func Copy added in v0.6.1

func Copy(dst Writer, src Reader) (n int, err error)

Copy will copy all quads from src to dst. It returns copied quads count and an error, if it failed.

Copy will try to cast dst to BatchWriter and will switch to CopyBatch implementation in case of success.

func CopyBatch added in v0.6.1

func CopyBatch(dst BatchWriter, src Reader, batchSize int) (cnt int, err error)

CopyBatch will copy all quads from src to dst in a batches of batchSize. It returns copied quads count and an error, if it failed.

If batchSize <= 0 default batch size will be used.

func HashOf added in v0.6.0

func HashOf(v Value) []byte

HashOf calculates a hash of value v.

func HashTo added in v0.6.0

func HashTo(v Value, p []byte)

HashTo calculates a hash of value v, storing it in a slice p.

func IsValidValue added in v0.7.0

func IsValidValue(v Value) bool

func NativeOf added in v0.6.0

func NativeOf(v Value) interface{}

NativeOf safely call v.Native, returning nil in case of nil Value.

func RegisterFormat added in v0.6.1

func RegisterFormat(f Format)

RegisterFormat registers a new quad-file format.

func RegisterStringConversion added in v0.6.0

func RegisterStringConversion(dataType IRI, fnc StringConversion)

RegisterStringConversion will register an automatic conversion of TypedString values with provided type to a native equivalent such as Int, Time, etc.

If fnc is nil, automatic conversion from selected type will be removed.

func StringOf added in v0.6.0

func StringOf(v Value) string

StringOf safely call v.String, returning empty string in case of nil Value.

func ToString added in v0.7.0

func ToString(v Value) string

ToString casts a values to String or falls back to StringOf.

Types

type BNode added in v0.6.0

type BNode string

BNode is an RDF Blank Node (ex: _:name).

func RandomBlankNode added in v0.6.1

func RandomBlankNode() BNode

RandomBlankNode returns a randomly generated Blank Node.

func (BNode) GoString added in v0.7.0

func (s BNode) GoString() string

func (BNode) Native added in v0.6.0

func (s BNode) Native() interface{}

func (BNode) String added in v0.6.0

func (s BNode) String() string

type BatchReader added in v0.6.1

type BatchReader interface {
	ReadQuads(buf []Quad) (int, error)
}

BatchReader is an interface for reading quads in batches.

ReadQuads reads at most len(buf) quads into buf. It returns number of quads that were read and an error. It returns an io.EOF if there is no more quads to read.

type BatchWriter added in v0.6.1

type BatchWriter interface {
	WriteQuads(buf []Quad) (int, error)
}

BatchWriter is an interface for writing quads in batches.

WriteQuads returns a number of quads that where written and an error, if any.

type Bool added in v0.6.0

type Bool bool

Bool is a native wrapper for bool type.

It uses NQuad notation similar to TypedString.

func (Bool) Native added in v0.6.0

func (s Bool) Native() interface{}

func (Bool) String added in v0.6.0

func (s Bool) String() string

func (Bool) TypedString added in v0.6.1

func (s Bool) TypedString() TypedString

type ByQuadString added in v0.6.0

type ByQuadString []Quad

func (ByQuadString) Len added in v0.6.0

func (o ByQuadString) Len() int

func (ByQuadString) Less added in v0.6.0

func (o ByQuadString) Less(i, j int) bool

func (ByQuadString) Swap added in v0.6.0

func (o ByQuadString) Swap(i, j int)

type ByValueString added in v0.6.0

type ByValueString []Value

func (ByValueString) Len added in v0.6.0

func (o ByValueString) Len() int

func (ByValueString) Less added in v0.6.0

func (o ByValueString) Less(i, j int) bool

func (ByValueString) Swap added in v0.6.0

func (o ByValueString) Swap(i, j int)

type Direction

type Direction byte

Direction specifies an edge's type.

const (
	Any Direction = iota
	Subject
	Predicate
	Object
	Label
)

List of the valid directions of a quad.

func (Direction) GoString added in v0.7.0

func (d Direction) GoString() string

func (Direction) Prefix

func (d Direction) Prefix() byte

func (Direction) String

func (d Direction) String() string

type Equaler added in v0.6.0

type Equaler interface {
	Equal(v Value) bool
}

Equaler interface is implemented by values, that needs a special equality check.

type Float added in v0.6.0

type Float float64

Float is a native wrapper for float64 type.

It uses NQuad notation similar to TypedString.

func (Float) Native added in v0.6.0

func (s Float) Native() interface{}

func (Float) String added in v0.6.0

func (s Float) String() string

func (Float) TypedString added in v0.6.1

func (s Float) TypedString() TypedString

type Format added in v0.6.1

type Format struct {
	// Name is a short format name used as identifier for RegisterFormat.
	Name string
	// Ext is a list of file extensions, allowed for file format. Can be used to detect file format, given a path.
	Ext []string
	// Mime is a list of MIME (content) types, allowed for file format. Can be used in HTTP request/responses.
	Mime []string
	// Reader is a function for creating format reader, that reads serialized data from io.Reader.
	Reader func(io.Reader) ReadCloser
	// Writer is a function for creating format writer, that streams serialized data to io.Writer.
	Writer func(io.Writer) WriteCloser
	// Binary is set to true if format is not human-readable.
	Binary bool
	// MarshalValue encodes one value in specific a format.
	MarshalValue func(v Value) ([]byte, error)
	// UnmarshalValue decodes a value from specific format.
	UnmarshalValue func(b []byte) (Value, error)
}

Format is a description for quad-file formats.

func FormatByExt added in v0.6.1

func FormatByExt(name string) *Format

FormatByExt returns a registered format by its file extension. Will return nil if format is not found.

func FormatByMime added in v0.6.1

func FormatByMime(name string) *Format

FormatByMime returns a registered format by its MIME type. Will return nil if format is not found.

func FormatByName added in v0.6.1

func FormatByName(name string) *Format

FormatByName returns a registered format by its name. Will return nil if format is not found.

func Formats added in v0.6.1

func Formats() []Format

Formats returns a list of all supported quad formats.

type IRI added in v0.6.0

type IRI string

IRI is an RDF Internationalized Resource Identifier (ex: <name>).

func (IRI) Full added in v0.6.1

func (s IRI) Full() IRI

func (IRI) FullWith added in v0.6.1

func (s IRI) FullWith(n *voc.Namespaces) IRI

func (IRI) GoString added in v0.7.0

func (s IRI) GoString() string

func (IRI) Native added in v0.6.0

func (s IRI) Native() interface{}

func (IRI) Short added in v0.6.1

func (s IRI) Short() IRI

func (IRI) ShortWith added in v0.6.1

func (s IRI) ShortWith(n *voc.Namespaces) IRI

func (IRI) String added in v0.6.0

func (s IRI) String() string

type Int added in v0.6.0

type Int int64

Int is a native wrapper for int64 type.

It uses NQuad notation similar to TypedString.

func (Int) Native added in v0.6.0

func (s Int) Native() interface{}

func (Int) String added in v0.6.0

func (s Int) String() string

func (Int) TypedString added in v0.6.1

func (s Int) TypedString() TypedString

type LangString added in v0.6.0

type LangString struct {
	Value String
	Lang  string
}

LangString is an RDF string with language (ex: "name"@lang).

func (LangString) Native added in v0.6.0

func (s LangString) Native() interface{}

func (LangString) String added in v0.6.0

func (s LangString) String() string

type Quad

type Quad struct {
	Subject   Value `json:"subject"`
	Predicate Value `json:"predicate"`
	Object    Value `json:"object"`
	Label     Value `json:"label,omitempty"`
}

Our quad struct, used throughout.

func Make added in v0.6.0

func Make(subject, predicate, object, label interface{}) (q Quad)

Make creates a quad with provided values.

func MakeIRI added in v0.6.1

func MakeIRI(subject, predicate, object, label string) (q Quad)

MakeIRI creates a quad with provided IRI values.

func MakeRaw deprecated added in v0.6.0

func MakeRaw(subject, predicate, object, label string) (q Quad)

MakeRaw creates a quad with provided raw values (nquads-escaped).

Deprecated: use Make pr MakeIRI instead.

func ReadAll added in v0.6.1

func ReadAll(r Reader) (arr []Quad, err error)

ReadAll reads all quads from r until EOF. It returns a slice with all quads that were read and an error, if any.

func (Quad) Get

func (q Quad) Get(d Direction) Value

Per-field accessor for quads.

func (Quad) GetString added in v0.6.0

func (q Quad) GetString(d Direction) string

Per-field accessor for quads that returns strings instead of values.

func (Quad) IsValid

func (q Quad) IsValid() bool

func (Quad) MarshalJSON added in v0.6.0

func (q Quad) MarshalJSON() ([]byte, error)

func (Quad) NQuad added in v0.4.1

func (q Quad) NQuad() string

Prints a quad in N-Quad format.

func (*Quad) Set added in v0.7.0

func (q *Quad) Set(d Direction, v Value)

func (Quad) String

func (q Quad) String() string

Pretty-prints a quad.

func (*Quad) UnmarshalJSON added in v0.6.0

func (q *Quad) UnmarshalJSON(data []byte) error

type Quads added in v0.6.1

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

func NewReader added in v0.6.1

func NewReader(quads []Quad) *Quads

NewReader creates a quad reader from a quad slice.

func (*Quads) ReadQuad added in v0.6.1

func (r *Quads) ReadQuad() (Quad, error)

func (*Quads) WriteQuad added in v0.6.1

func (r *Quads) WriteQuad(q Quad) error

type ReadCloser added in v0.6.1

type ReadCloser interface {
	Reader
	io.Closer
}

type ReadSkipCloser added in v0.6.1

type ReadSkipCloser interface {
	Reader
	Skipper
	io.Closer
}

type Reader added in v0.6.1

type Reader interface {
	ReadQuad() (Quad, error)
}

Reader is a minimal interface for quad readers. Used for quad deserializers and quad iterators.

ReadQuad reads next valid Quad. It returns io.EOF if no quads are left.

type Sequence added in v0.6.1

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

Sequence is an object to generate a sequence of Blank Nodes.

func (*Sequence) Next added in v0.6.1

func (s *Sequence) Next() BNode

Next returns a new blank node. It's safe for concurrent use.

type Skipper added in v0.6.1

type Skipper interface {
	SkipQuad() error
}

Skipper is an interface for quad reader that can skip quads efficiently without decoding them.

It returns io.EOF if no quads are left.

type String added in v0.6.0

type String string

String is an RDF string value (ex: "name").

func (String) GoString added in v0.7.0

func (s String) GoString() string

func (String) Native added in v0.6.0

func (s String) Native() interface{}

func (String) String added in v0.6.0

func (s String) String() string

type StringConversion added in v0.6.0

type StringConversion func(string) (Value, error)

StringConversion is a function to convert string values with a specific IRI type to their native equivalents.

type Time added in v0.6.0

type Time time.Time

Time is a native wrapper for time.Time type.

It uses NQuad notation similar to TypedString.

func (Time) Equal added in v0.6.0

func (s Time) Equal(v Value) bool

func (Time) Native added in v0.6.0

func (s Time) Native() interface{}

func (Time) String added in v0.6.0

func (s Time) String() string

func (Time) TypedString added in v0.6.1

func (s Time) TypedString() TypedString

type TypedString added in v0.6.0

type TypedString struct {
	Value String
	Type  IRI
}

TypedString is an RDF value with type (ex: "name"^^<type>).

func (TypedString) Native added in v0.6.0

func (s TypedString) Native() interface{}

func (TypedString) ParseValue added in v0.6.0

func (s TypedString) ParseValue() (Value, error)

ParseValue will try to parse underlying string value using registered functions.

It will return unchanged value if suitable function is not available.

Error will be returned if the type was recognizes, but parsing failed.

func (TypedString) String added in v0.6.0

func (s TypedString) String() string

type TypedStringer added in v0.6.1

type TypedStringer interface {
	TypedString() TypedString
}

type Value added in v0.6.0

type Value interface {
	String() string
	// Native converts Value to a closest native Go type.
	//
	// If type has no analogs in Go, Native return an object itself.
	Native() interface{}
}

Value is a type used by all quad directions.

func AsValue added in v0.6.0

func AsValue(v interface{}) (out Value, ok bool)

AsValue converts native type into closest Value representation. It returns false if type was not recognized.

func Raw deprecated added in v0.6.0

func Raw(s string) Value

Raw is a Turtle/NQuads-encoded value.

Deprecated: use IRI or String instead.

func StringToValue added in v0.6.0

func StringToValue(v string) Value

StringToValue is a function to convert strings to typed quad values.

Warning: should not be used directly - will be deprecated.

type WriteCloser added in v0.6.1

type WriteCloser interface {
	Writer
	io.Closer
}

type Writer added in v0.6.1

type Writer interface {
	WriteQuad(Quad) error
}

Writer is a minimal interface for quad writers. Used for quad serializers and quad stores.

Directories

Path Synopsis
Package dot provides an encoder for DOT format (graphviz).
Package dot provides an encoder for DOT format (graphviz).
Package gml provides an encoder for Graph Modeling Format
Package gml provides an encoder for Graph Modeling Format
Package graphml provides an encoder for GraphML format
Package graphml provides an encoder for GraphML format
Package json provides an encoder/decoder for JSON quad formats
Package json provides an encoder/decoder for JSON quad formats
Package jsonld provides an encoder/decoder for JSON-LD quad format
Package jsonld provides an encoder/decoder for JSON-LD quad format
Package nquads implements parsing the RDF 1.1 N-Quads like line-based syntax for RDF datasets.
Package nquads implements parsing the RDF 1.1 N-Quads like line-based syntax for RDF datasets.
Package pquads implements Cayley-specific protobuf-based quads format.
Package pquads implements Cayley-specific protobuf-based quads format.
pio

Jump to

Keyboard shortcuts

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