quad: github.com/cayleygraph/quad Index | Files | Directories

package quad

import "github.com/cayleygraph/quad"

Package quad defines quad and triple handling.

Index

Package Files

formats.go quad.go rw.go value.go

Constants

const (
    // IRIDefault preserves current IRI formatting.
    IRIDefault = IRIFormat(iota)
    // IRIShort changes IRI to use a short namespace prefix (ex: <rdf:type>).
    IRIShort
    // IRIFull changes IRI to use full form (ex: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>).
    IRIFull
)
const HashSize = sha1.Size

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

Variables

var (
    ErrInvalid    = errors.New("invalid N-Quad")
    ErrIncomplete = errors.New("incomplete N-Quad")
)
var DefaultBatch = 10000
var Directions = []Direction{Subject, Predicate, Object, Label}
var KnownBoolTypes = []IRI{
    defaultBoolType,
    schema.Boolean,
}

KnownBoolTypes consists of known IRIs of boolean types

var KnownFloatTypes = []IRI{
    defaultFloatType,
    xsd.Float,
    schema.Float,
    schema.Number,
}

KnownFloatTypes consists of known IRIs of floating-point numbers types

var KnownIntTypes = []IRI{
    defaultIntType,
    xsd.Int,
    xsd.Long,
    schema.Integer,
}

KnownIntTypes consists of known IRIs of integer types

var KnownTimeTypes = []IRI{
    defaultTimeType,
    xsd.DateTime,
    schema.DateTime,
}

KnownTimeTypes consists of known IRIs of datetime types

func Copy Uses

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 Uses

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 HasStringConversion Uses

func HasStringConversion(dataType IRI) bool

HasStringConversion returns whether IRI has a string conversion

func HashOf Uses

func HashOf(v Value) []byte

HashOf calculates a hash of value v.

func HashTo Uses

func HashTo(v Value, p []byte)

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

func IsValidValue Uses

func IsValidValue(v Value) bool

IsValidValue checks if the value is valid. It returns false if the value is nil, an empty IRI or an empty BNode.

func NativeOf Uses

func NativeOf(v Value) interface{}

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

func RegisterFormat Uses

func RegisterFormat(f Format)

RegisterFormat registers a new quad-file format.

func RegisterStringConversion Uses

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 RegisterStringConversions Uses

func RegisterStringConversions(dataTypes []IRI, fnc StringConversion)

RegisterStringConversions calls RegisterStringConversion with every IRI in dataTypes and fnc

func StringOf Uses

func StringOf(v Value) string

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

func ToString Uses

func ToString(v Value) string

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

type BNode Uses

type BNode string

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

func RandomBlankNode Uses

func RandomBlankNode() BNode

RandomBlankNode returns a randomly generated Blank Node.

func (BNode) GoString Uses

func (s BNode) GoString() string

func (BNode) Native Uses

func (s BNode) Native() interface{}

func (BNode) String Uses

func (s BNode) String() string

type BatchReader Uses

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 Uses

type BatchWriter interface {
    // WriteQuads returns a number of quads that where written and an error, if any.
    WriteQuads(buf []Quad) (int, error)
}

BatchWriter is an interface for writing quads in batches.

type Bool Uses

type Bool bool

Bool is a native wrapper for bool type.

It uses NQuad notation similar to TypedString.

func (Bool) Native Uses

func (s Bool) Native() interface{}

func (Bool) String Uses

func (s Bool) String() string

func (Bool) TypedString Uses

func (s Bool) TypedString() TypedString

type ByQuadString Uses

type ByQuadString []Quad

func (ByQuadString) Len Uses

func (o ByQuadString) Len() int

func (ByQuadString) Less Uses

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

func (ByQuadString) Swap Uses

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

type ByValueString Uses

type ByValueString []Value

func (ByValueString) Len Uses

func (o ByValueString) Len() int

func (ByValueString) Less Uses

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

func (ByValueString) Swap Uses

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

type Direction Uses

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 Uses

func (d Direction) GoString() string

func (Direction) Prefix Uses

func (d Direction) Prefix() byte

func (Direction) String Uses

func (d Direction) String() string

type Equaler Uses

type Equaler interface {
    Equal(v Value) bool
}

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

type Float Uses

type Float float64

Float is a native wrapper for float64 type.

It uses NQuad notation similar to TypedString.

func (Float) Native Uses

func (s Float) Native() interface{}

func (Float) String Uses

func (s Float) String() string

func (Float) TypedString Uses

func (s Float) TypedString() TypedString

type Format Uses

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 Uses

func FormatByExt(name string) *Format

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

func FormatByMime Uses

func FormatByMime(name string) *Format

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

func FormatByName Uses

func FormatByName(name string) *Format

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

func Formats Uses

func Formats() []Format

Formats returns a list of all supported quad formats.

type IRI Uses

type IRI string

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

func (IRI) Format Uses

func (s IRI) Format(format IRIFormat) IRI

Format the IRI according to selection.

func (IRI) Full Uses

func (s IRI) Full() IRI

Full uses voc package to convert a short namespace prefix (if any) to a full IRI prefix. The prefix must be registered in the voc package.

func (IRI) FullWith Uses

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

FullWith uses provided namespace to convert a short namespace prefix (if any) to a full IRI prefix.

func (IRI) GoString Uses

func (s IRI) GoString() string

GoString overrides IRI's %#v printing behaviour to include the type name.

func (IRI) Native Uses

func (s IRI) Native() interface{}

Native returns an IRI value unchanged (to not collide with String values).

func (IRI) Short Uses

func (s IRI) Short() IRI

Short uses voc package to convert a full IRI prefix (if any) to a short namespace prefix. The prefix must be registered in the voc package.

func (IRI) ShortWith Uses

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

ShortWith uses the provided namespace to convert a full IRI prefix (if any) to a short namespace prefix.

func (IRI) String Uses

func (s IRI) String() string

String prints IRI in "<iri>" form.

type IRIFormat Uses

type IRIFormat int

IRIFormat is a format of IRI.

type IRIOptions Uses

type IRIOptions struct {
    Format IRIFormat // short vs full IRI format
    // Func is executed after all other options and have a chance to replace the value.
    // Returning an empty IRI changes the value to nil.
    Func func(d Direction, iri IRI) (IRI, error)
}

IRIOptions is a set of option

type Identifier Uses

type Identifier interface {
    Value
    // contains filtered or unexported methods
}

Identifier is a union of IRI and BNode.

type Int Uses

type Int int64

Int is a native wrapper for int64 type.

It uses NQuad notation similar to TypedString.

func (Int) Native Uses

func (s Int) Native() interface{}

func (Int) String Uses

func (s Int) String() string

func (Int) TypedString Uses

func (s Int) TypedString() TypedString

type LangString Uses

type LangString struct {
    Value String
    Lang  string
}

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

func (LangString) Native Uses

func (s LangString) Native() interface{}

func (LangString) String Uses

func (s LangString) String() string

type Quad Uses

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 Uses

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

Make creates a quad with provided values.

func MakeIRI Uses

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

MakeIRI creates a quad with provided IRI values.

func MakeRaw Uses

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 Uses

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 Uses

func (q Quad) Get(d Direction) Value

Per-field accessor for quads.

func (Quad) GetString Uses

func (q Quad) GetString(d Direction) string

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

func (Quad) IsValid Uses

func (q Quad) IsValid() bool

func (Quad) MarshalJSON Uses

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

func (Quad) NQuad Uses

func (q Quad) NQuad() string

Prints a quad in N-Quad format.

func (*Quad) Set Uses

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

func (Quad) String Uses

func (q Quad) String() string

Pretty-prints a quad.

func (*Quad) UnmarshalJSON Uses

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

type Quads Uses

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

func NewReader Uses

func NewReader(quads []Quad) *Quads

NewReader creates a quad reader from a quad slice.

func (*Quads) ReadQuad Uses

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

func (*Quads) WriteQuad Uses

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

type ReadCloser Uses

type ReadCloser interface {
    Reader
    io.Closer
}

type ReadSkipCloser Uses

type ReadSkipCloser interface {
    Reader
    Skipper
    io.Closer
}

type Reader Uses

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 Uses

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

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

func (*Sequence) Next Uses

func (s *Sequence) Next() BNode

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

type Skipper Uses

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 Uses

type String string

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

func (String) GoString Uses

func (s String) GoString() string

func (String) Native Uses

func (s String) Native() interface{}

func (String) String Uses

func (s String) String() string

type StringConversion Uses

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 Uses

type Time time.Time

Time is a native wrapper for time.Time type.

It uses NQuad notation similar to TypedString.

func (Time) Equal Uses

func (s Time) Equal(v Value) bool

func (Time) Native Uses

func (s Time) Native() interface{}

func (Time) String Uses

func (s Time) String() string

func (Time) TypedString Uses

func (s Time) TypedString() TypedString

type TypedString Uses

type TypedString struct {
    Value String
    Type  IRI
}

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

func (TypedString) Native Uses

func (s TypedString) Native() interface{}

func (TypedString) ParseValue Uses

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 Uses

func (s TypedString) String() string

type TypedStringer Uses

type TypedStringer interface {
    TypedString() TypedString
}

type Value Uses

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 Uses

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 Uses

func Raw(s string) Value

Raw is a Turtle/NQuads-encoded value.

Deprecated: use IRI or String instead.

func StringToValue Uses

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 Uses

type WriteCloser interface {
    Writer
    io.Closer
}

type Writer Uses

type Writer interface {
    // WriteQuad writes a single quad and returns an error, if any.
    //
    // Deprecated: use WriteQuads instead.
    WriteQuad(Quad) error
    BatchWriter
}

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

func IRIWriter Uses

func IRIWriter(w Writer, opt IRIOptions) Writer

IRIWriter is a writer implementation that converts all IRI values in quads according to the IRIOptions.

func ValuesWriter Uses

func ValuesWriter(w Writer, fnc func(d Direction, v Value) (Value, error)) Writer

ValuesWriter is a writer implementation that converts all quad values using the callback function.

Directories

PathSynopsis
dotPackage dot provides an encoder for DOT format (graphviz).
gmlPackage gml provides an encoder for Graph Modeling Format
graphmlPackage graphml provides an encoder for GraphML format
jsonPackage json provides an encoder/decoder for JSON quad formats
jsonldPackage jsonld provides an encoder/decoder for JSON-LD quad format
nquadsPackage nquads implements parsing the RDF 1.1 N-Quads like line-based syntax for RDF datasets.
pquadsPackage pquads implements Cayley-specific protobuf-based quads format.
pquads/pio
vocPackage voc implements an RDF namespace (vocabulary) registry.
voc/corePackage core imports all well-known RDF vocabularies.
voc/owlPackage owl contains constants of the Web Ontology Language (OWL)
voc/rdfPackage rdf contains constants of the RDF Concepts Vocabulary (RDF)
voc/rdfsPackage rdfs contains constants of the RDF Schema vocabulary (RDFS)
voc/schemaPackage schema contains constants of the Schema.org vocabulary.
voc/xsdPackage xsd contains constants of the W3C XML Schema Definition Language https://www.w3.org/TR/xmlschema11-1/

Package quad imports 15 packages (graph) and is imported by 85 packages. Updated 2020-04-07. Refresh now. Tools for package owners.